Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverse expression IR for casts is sometime incorrect #1211

Open
dtarditi opened this issue Oct 12, 2024 · 0 comments
Open

Inverse expression IR for casts is sometime incorrect #1211

dtarditi opened this issue Oct 12, 2024 · 0 comments

Comments

@dtarditi
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant