[LLVMbugs] [Bug 10427] New: clang should warn if a macro argument expansion is "obviously" missing parentheses
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jul 20 08:32:51 PDT 2011
http://llvm.org/bugs/show_bug.cgi?id=10427
Summary: clang should warn if a macro argument expansion is
"obviously" missing parentheses
Product: clang
Version: trunk
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: nicolasweber at gmx.de
CC: llvmbugs at cs.uiuc.edu
Consider this bug from the valgrind sources:
hummer:src thakis$ cat test.c
#include <stdio.h>
struct vki_timeval {
int a, b, c, d, e;
};
#define PRE_timeval_READ(zzname, zzarg) \
do { \
struct vki_timeval *zztv = (struct vki_timeval *)zzarg; \
printf("Note: %s %d\n", zzname, zztv->c); \
} while (0)
int main() {
struct vki_timeval vals[3] = {
{ 1, 1, 1, 1, 1 },
{ 2, 2, 2, 2, 2 },
{ 3, 3, 3, 3, 3 }
};
void* tvp = &vals[0];
PRE_timeval_READ( "futimes(tvp[1])", tvp+sizeof(struct vki_timeval) );
}
hummer:src thakis$ gcc test.c -o foo
hummer:src thakis$ ./foo
Note: futimes(tvp[1]) 1836213620
The fix for the bug is (note the added parens):
struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \
Clang could maybe warn if something in a macro (here: the cast) binds with a
high precendence to only parts of a macro argument (here
"tvp+sizeof(vki_timeval)") or some such.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list