Hello,
Unlike gcc, clang does not provide builtin functions for functions in ctype.h, such as tolower. To generated better optimized code, I’m planning to add these functions as builtins with attributes. Regarding this, I have a few questions:
- In “Attributes in Clang” page (http://clang.llvm.org/docs/AttributeReference.html), “nothrow” and “const” are not in the list while they are still used in Builtins.def. Are these attributes deprecated?
- (Assuming they are not deprecated) Is there a place that I can find definitions for attributes used in builtins.def? In particular, I wonder if “const” attributes of clang has same meaning with gcc’s “const” attribute, as it seems that clang does not support “pure” attribute.
Thanks,
Taewook
Hello,
Unlike gcc, clang does not provide builtin functions for functions in
ctype.h, such as tolower. To generated better optimized code, I'm planning
to add these functions as builtins with attributes. Regarding this, I have
a few questions:
1. In "Attributes in Clang" page (
Attributes in Clang — Clang 18.0.0git documentation), "nothrow" and
"const" are not in the list while they are still used in Builtins.def. Are
these attributes deprecated?
No, they're just not documented yet. (We'd appreciate patches to
include/clang/AttrDocs.td and include/clang/Attr.td if you're feeling
enthusiastic, but note that this needs to be original documentation -- it
wouldn't be acceptable to copy documentation from GCC due to license
differences.)
1. (Assuming they are not deprecated) Is there a place that I can find
definitions for attributes used in builtins.def? In particular, I wonder if
"const" attributes of clang has same meaning with gcc's "const" attribute,
as it seems that clang does not support "pure" attribute.
Yes, the attributes listed in clang's Builtins.def are the
__attribute__((X)) form, which generally mean the same thing to Clang as
they do to GCC (with rare exceptions).
Thank you for your reply. I wonder if clang does not support “pure” attribute at all, or has a different name for it.
Thanks,
Taewook
Clang does support it, under the same name, but it looks like we don’t apply it to any builtin functions (yet). It seems appropriate for the is* and to* functions (if there are functions rather than macros) to be const rather than just pure, though, as they do not access memory that is visible to the caller.
Thank you for your reply. I wonder if clang does not support "pure"
attribute at all, or has a different name for it.
Clang does support __attribute__((pure)); see Attr.td:1309, and it
affecting codegen in CGCall.cpp:1639 for more details.
~Aaron
What kind of optimisation do you have planned? Especially, keep in mind
that setlocale() is a global property...
Joerg