Skip to content

Commit

Permalink
[clang][analyzer] Fix a crash in alpha.unix.BlockInCriticalSection (#…
Browse files Browse the repository at this point in the history
…90030)

When analyzing C code with function pointers the checker crashes because
of how the implementation extracts `IdentifierInfo`. Without the fix, this
test crashes.
  • Loading branch information
gamesh411 authored May 15, 2024
1 parent 61da636 commit eda098a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class RAIIMutexDescriptor {
// this function is called instead of early returning it. To avoid this, a
// bool variable (IdentifierInfoInitialized) is used and the function will
// be run only once.
Guard = &Call.getCalleeAnalysisDeclContext()->getASTContext().Idents.get(
GuardName);
IdentifierInfoInitialized = true;
const auto &ASTCtx = Call.getState()->getStateManager().getContext();
Guard = &ASTCtx.Idents.get(GuardName);
}
}

Expand Down
6 changes: 6 additions & 0 deletions clang/test/Analysis/block-in-critical-section.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify %s
// expected-no-diagnostics

// This should not crash
int (*a)(void);
void b(void) { a(); }

0 comments on commit eda098a

Please sign in to comment.