Skip to content

Add -fno-builtin command line flag#5081

Merged
kinke merged 8 commits intoldc-developers:masterfrom
gnavdev28:fn_builtin
Mar 9, 2026
Merged

Add -fno-builtin command line flag#5081
kinke merged 8 commits intoldc-developers:masterfrom
gnavdev28:fn_builtin

Conversation

@gnavdev28
Copy link
Contributor

Add -fno-builtin flag

This PR implements the -fno-builtin flag to disable implicit knowledge of built-in functions, as requested in #3263.

Changes:

  • Added -fno-builtin to command-line options.
  • Attached "no-built-in" attribute to LLVM functions in codegen.
  • Added verification test tests/codegen/attr_fno_builtin.d.

Fixes part of #3263.

@gnavdev28 gnavdev28 force-pushed the fn_builtin branch 3 times, most recently from 82e1465 to b22ee17 Compare March 7, 2026 03:34
Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

also why the changes phobos?

@gnavdev28 gnavdev28 force-pushed the fn_builtin branch 2 times, most recently from f4c69da to 203d3a7 Compare March 8, 2026 03:50
extern(C) int printf(const char*, ...);

extern(C) void test_builtin() {
printf("hi reviewer\n");
Copy link
Member

@kinke kinke Mar 8, 2026

Choose a reason for hiding this comment

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

I suggest using something like https://cpp.godbolt.org/z/bGPzjrxe3 - with -fno-builtin, LDC shouldn't optimize a memcpy call etc. with -O. [And please add a trailing newline for the file, see the diff here on GitHub.]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for you suggetions!
I added a trailing newline, please take a look ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image i built and tested my code locally with `-fno-builtin` flag and it works the same as your example @kinke

Copy link
Member

Choose a reason for hiding this comment

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

I meant changing the test so that it tests something useful, e.g., breaking as soon as LLVM changes the string.

@gnavdev28
Copy link
Contributor Author

@kinke, please leave a review, thank you!

@kinke kinke merged commit a9e958a into ldc-developers:master Mar 9, 2026
23 checks passed
@gnavdev28 gnavdev28 deleted the fn_builtin branch March 9, 2026 14:21
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.

3 participants