Skip to content

Commit 7437545

Browse files
committed
[libclang] Fix hang in release / assertion in debug when evaluating value-dependent types.
Expression evaluator doesn't work in value-dependent types, so ensure that the precondition it asserts holds. This fixes https://bugs.llvm.org/show_bug.cgi?id=42532 Differential Revision: https://reviews.llvm.org/D64409 llvm-svn: 365490
1 parent e0a3ee7 commit 7437545

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/test/Index/evaluate-cursor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ unsigned long long HUGE = 1ull << 63;
2121

2222
long long HUGE_NEG = -(1ll << 35);
2323

24+
template <typename d> class e {
25+
using f = d;
26+
static const auto g = alignof(f);
27+
};
28+
2429
// RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
2530
// RUN: -evaluate-cursor-at=%s:8:7 \
2631
// RUN: -evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -42,3 +47,9 @@ long long HUGE_NEG = -(1ll << 35);
4247
// CHECK-LONG: unsigned, Value: 1152921504606846976
4348
// CHECK-LONG: unsigned, Value: 9223372036854775808
4449
// CHECK-LONG: Value: -34359738368
50+
51+
// RUN: c-index-test -evaluate-cursor-at=%s:18:20 \
52+
// RUN: -evaluate-cursor-at=%s:20:20 \
53+
// RUN: -evaluate-cursor-at=%s:26:21 \
54+
// RUN: -std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
55+
// CHECK-DOES-NOT-CRASH: Not Evaluatable

clang/tools/libclang/CIndex.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,8 @@ static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) {
37823782
return nullptr;
37833783

37843784
expr = expr->IgnoreParens();
3785+
if (expr->isValueDependent())
3786+
return nullptr;
37853787
if (!expr->EvaluateAsRValue(ER, ctx))
37863788
return nullptr;
37873789

0 commit comments

Comments
 (0)