[cfe-commits] r64700 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDeclAttr.cpp test/Sema/attr-aligned.c

Daniel Dunbar daniel at zuster.org
Mon Feb 16 15:37:57 PST 2009


Author: ddunbar
Date: Mon Feb 16 17:37:57 2009
New Revision: 64700

URL: http://llvm.org/viewvc/llvm-project?rev=64700&view=rev
Log:
Diagnose non-power-of-2 arguments to attribute aligned.

Added:
    cfe/trunk/test/Sema/attr-aligned.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=64700&r1=64699&r2=64700&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Mon Feb 16 17:37:57 2009
@@ -356,6 +356,8 @@
      "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,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=64700&r1=64699&r2=64700&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Feb 16 17:37:57 2009
@@ -1218,6 +1218,12 @@
       << "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));
 }
 

Added: cfe/trunk/test/Sema/attr-aligned.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-aligned.c?rev=64700&view=auto

==============================================================================
--- cfe/trunk/test/Sema/attr-aligned.c (added)
+++ cfe/trunk/test/Sema/attr-aligned.c Mon Feb 16 17:37:57 2009
@@ -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}}





More information about the cfe-commits mailing list