mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
PR7242: Make sure to use a different context for evaluating constant
initializers, so the result of the evaluation doesn't leak through inconsistently. Also, don't evaluate references to variables with initializers with side-effects. llvm-svn: 113128
This commit is contained in:
@@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
|
||||
|
||||
VD->setEvaluatingValue();
|
||||
|
||||
if (Visit(const_cast<Expr*>(Init))) {
|
||||
Expr::EvalResult EResult;
|
||||
if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects &&
|
||||
EResult.Val.isInt()) {
|
||||
// Cache the evaluated value in the variable declaration.
|
||||
Result = EResult.Val;
|
||||
VD->setEvaluatedValue(Result);
|
||||
return true;
|
||||
}
|
||||
|
||||
9
clang/test/CodeGen/fold-const-declref.c
Normal file
9
clang/test/CodeGen/fold-const-declref.c
Normal file
@@ -0,0 +1,9 @@
|
||||
// RUN: %clang_cc1 -verify -emit-llvm-only
|
||||
|
||||
// PR7242: Check that this doesn't crash.
|
||||
int main(void)
|
||||
{
|
||||
int __negative = 1;
|
||||
const int __max = __negative && 0 ;
|
||||
__max / 0;
|
||||
}
|
||||
Reference in New Issue
Block a user