Skip to content

C front-end: permit taking the address of built-in functions#9118

Open
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:fix/builtin-address-of
Open

C front-end: permit taking the address of built-in functions#9118
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:fix/builtin-address-of

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

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]

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

tautschnig and others added 2 commits July 17, 2026 10:50
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 tautschnig self-assigned this Jul 17, 2026
Copilot AI review requested due to automatic review settings July 17, 2026 11:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_symbol to consult builtin_factory when a symbol lookup fails, enabling expressions like void (*f)(int) = __builtin_exit; to type-check.
  • Add a CBMC library model for __builtin_exit so calls to it can be analyzed like exit.
  • Add regression tests covering taking addresses of built-ins (ANSI-C front-end and CBMC) and direct use of __builtin_exit in 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

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.77%. Comparing base (f5bf9cc) to head (e8177e2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Successfully merging this pull request may close these issues.

Conversion error when taking the address of a gcc built-in function

2 participants