[PATCH] D68824: Fix __builtin_assume_aligned with too large values.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 14:53:04 PDT 2019


rsmith added a comment.

This seems to be missing a CodeGen test for what IR we generate on an overly-large alignment. (The warning says the alignment is ignored, but I don't see where you're actually doing anything different in that case when generating IR.)



================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2857-2859
+    : Warning<"requested alignment must be %0 bytes or smaller; assumption "
+              "ignored">,
+      InGroup<DiagGroup<"builtin-assume-aligned-alignment">>;
----------------
Ignoring the assumption in this case seems unnecessarily user-hostile (and would require hard-coding an arbitrary LLVM limit in the source code to work around). Couldn't we just assume the highest alignment that we do support instead?


================
Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1522
   for (const auto *Clause : D.getClausesOfKind<OMPAlignedClause>()) {
-    unsigned ClauseAlignment = 0;
+    size_t ClauseAlignment = 0;
     if (const Expr *AlignmentExpr = Clause->getAlignment()) {
----------------
It's not appropriate to assume that `size_t` is any bigger than `unsigned` or generally that it's meaningful on the target. If you want 64 bits here, use `uint64_t`, but the right choice is probably `llvm::APInt`.


================
Comment at: clang/lib/Sema/SemaChecking.cpp:6067-6070
+    // Alignment calculations can wrap around if it's greater than 2**28.
+    unsigned MaximumAlignment =
+        Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
+                                                                : 268435456;
----------------
Why is there a different limit depending on bin format? We can support this at the IR level regardless, can't we? (I don't see how the binary format is relevant.)


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

https://reviews.llvm.org/D68824





More information about the cfe-commits mailing list