r336364 - Fix __builtin_*_overflow when out-param isn't constexpr

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 5 08:52:58 PDT 2018


Author: erichkeane
Date: Thu Jul  5 08:52:58 2018
New Revision: 336364

URL: http://llvm.org/viewvc/llvm-project?rev=336364&view=rev
Log:
Fix __builtin_*_overflow when out-param isn't constexpr

As brought up on cfe-commits[1], r334650 causes the dependency of the
out parameter to the __builtin_*_overflow functions to be ignored. The result
was a usage that was otherwise constexpr (both operands to the operation were
constexpr) would be evaluated, but the out parameter wouldn't be modified, so
it would still be 'undef'.

This patch correctly handles the return value of handleAssignment to ensure that
this value is properly considered/evaluated.

[1] http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180702/233667.html

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CodeGenCXX/builtins.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=336364&r1=336363&r2=336364&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jul  5 08:52:58 2018
@@ -8346,7 +8346,8 @@ bool IntExprEvaluator::VisitBuiltinCallE
     }
 
     APValue APV{Result};
-    handleAssignment(Info, E, ResultLValue, ResultType, APV);
+    if (!handleAssignment(Info, E, ResultLValue, ResultType, APV))
+      return false;
     return Success(DidOverflow, E);
   }
   }

Modified: cfe/trunk/test/CodeGenCXX/builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtins.cpp?rev=336364&r1=336363&r2=336364&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/builtins.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtins.cpp Thu Jul  5 08:52:58 2018
@@ -30,3 +30,19 @@ long y = __builtin_abs(-2l);
 extern const char char_memchr_arg[32];
 char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32);
 // CHECK: call i8* @memchr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @char_memchr_arg, i32 0, i32 0), i32 123, i64 32)
+
+int constexpr_overflow_result() {
+  constexpr int x = 1;
+  // CHECK: alloca i32
+  constexpr int y = 2;
+  // CHECK: alloca i32
+  int z;
+  // CHECK: [[Z:%.+]] = alloca i32
+
+  __builtin_sadd_overflow(x, y, &z);
+  return z;
+  // CHECK: [[RET_PTR:%.+]] = extractvalue { i32, i1 } %0, 0
+  // CHECK: store i32 [[RET_PTR]], i32* [[Z]]
+  // CHECK: [[RET_VAL:%.+]] = load i32, i32* [[Z]]
+  // CHECK: ret i32 [[RET_VAL]]
+}




More information about the cfe-commits mailing list