Skip to content

Commit 17a1b8f

Browse files
committed
[clang][Interp] Fix nullptr - nullptr expressions
They can happen and we used to run into an assertion.
1 parent 8d8bb35 commit 17a1b8f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,11 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
15791579
return false;
15801580
}
15811581

1582+
if (LHS.isZero() && RHS.isZero()) {
1583+
S.Stk.push<T>();
1584+
return true;
1585+
}
1586+
15821587
T A = T::from(LHS.getIndex());
15831588
T B = T::from(RHS.getIndex());
15841589
return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, A.bitWidth(), A, B);

clang/test/AST/Interp/literals.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,3 +1124,10 @@ namespace rdar8769025 {
11241124
f1(0); // both-warning{{null passed to a callee that requires a non-null argument}}
11251125
}
11261126
}
1127+
1128+
namespace nullptrsub {
1129+
void a() {
1130+
char *f = (char *)0;
1131+
f = (char *)((char *)0 - (char *)0);
1132+
}
1133+
}

0 commit comments

Comments
 (0)