Skip to content

Commit bc034ba

Browse files
committed
[clang][Interp] Protect InitPtr from non-initializable pointers
This can happen when an initializer returns a dummy pointer.
1 parent ba451c8 commit bc034ba

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,13 +1278,16 @@ inline bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
12781278

12791279
inline bool InitPtrPop(InterpState &S, CodePtr OpPC) {
12801280
const Pointer &Ptr = S.Stk.pop<Pointer>();
1281-
Ptr.initialize();
1281+
if (Ptr.canBeInitialized())
1282+
Ptr.initialize();
12821283
return true;
12831284
}
12841285

12851286
inline bool InitPtr(InterpState &S, CodePtr OpPC) {
12861287
const Pointer &Ptr = S.Stk.peek<Pointer>();
1287-
Ptr.initialize();
1288+
1289+
if (Ptr.canBeInitialized())
1290+
Ptr.initialize();
12881291
return true;
12891292
}
12901293

clang/test/AST/Interp/complex.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -Wno-unused-value %s
2+
// RUN: %clang_cc1 -verify=ref,both -Wno-unused-value %s
3+
4+
// expected-no-diagnostics
5+
// ref-no-diagnostics
6+
7+
void blah() {
8+
__complex__ unsigned xx;
9+
__complex__ signed yy;
10+
__complex__ int result;
11+
12+
/// The following line calls into the constant interpreter.
13+
result = xx * yy;
14+
}

0 commit comments

Comments
 (0)