From 8c79706e89dd2792bcc7b1e44d8f5db6abaf1617 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 27 Nov 2018 14:01:40 +0000 Subject: Revert r347417 "Re-Reinstate 347294 with a fix for the failures." This caused a miscompile in Chrome (see crbug.com/908372) that's illustrated by this small reduction: static bool f(int *a, int *b) { return !__builtin_constant_p(b - a) || (!(b - a)); } int arr[] = {1,2,3}; bool g() { return f(arr, arr + 3); } $ clang -O2 -S -emit-llvm a.cc -o - g() should return true, but after r347417 it became false for some reason. This also reverts the follow-up commits. r347417: > Re-Reinstate 347294 with a fix for the failures. > > Don't try to emit a scalar expression for a non-scalar argument to > __builtin_constant_p(). > > Third time's a charm! r347446: > The result of is.constant() is unsigned. r347480: > A __builtin_constant_p() returns 0 with a function type. r347512: > isEvaluatable() implies a constant context. > > Assume that we're in a constant context if we're asking if the expression can > be compiled into a constant initializer. This fixes the issue where a > __builtin_constant_p() in a compound literal was diagnosed as not being > constant, even though it's always possible to convert the builtin into a > constant. r347531: > A "constexpr" is evaluated in a constant context. Make sure this is reflected > if a __builtin_constant_p() is a part of a constexpr. llvm-svn: 347656 --- clang/lib/Sema/SemaInit.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'clang/lib/Sema/SemaInit.cpp') diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 12946060084..3184be80386 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -8050,9 +8050,8 @@ ExprResult InitializationSequence::Perform(Sema &S, break; } - Expr::EvalResult EVResult; - Init->EvaluateAsInt(EVResult, S.Context); - llvm::APSInt Result = EVResult.Val.getInt(); + llvm::APSInt Result; + Init->EvaluateAsInt(Result, S.Context); const uint64_t SamplerValue = Result.getLimitedValue(); // 32-bit value of sampler's initializer is interpreted as // bit-field with the following structure: -- cgit v1.2.3