[cfe-commits] r147655 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/no-builtin.c

David Chisnall csdavec at swan.ac.uk
Fri Jan 6 04:20:19 PST 2012


Author: theraven
Date: Fri Jan  6 06:20:19 2012
New Revision: 147655

URL: http://llvm.org/viewvc/llvm-project?rev=147655&view=rev
Log:
If we are compiling with -fno-builtin then don't do constant folding of
builtins.

This fixes PR11711.


Added:
    cfe/trunk/test/CodeGen/no-builtin.c
Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=147655&r1=147654&r2=147655&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jan  6 06:20:19 2012
@@ -175,7 +175,8 @@
                                         unsigned BuiltinID, const CallExpr *E) {
   // See if we can constant fold this builtin.  If so, don't emit it at all.
   Expr::EvalResult Result;
-  if (E->EvaluateAsRValue(Result, CGM.getContext()) &&
+  if (!getContext().getLangOptions().NoBuiltin &&
+      E->EvaluateAsRValue(Result, CGM.getContext()) &&
       !Result.hasSideEffects()) {
     if (Result.Val.isInt())
       return RValue::get(llvm::ConstantInt::get(getLLVMContext(),

Added: cfe/trunk/test/CodeGen/no-builtin.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/no-builtin.c?rev=147655&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/no-builtin.c (added)
+++ cfe/trunk/test/CodeGen/no-builtin.c Fri Jan  6 06:20:19 2012
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fno-builtin -emit-llvm %s -o - | FileCheck %s
+//
+// Check that -fno-builtin prevents us from constant-folding through builtins
+// (PR11711)
+
+double
+cos(double x)
+{
+  printf("ok\n");
+  exit(0);
+}
+
+int
+main(int argc, char *argv[])
+{
+  cos(1); // CHECK: cos
+  printf("not ok\n");
+  abort();
+}
+





More information about the cfe-commits mailing list