[PATCH] D78767: [Sema] Teach -Wcast-align to compute a more accurate alignment when the source expression has array subscript or pointer arithmetic operators

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 24 10:16:03 PDT 2020


rjmccall added inline comments.


================
Comment at: clang/include/clang/AST/Expr.h:710
+  /// possible to compute the alignment, return zero.
+  CharUnits getAlignmentFromDecl(ASTContext &Ctx) const;
+
----------------
Nothing about the name here suggests that it only works on expressions of pointer type.  Maybe call it `getPresumedAlignmentOfPointer` or something and then make it also consider the type alignment?


================
Comment at: clang/lib/AST/ExprConstant.cpp:14844
+  if (auto *VD = Result.Base.dyn_cast<const ValueDecl *>())
+    return Ctx.getDeclAlign(VD).alignmentAtOffset(Result.Offset);
+
----------------
Does this do the right thing if `getDeclAlign` returns 0, or can that never happen?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78767/new/

https://reviews.llvm.org/D78767





More information about the cfe-commits mailing list