[PATCH] D21099: [Sema] Teach -Wcast-align to look at the aligned attribute of the declared variables
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 17 04:19:15 PST 2016
arphaman added inline comments.
================
Comment at: lib/Sema/SemaChecking.cpp:10304
CharUnits SrcAlign = Context.getTypeAlignInChars(SrcPointee);
+ Expr *SE = nullptr;
+
----------------
NIT, but I think you don't need the extra variable and the `if (SE)` below if you extract the code inside `if (SE) {` into a static function that returns SrcAlign. Then the if/else below can be rewritten like:
```
if (auto *CE = dyn_cast<CastExpr>(Op)) {
if (CE->getCastKind() == CK_ArrayToPointerDecay)
SrcAlign = newFunction(CE->getSubExpr(), Context);
} else if (auto *UO = dyn_cast<UnaryOperator>(Op)) {
if (UO->getOpcode() == UO_AddrOf)
SrcAlign = newFunction(UO->getSubExpr(), Context);
}
```
================
Comment at: lib/Sema/SemaChecking.cpp:10315
+ if (SE) {
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(SE))
+ SrcAlign = Context.getDeclAlign(DRE->getDecl());
----------------
You can use `const auto` here.
================
Comment at: lib/Sema/SemaChecking.cpp:10317
+ SrcAlign = Context.getDeclAlign(DRE->getDecl());
+ else if (const MemberExpr *ME = dyn_cast<MemberExpr>(SE))
+ SrcAlign = Context.getDeclAlign(ME->getMemberDecl());
----------------
Same here.
https://reviews.llvm.org/D21099
More information about the cfe-commits
mailing list