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: unassignedclangb...@nondot.org
Reporter: nar...@airemix.jp
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs