Add builtin knowledge about longjmp being noreturn. Add printing for
the noreturn attribute.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77253 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index 589cdec..e5bf59f 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -335,6 +335,8 @@
}
Proto += ")";
+ if (D->hasAttr<NoReturnAttr>())
+ Proto += " __attribute((noreturn))";
if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
if (CDecl->getNumBaseOrMemberInitializers() > 0) {
Proto += " : ";
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index bf2d3cc..d168a90 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3705,7 +3705,9 @@
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) {
diff --git a/test/Sema/return.c b/test/Sema/return.c
index 99568b0..f439ad7 100644
--- a/test/Sema/return.c
+++ b/test/Sema/return.c
@@ -196,3 +196,9 @@
int test29() {
exit(1);
}
+
+#include <setjmp.h>
+jmp_buf test30_j;
+int test30() {
+ longjmp(test30_j, 1);
+}