[PATCH] D152335: [Clang] Add check to Sema::AddAlignedAttr to verify active bits is not out of range

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 7 12:04:49 PDT 2023


shafik updated this revision to Diff 529396.
shafik marked 2 inline comments as done.
shafik added a comment.

- Switched to using APSInt::operator> as discussed offline w/ Erich and Aaron


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

https://reviews.llvm.org/D152335

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-aligned.c


Index: clang/test/Sema/attr-aligned.c
===================================================================
--- clang/test/Sema/attr-aligned.c
+++ clang/test/Sema/attr-aligned.c
@@ -1,8 +1,10 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested alignment must be 4294967296 bytes or smaller}}
 int y __attribute__((aligned(1ull << 32)));
+// GH50534
+int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // expected-error {{requested alignment must be 4294967296 bytes or smaller}}
 
 // PR26444
 int y __attribute__((aligned(1 << 29)));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4473,6 +4473,15 @@
   if (ICE.isInvalid())
     return;
 
+  uint64_t MaximumAlignment = Sema::MaximumAlignment;
+  if (Context.getTargetInfo().getTriple().isOSBinFormatCOFF())
+    MaximumAlignment = std::min(MaximumAlignment, uint64_t(8192));
+  if (Alignment > MaximumAlignment) {
+    Diag(AttrLoc, diag::err_attribute_aligned_too_great)
+        << MaximumAlignment << E->getSourceRange();
+    return;
+  }
+
   uint64_t AlignVal = Alignment.getZExtValue();
   // C++11 [dcl.align]p2:
   //   -- if the constant expression evaluates to zero, the alignment
@@ -4487,15 +4496,6 @@
     }
   }
 
-  uint64_t MaximumAlignment = Sema::MaximumAlignment;
-  if (Context.getTargetInfo().getTriple().isOSBinFormatCOFF())
-    MaximumAlignment = std::min(MaximumAlignment, uint64_t(8192));
-  if (AlignVal > MaximumAlignment) {
-    Diag(AttrLoc, diag::err_attribute_aligned_too_great)
-        << MaximumAlignment << E->getSourceRange();
-    return;
-  }
-
   const auto *VD = dyn_cast<VarDecl>(D);
   if (VD) {
     unsigned MaxTLSAlign =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152335.529396.patch
Type: text/x-patch
Size: 2048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230607/d98dfaf8/attachment.bin>


More information about the cfe-commits mailing list