[PATCH] D118350: [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is passed to a function

Zarko Todorovski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 3 14:33:22 PST 2022


ZarkoCA added inline comments.


================
Comment at: clang/lib/Sema/SemaChecking.cpp:5246
+
+  if (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg->IgnoreParens())) {
+    if (const auto *DR = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) {
----------------
sfertile wrote:
> Nit: To avoid the deep nesting, can we instead have a series of casts, and if the resulting pointer is null we return early?
Reworked it to use a few early returns. Does that work better? 


================
Comment at: clang/test/Sema/aix-attr-align.c:10
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[8] __attribute__((aligned(16))); // expected-warning {{alignment of 16 bytes for a struct member is not binary compatible with IBM XL C/C++ for AIX 16.1.0 or older}}
 };
----------------
sfertile wrote:
> As far as I am aware, the layout of a 16-byte aligned member is exactly the same between the all the compilers on AIX, and the only incompatibility is when passing them byval. If that's true then warning on the declaration here is much too verbose, as most uses will be fine and warning on the callsite (and later on the function definition) calls attention to it only when there is indeed the possibility of an incompatability.
The way this test case was written it made it seem as if it would warn on any such declaration. I added `struct R` here where it has a member aligned 16 but it's not passed byval anywhere and no warning is expected. I also added a comment to make it clearer. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118350



More information about the cfe-commits mailing list