summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-21 03:09:59 +0000
committerChris Lattner <sabre@nondot.org>2009-09-21 03:09:59 +0000
commitbf20638966e205e6dc18451275e5c51264f255e6 (patch)
treea1d94b0ca15cafbafdea10ae405e6b0fd8648cf9
parent26e37a77c6bc36d219aacd9edec9247df8725c3d (diff)
downloadbcm5719-llvm-bf20638966e205e6dc18451275e5c51264f255e6.tar.gz
bcm5719-llvm-bf20638966e205e6dc18451275e5c51264f255e6.zip
Implement __builtin_unreachable(), a GCC 4.5 extension.
llvm-svn: 82433
-rw-r--r--clang/docs/LanguageExtensions.html42
-rw-r--r--clang/include/clang/Basic/Builtins.def1
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp7
-rw-r--r--clang/test/Sema/builtins.c11
4 files changed, 60 insertions, 1 deletions
diff --git a/clang/docs/LanguageExtensions.html b/clang/docs/LanguageExtensions.html
index d94eb4fd149..9ac35e1dc2d 100644
--- a/clang/docs/LanguageExtensions.html
+++ b/clang/docs/LanguageExtensions.html
@@ -27,6 +27,7 @@ td {
<li><a href="#builtins">Builtin Functions</a>
<ul>
<li><a href="#__builtin_shufflevector">__builtin_shufflevector</a></li>
+ <li><a href="#__builtin_unreachable">__builtin_unreachable</a></li>
</ul>
</li>
<li><a href="#targetspecific">Target-Specific Extensions</a>
@@ -310,6 +311,47 @@ with the same element type as vec1/vec2 but that has an element count equal to
the number of indices specified.
</p>
+<p>Query for this feature with __has_builtin(__builtin_shufflevector).</p>
+
+<!-- ======================================================================= -->
+<h3 id="__builtin_unreachable">__builtin_unreachable</h3>
+<!-- ======================================================================= -->
+
+<p><tt>__builtin_unreachable</tt> is used to indicate that a specific point in
+the program cannot be reached, even if the compiler might otherwise think it
+can. This is useful to improve optimization and eliminates certain warnings.
+For example, without the <tt>__builtin_unreachable</tt> in the example below,
+the compiler assumes that the inline asm can fall through and prints a "function
+declared 'noreturn' should not return" warning.
+</p>
+
+<p><b>Syntax:</b></p>
+
+<pre>
+__builtin_unreachable()
+</pre>
+
+<p><b>Example of Use:</b></p>
+
+<pre>
+void myabort(void) __attribute__((noreturn));
+void myabort(void) {
+ asm("int3");
+ __builtin_unreachable();
+}
+</pre>
+
+<p><b>Description:</b></p>
+
+<p>The __builtin_unreachable() builtin has completely undefined behavior. Since
+it has undefined behavior, it is a statement that it is never reached and the
+optimizer can take advantage of this to produce better code. This builtin takes
+no arguments and produces a void result.
+</p>
+
+<p>Query for this feature with __has_builtin(__builtin_unreachable).</p>
+
+
<!-- ======================================================================= -->
<h2 id="targetspecific">Target-Specific Extensions</h2>
<!-- ======================================================================= -->
diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index 051fd399812..da0906b77b3 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -271,6 +271,7 @@ BUILTIN(__builtin___vprintf_chk, "iicC*a", "FP:1:")
BUILTIN(__builtin_expect, "iii" , "nc")
BUILTIN(__builtin_prefetch, "vvC*.", "nc")
BUILTIN(__builtin_trap, "v", "n")
+BUILTIN(__builtin_unreachable, "v", "nr")
BUILTIN(__builtin_shufflevector, "v." , "nc")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e049cc890d7..ffc8ea7daaf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -224,7 +224,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0);
return RValue::get(Builder.CreateCall(F));
}
-
+ case Builtin::BI__builtin_unreachable: {
+ Value *V = Builder.CreateUnreachable();
+ Builder.ClearInsertionPoint();
+ return RValue::get(V);
+ }
+
case Builtin::BI__builtin_powi:
case Builtin::BI__builtin_powif:
case Builtin::BI__builtin_powil: {
diff --git a/clang/test/Sema/builtins.c b/clang/test/Sema/builtins.c
index 068f3006f4a..c3daa667d8a 100644
--- a/clang/test/Sema/builtins.c
+++ b/clang/test/Sema/builtins.c
@@ -41,3 +41,14 @@ void test9(short v) {
old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
old = __sync_fetch_and_add((int**)0, 42i); // expected-warning {{imaginary constants are an extension}}
}
+
+
+// rdar://7236819
+void test10(void) __attribute__((noreturn));
+
+void test10(void) {
+ __asm__("int3");
+ __builtin_unreachable();
+
+ // No warning about falling off the end of a noreturn function.
+}
OpenPOWER on IntegriCloud