]> granicus.if.org Git - clang/commitdiff
Diagnose non-power-of-2 arguments to attribute aligned.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 16 Feb 2009 23:37:57 +0000 (23:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 16 Feb 2009 23:37:57 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64700 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-aligned.c [new file with mode: 0644]

index af4c7f5aa4566778a8691be68297d5e2040b96cd..8514b922147ce9d38c524678a1c4019e16a73fe2 100644 (file)
@@ -356,6 +356,8 @@ DIAG(err_as_qualified_auto_decl, ERROR,
      "automatic variable qualified with an address space")
 DIAG(err_attribute_annotate_no_string, ERROR,
      "argument to annotate attribute was not a string literal")
+DIAG(err_attribute_aligned_not_power_of_two, ERROR,
+     "requested alignment is not a power of 2")
 DIAG(warn_redeclaration_without_attribute_prev_attribute_ignored, WARNING,
   "'%0' redeclared without %1 attribute: previous %1 ignored")
 DIAG(warn_attribute_ignored, WARNING,
index a28d0a6d6de18520b7e43708ac75f7230f32227e..1d83605316cea13b143b14d0382a9c17a88da1f4 100644 (file)
@@ -1218,6 +1218,12 @@ static void HandleAlignedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
       << "aligned" << alignmentExpr->getSourceRange();
     return;
   }
+  if (!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_aligned_not_power_of_two) 
+      << alignmentExpr->getSourceRange();
+    return;
+  }
+
   d->addAttr(new AlignedAttr(Alignment.getZExtValue() * 8));
 }
 
diff --git a/test/Sema/attr-aligned.c b/test/Sema/attr-aligned.c
new file mode 100644 (file)
index 0000000..390e6d9
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: clang -fsyntax-only -verify %s
+
+int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}}