C front-end: permit taking the address of built-in functions#9118
Open
tautschnig wants to merge 2 commits into
Open
C front-end: permit taking the address of built-in functions#9118tautschnig wants to merge 2 commits into
tautschnig wants to merge 2 commits into
Conversation
Referencing a built-in function outside a direct call, such as when taking its address, failed with "failed to find symbol" (CONVERSION ERROR) because only typecheck_side_effect_function_call would consult builtin_factory to add declarations of built-ins on demand. Also try builtin_factory when a symbol expression fails to resolve, so that code like 'void (*f)(int) = __builtin_exit;' type-checks. Direct calls to built-ins that CBMC rewrites into expressions are unaffected, as that rewriting happens for all calls irrespective of a symbol table entry. Calls via function pointers to built-ins without a library model continue to be flagged by the no-body checks. Fixes: diffblue#8811 Co-authored-by: Kiro <[email protected]>
GCC permits taking the address of __builtin_exit and calling it like a regular function. Model it like exit so that programs referencing __builtin_exit can be verified instead of failing the no-body check. Co-authored-by: Kiro <[email protected]>
tautschnig
requested review from
kroening,
peterschrammel and
remi-delmas-3000
as code owners
July 17, 2026 11:05
There was a problem hiding this comment.
Pull request overview
This PR fixes a C front-end limitation where referencing GCC/Clang built-in functions outside of direct calls (e.g., taking their address) could fail during typechecking due to missing on-demand builtin declarations, addressing #8811.
Changes:
- Extend
c_typecheck_expr_symbolto consultbuiltin_factorywhen a symbol lookup fails, enabling expressions likevoid (*f)(int) = __builtin_exit;to type-check. - Add a CBMC library model for
__builtin_exitso calls to it can be analyzed likeexit. - Add regression tests covering taking addresses of built-ins (ANSI-C front-end and CBMC) and direct use of
__builtin_exitin the library suite.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ansi-c/library/stdlib.c | Adds a library implementation for __builtin_exit. |
| src/ansi-c/c_typecheck_expr.cpp | Tries builtin_factory when resolving an unresolved symbol expression. |
| regression/cbmc/gcc_builtins_address_of/test.desc | Adds CBMC regression for address-of builtins. |
| regression/cbmc/gcc_builtins_address_of/main.c | Test program taking addresses of builtins and using them. |
| regression/cbmc-library/__builtin_exit/test.desc | Adds regression ensuring __builtin_exit is modeled and usable. |
| regression/cbmc-library/__builtin_exit/main.c | Test program calling __builtin_exit. |
| regression/ansi-c/gcc_builtins_address_of/test.desc | Adds ANSI-C front-end regression for address-of builtins. |
| regression/ansi-c/gcc_builtins_address_of/main.c | Test program for front-end-only address-of builtins. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+113
to
+117
| void __builtin_exit(int status) | ||
| { | ||
| (void)status; | ||
| __CPROVER_assume(0); | ||
| } |
Comment on lines
+7
to
+9
| -- | ||
| ^warning: ignoring | ||
| ^CONVERSION ERROR$ |
Comment on lines
+6
to
+8
| -- | ||
| ^warning: ignoring | ||
| ^CONVERSION ERROR$ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9118 +/- ##
===========================================
- Coverage 80.77% 80.77% -0.01%
===========================================
Files 1712 1712
Lines 189814 189815 +1
Branches 73 73
===========================================
- Hits 153328 153326 -2
- Misses 36486 36489 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Referencing a built-in function outside a direct call, such as when taking its address, failed with "failed to find symbol" (CONVERSION ERROR) because only typecheck_side_effect_function_call would consult builtin_factory to add declarations of built-ins on demand.
Also try builtin_factory when a symbol expression fails to resolve, so that code like 'void (*f)(int) = __builtin_exit;' type-checks. Direct calls to built-ins that CBMC rewrites into expressions are unaffected, as that rewriting happens for all calls irrespective of a symbol table entry. Calls via function pointers to built-ins without a library model continue to be flagged by the no-body checks.
Fixes: #8811
Co-authored-by: Kiro [email protected]