Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Frontend crash trying to evaluate constexpr (valid code) #23860

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR23861
Status NEW
Importance P normal
Reported by Davide Italiano (ditaliano@apple.com)
Reported on 2015-06-16 15:26:10 -0700
Last modified on 2015-06-16 15:27:36 -0700
Version unspecified
Hardware PC FreeBSD
CC llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
[davide@rabbit1 /exps/llvm2/build/bin]$ ./clang -std=c++14 crash.cc
Assertion failed: (Result && "missing value for local variable"), function
evaluateVarDeclInit, file ../tools/clang/lib/AST/ExprConstant.cpp, line 1964.
clang-3.7: error: unable to execute command: Abort trap (core dumped)

######################

#include <iostream>

int main() {
    constexpr int i = 1;
    struct A {
        constexpr int a() { return i; }
    };
}

######################

evalValDeclInit() tries to get the value of 'VD' as temporary based on the
frame, which turns out to be null, triggering the assert.
In fact, we have the value for that VarDecl, and the following (probably wrong)
patch forces the evaluation.
I'll try to investigate further, but let's keep track this on bugzilla so I
won't forget. Ideas welcome.

(gdb) p VD->dump()
VarDecl 0x807cc7e38 <crash2.cc:4:5, col:23> col:19 referenced i 'const int'
cinit
`-IntegerLiteral 0x807cc7e98 <col:23> 'int' 1

Index: AST/ExprConstant.cpp
===================================================================
--- AST/ExprConstant.cpp        (revision 239766)
+++ AST/ExprConstant.cpp        (working copy)
@@ -1961,6 +1961,13 @@
   // If this is a local variable, dig out its value.
   if (Frame) {
     Result = Frame->getTemporary(VD);
+    // Try to evaluate the hard way.
+#if 1
+    if (!Result) {
+      VD->evaluateValue();
+      Result = VD->getEvaluatedValue();
+    }
+#endif
     assert(Result && "missing value for local variable");
     return true;
   }
Quuxplusone commented 9 years ago