diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 23:37:57 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 23:37:57 +0000 |
commit | 396b2a22788b0134018760d6a476de1e20f81334 (patch) | |
tree | 4f88501eb6d5e87c0c92ac24ca3b2ee8d928d2a2 | |
parent | f57c5b2ef767223f349be6adba9bf1b4f9d19283 (diff) |
Diagnose non-power-of-2 arguments to attribute aligned.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64700 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.def | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 6 | ||||
-rw-r--r-- | test/Sema/attr-aligned.c | 3 |
3 files changed, 11 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index af4c7f5aa4..8514b92214 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -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, diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index a28d0a6d6d..1d83605316 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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 index 0000000000..390e6d9df4 --- /dev/null +++ b/test/Sema/attr-aligned.c @@ -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}} |