Skip to content

Commit

Permalink
[clang][Interp] Fix nullptr - nullptr expressions
Browse files Browse the repository at this point in the history
They can happen and we used to run into an assertion.
  • Loading branch information
tbaederr committed Feb 19, 2024
1 parent 8d8bb35 commit 17a1b8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/AST/Interp/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,11 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
return false;
}

if (LHS.isZero() && RHS.isZero()) {
S.Stk.push<T>();
return true;
}

T A = T::from(LHS.getIndex());
T B = T::from(RHS.getIndex());
return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, A.bitWidth(), A, B);
Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,10 @@ namespace rdar8769025 {
f1(0); // both-warning{{null passed to a callee that requires a non-null argument}}
}
}

namespace nullptrsub {
void a() {
char *f = (char *)0;
f = (char *)((char *)0 - (char *)0);
}
}

0 comments on commit 17a1b8f

Please sign in to comment.