Skip to content

Commit b04a419

Browse files
authored
Minor refactororing of ASTContext::getDeclAlign() (NFC) (#72977)
1 parent eef8e1d commit b04a419

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,28 +1627,22 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {
16271627
CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
16281628
unsigned Align = Target->getCharWidth();
16291629

1630-
bool UseAlignAttrOnly = false;
1631-
if (unsigned AlignFromAttr = D->getMaxAlignment()) {
1630+
const unsigned AlignFromAttr = D->getMaxAlignment();
1631+
if (AlignFromAttr)
16321632
Align = AlignFromAttr;
16331633

1634-
// __attribute__((aligned)) can increase or decrease alignment
1635-
// *except* on a struct or struct member, where it only increases
1636-
// alignment unless 'packed' is also specified.
1637-
//
1638-
// It is an error for alignas to decrease alignment, so we can
1639-
// ignore that possibility; Sema should diagnose it.
1640-
if (isa<FieldDecl>(D)) {
1641-
UseAlignAttrOnly = D->hasAttr<PackedAttr>() ||
1642-
cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1643-
} else {
1644-
UseAlignAttrOnly = true;
1645-
}
1646-
}
1647-
else if (isa<FieldDecl>(D))
1648-
UseAlignAttrOnly =
1649-
D->hasAttr<PackedAttr>() ||
1650-
cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1651-
1634+
// __attribute__((aligned)) can increase or decrease alignment
1635+
// *except* on a struct or struct member, where it only increases
1636+
// alignment unless 'packed' is also specified.
1637+
//
1638+
// It is an error for alignas to decrease alignment, so we can
1639+
// ignore that possibility; Sema should diagnose it.
1640+
bool UseAlignAttrOnly;
1641+
if (const FieldDecl *FD = dyn_cast<FieldDecl>(D))
1642+
UseAlignAttrOnly =
1643+
FD->hasAttr<PackedAttr>() || FD->getParent()->hasAttr<PackedAttr>();
1644+
else
1645+
UseAlignAttrOnly = AlignFromAttr != 0;
16521646
// If we're using the align attribute only, just ignore everything
16531647
// else about the declaration and its type.
16541648
if (UseAlignAttrOnly) {

0 commit comments

Comments
 (0)