[cfe-commits] r102705 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaType.cpp test/Sema/attr-noreturn.c
Abramo Bagnara
abramo.bagnara at gmail.com
Fri Apr 30 02:13:03 PDT 2010
Author: abramo
Date: Fri Apr 30 04:13:03 2010
New Revision: 102705
URL: http://llvm.org/viewvc/llvm-project?rev=102705&view=rev
Log:
Attribute noreturn is now put in declaration attributes. Fixed a double warning generation.
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/attr-noreturn.c
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=102705&r1=102704&r2=102705&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr 30 04:13:03 2010
@@ -467,10 +467,11 @@
}
static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
- Sema &S) {
+ Sema &S, bool EmitDiagnostics) {
// check the attribute arguments.
if (Attr.getNumArgs() != 0) {
- S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ if (EmitDiagnostics)
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return false;
}
@@ -478,10 +479,11 @@
ValueDecl *VD = dyn_cast<ValueDecl>(d);
if (VD == 0 || (!VD->getType()->isBlockPointerType()
&& !VD->getType()->isFunctionPointerType())) {
- S.Diag(Attr.getLoc(),
- Attr.isCXX0XAttribute() ? diag::err_attribute_wrong_decl_type
- : diag::warn_attribute_wrong_decl_type)
- << Attr.getName() << 0 /*function*/;
+ if (EmitDiagnostics)
+ S.Diag(Attr.getLoc(),
+ Attr.isCXX0XAttribute() ? diag::err_attribute_wrong_decl_type
+ : diag::warn_attribute_wrong_decl_type)
+ << Attr.getName() << 0 /*function*/;
return false;
}
}
@@ -490,21 +492,17 @@
}
static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
- // NOTE: We don't add the attribute to a FunctionDecl because the noreturn
- // trait will be part of the function's type.
-
- // Don't apply as a decl attribute to ValueDecl.
- // FIXME: probably ought to diagnose this.
- if (isa<ValueDecl>(d))
- return;
-
- if (HandleCommonNoReturnAttr(d, Attr, S))
+ /*
+ Do check for well-formedness, but do not emit diagnostics:
+ it was already emitted by Sema::ProcessFnAttr().
+ */
+ if (HandleCommonNoReturnAttr(d, Attr, S, /*EmitDiagnostic=*/false))
d->addAttr(::new (S.Context) NoReturnAttr());
}
static void HandleAnalyzerNoReturnAttr(Decl *d, const AttributeList &Attr,
Sema &S) {
- if (HandleCommonNoReturnAttr(d, Attr, S))
+ if (HandleCommonNoReturnAttr(d, Attr, S, true))
d->addAttr(::new (S.Context) AnalyzerNoReturnAttr());
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=102705&r1=102704&r2=102705&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Apr 30 04:13:03 2010
@@ -1912,8 +1912,8 @@
// type, but others can be present in the type specifiers even though they
// apply to the decl. Here we apply type attributes and ignore the rest.
for (; AL; AL = AL->getNext()) {
- // If this is an attribute we can handle, do so now, otherwise, add it to
- // the LeftOverAttrs list for rechaining.
+ // If this is an attribute we can handle, do so now,
+ // otherwise, add it to the FnAttrs list for rechaining.
switch (AL->getKind()) {
default: break;
Modified: cfe/trunk/test/Sema/attr-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-noreturn.c?rev=102705&r1=102704&r2=102705&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-noreturn.c (original)
+++ cfe/trunk/test/Sema/attr-noreturn.c Fri Apr 30 04:13:03 2010
@@ -40,3 +40,5 @@
__attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) {
x();
}
+
+typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute requires 0 argument(s)}}
More information about the cfe-commits
mailing list