Support for __attribute__((no_builtin("foo"))) was added in https://reviews.llvm.org/D68028,
but builtins were still being used even when the attribute was placed on a function.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
If I understand correctly, D68028 made it so that LLVM doesn't add any builtin calls (e.g. turning for-loops into memcpy), but Clang could still turn calls into builtins. Maybe the patch description could be expanded to explain this?
clang/lib/CodeGen/CGExpr.cpp | ||
---|---|---|
5068 | What if CurFn has the "wildcard" no-builtins attribute? |
FWIW, it looks like precommit CI found issues in the newly added test which should be addressed.
clang/test/CodeGen/no-builtin-2.c | ||
---|---|---|
4 | You shouldn't include system headers -- that will pull from whatever is installed on the test system. If you included this for size_t, you can do something like: typedef __typeof_(sizeof(0)) size_t; to work around it. |
I'm not too sure, but I think D68028 just adds the attribute nobuiltin, but it gets ignored. It doesn't seem to affect the calls in the function. They're still being converted into builtins even with the attribute on the function.
clang/lib/CodeGen/CGExpr.cpp | ||
---|---|---|
5068 | Hmmm, good question. Currently, "*" generates a warning. I was able to get "*" to add the attribute no-builtins to the function, but if I try making it affect the calls in the function, I see a compiler crash when compiling compiler-rt. It looks like some builtins must be generated even if -fno-builtins is called such as __sync_lock_test_and_set_1. I'm not sure how to check for that. |
Update patch to accept attribute((no_builtin("*")). It adds no-builtins to the function attributes, but it still doesn't affect the calls. The calls in the function still become builtin calls.
Correct -- that commit was just adding the attribute and ensuring it parsed correctly and met semantic requirements. That's why its documentation says .. Note:: This attribute is not yet fully implemented, it is validated but has no effect on the generated code. There is more interesting discussion in https://reviews.llvm.org/D61634 that relates.
clang/lib/CodeGen/CGExpr.cpp | ||
---|---|---|
5068 | I think you're looking for isPredefinedLibFunction() |
- Added isPredefinedLibFunction() check
- Added testcase for __attribute__((no_builtin("*")))
I think the only thing missing is an update to the documentation: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/AttrDocs.td#L5999, and add a release note about the change in functionality.
clang/test/CodeGen/no-builtin-2.c | ||
---|---|---|
52 | In AttrDocs.td it says the wildcard case is spelled "attribute((no_builtin))". |
clang/test/CodeGen/no-builtin-2.c | ||
---|---|---|
52 | Ah whoops, missed that. I don't think I need the changes in SemaDeclAttr.cpp then. Thanks for catching this! |
- Removed __attribute__((no_builtin("*"))) from test
- Remove the logic that accepted __attribute__((no_builtin("*")))
Just one more comment, then I'm happy :)
clang/lib/CodeGen/CGExpr.cpp | ||
---|---|---|
5067 | The comment needs updating too (for the wildcard thing). |
Might as well use a Twine since the next line uses one as well.