Add builtin knowledge about longjmp being noreturn. Add printing for
authorMike Stump <mrs@apple.com>
Mon, 27 Jul 2009 21:33:40 +0000 (21:33 +0000)
committerMike Stump <mrs@apple.com>
Mon, 27 Jul 2009 21:33:40 +0000 (21:33 +0000)
the noreturn attribute.

llvm-svn: 77253

clang/lib/AST/DeclPrinter.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/return.c

index 589cdec..e5bf59f 100644 (file)
@@ -335,6 +335,8 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
     }
 
     Proto += ")";
+    if (D->hasAttr<NoReturnAttr>())
+      Proto += " __attribute((noreturn))";
     if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
       if (CDecl->getNumBaseOrMemberInitializers() > 0) {
         Proto += " : ";
index bf2d3cc..d168a90 100644 (file)
@@ -3705,7 +3705,9 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
     if (!FD->getAttr<FormatAttr>())
       FD->addAttr(::new (Context) FormatAttr("printf", 2,
                                              Name->isStr("vasprintf") ? 0 : 3));
-  }
+  } else if (Name->isStr("longjmp") &&
+             !FD->hasAttr<NoReturnAttr>())
+    FD->addAttr(::new (Context) NoReturnAttr());
 }
 
 TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T) {
index 99568b0..f439ad7 100644 (file)
@@ -196,3 +196,9 @@ void exit(int);
 int test29() {
   exit(1);
 }
+
+#include <setjmp.h>
+jmp_buf test30_j;
+int test30() {
+  longjmp(test30_j, 1);
+}