Open
Description
While doing the upgrade to clang 17 sources, I found that a compiler assert was failing in a new test that was added to clang-17: test/Sema/pointer-subtraction.c
.
#3 0x00007ff67d2383dd llvm::llvm_unreachable_internal(char const *, char const *, unsigned int) ... llvm\lib\Support\ErrorHandling.cpp:212:0
#4 0x00007ff6861abd97 `anonymous namespace'::IntExprEvaluator::VisitCastExpr ... clang\lib\AST\ExprConstant.cpp:13583:0
A minimal cut-down case is:
void a(void) {
char *f = (char *)0;
f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}};
f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
}
I tracked the assert failure to incorrect IR being created for inverse expressions for casts in lib/AST/ExprUtils.cpp in the InverseUtil
class. The problem is that some cast operators need to be inverted too. For example CK_IntegralToPointer
needs to be inverted to CK_PointerToIntegral
.
Metadata
Metadata
Assignees
Labels
No labels