]> granicus.if.org Git - clang/commitdiff
Add noreturn for exit.
authorMike Stump <mrs@apple.com>
Mon, 27 Jul 2009 19:14:18 +0000 (19:14 +0000)
committerMike Stump <mrs@apple.com>
Mon, 27 Jul 2009 19:14:18 +0000 (19:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77237 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Builtins.def
include/clang/Basic/Builtins.h
lib/Sema/SemaDecl.cpp
test/Sema/return.c

index c2f4061c5d789b46de3c0b76902a701a8adf8db2..9c5edf38bce5d01243a1e338ae710c29b25e46f0 100644 (file)
@@ -54,6 +54,7 @@
 // of the function.  These must be kept in sync with the predicates in the
 // Builtin::Context class.  Currently we have:
 //  n -> nothrow
+//  r -> noreturn
 //  c -> const
 //  F -> this is a libc/libm function with a '__builtin_' prefix added.
 //  f -> this is a libc/libm function without the '__builtin_' prefix. It can
@@ -335,6 +336,9 @@ BUILTIN(__sync_fetch_and_umax, "UiUi*Ui", "n")
 // C99 library functions
 // C99 stdlib.h
 LIBBUILTIN(calloc, "v*zz",        "f",     "stdlib.h")
+LIBBUILTIN(exit, "vi",            "fr",    "stdlib.h")
+LIBBUILTIN(_Exit, "vi",           "fr",    "stdlib.h")
+LIBBUILTIN(_exit, "vi",           "fr",    "unistd.h")
 LIBBUILTIN(malloc, "v*z",         "f",     "stdlib.h")
 LIBBUILTIN(realloc, "v*v*z",      "f",     "stdlib.h")
 // C99 string.h
index 5711fc1eb4a5aed99b1e1fa7ee90157cac47dba6..cd05bccfb4c068e2f5b2dbf808bb931ec13f7e2a 100644 (file)
@@ -90,6 +90,11 @@ public:
     return strchr(GetRecord(ID).Attributes, 'n') != 0;
   }
   
+  /// isNoReturn - Return true if we know this builtin never returns.
+  bool isNoReturn(unsigned ID) const {
+    return strchr(GetRecord(ID).Attributes, 'r') != 0;
+  }
+  
   /// isLibFunction - Return true if this is a builtin for a libc/libm function,
   /// with a "__builtin_" prefix (e.g. __builtin_abs).
   bool isLibFunction(unsigned ID) const {
index 0f4e9a42d6ed3a1bdaa7dd08be5447e75f2d6411..bf2d3ccec26aee7f820496e73dcccb5a01b8dcc4 100644 (file)
@@ -3676,6 +3676,9 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
       if (!FD->getAttr<ConstAttr>())
         FD->addAttr(::new (Context) ConstAttr());
     }
+
+    if (Context.BuiltinInfo.isNoReturn(BuiltinID))
+      FD->addAttr(::new (Context) NoReturnAttr());
   }
 
   IdentifierInfo *Name = FD->getIdentifier();
index 9234e3ee2a760f88a7b6e1dcf166de1bd798be83..99568b07cd4b68372b0320484a37c84b606d19f2 100644 (file)
@@ -191,3 +191,8 @@ int test27() {
 // PR4624
 void test28() __attribute__((noreturn));
 void test28(x) { while (1) { } }
+
+void exit(int);
+int test29() {
+  exit(1);
+}