[llvm-bugs] [Bug 38091] New: No support for gcc "error" function attribute
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 7 12:25:20 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38091
Bug ID: 38091
Summary: No support for gcc "error" function attribute
Product: clang
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: naruse at airemix.jp
CC: llvm-bugs at lists.llvm.org
GCC 4.3 supports "error" function attribute, but clang doesn't support it.
https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Function-Attributes.html#index-g_t_0040code_007berror_007d-function-attribute-2123
Below description is why I want clang to implement this.
This attribute is similar to "diagnose_if" and "enable_if" function attribute.
But "error" function attribute behaves different and useful.
```c
int rb_scan_args_bad_format(const char *fmt,int ofs)
__attribute__((diagnose_if(fmt, "bad scan arg format","error")));
int
main(int argc, char **argv) {
if (0) {
rb_scan_args_bad_format("foo", 3);
}
}
```
clang show error above code though the function call is optimized out.
But gcc successfully compiles below code.
```c
int rb_scan_args_bad_format(const char *fmt,int ofs)
__attribute__((error("bad scan arg format")));
int
main(int argc, char **argv) {
if (0) {
rb_scan_args_bad_format("foo", 3);
}
}
```
For example Ruby uses this feature in rb_scan_args.
https://github.com/ruby/ruby/blob/v2_5_1/include/ruby/ruby.h
Its behavior is explained in
https://silverhammermba.github.io/emberb/c/#parsing-arguments
Recent Ruby uses macros to implement it in order to handle its argument at
compile time.
And it uses "error" function attribute if its format argument is invalid.
In this use case, "error" function attribute's ignored if optimized out
behavior is very useful.
This is why I want clang also implement "error" function attribute.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180707/60f45fac/attachment.html>
More information about the llvm-bugs
mailing list