[LLVMbugs] [Bug 23861] New: Frontend crash trying to evaluate constexpr (valid code)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 16 13:26:10 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23861

            Bug ID: 23861
           Summary: Frontend crash trying to evaluate constexpr (valid
                    code)
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davide at freebsd.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

[davide at 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;
   }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150616/ba359701/attachment.html>


More information about the llvm-bugs mailing list