[LLVMbugs] [Bug 10215] New: Location of argument to function style macro not correctly tracked

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 28 00:14:56 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10215

           Summary: Location of argument to function style macro not
                    correctly tracked
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: chandlerc at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6796)
 --> (http://llvm.org/bugs/attachment.cgi?id=6796)
Patch originally proposed for PR9279

This is reduced from two of several test cases I provided as part of my patch
to PR9279. It also contributes to the final problem listed on the original PR.

Given:
% cat x2.c
#define macro_args1(x) x
#define macro_args2(x) macro_args1(x)
#define macro_args3(x) macro_args2(x)

#define macro_many_args1(x, y, z) y
#define macro_many_args2(x, y, z) macro_many_args1(x, y, z)
#define macro_many_args3(x, y, z) macro_many_args2(x, y, z)

void test() {
  macro_many_args3(
    1,
    2,
    3);

  macro_many_args3(
    1,
    macro_args2(2),
    3);
}

Clang currently prints (after Chris's patch for PR9279):
% ./bin/clang -fsyntax-only x2.c
x2.c:14:3: warning: expression result unused [-Wunused-value]
  macro_many_args3(
  ^~~~~~~~~~~~~~~~~
x2.c:9:35: note: instantiated from:
#define macro_many_args3(x, y, z) macro_many_args2(x, \
                                  ^
x2.c:6:35: note: instantiated from:
#define macro_many_args2(x, y, z) macro_many_args1(x, \
                                  ^
x2.c:14:3: note: instantiated from:
    2,
    ^
x2.c:19:3: warning: expression result unused [-Wunused-value]
  macro_many_args3(
  ^~~~~~~~~~~~~~~~~
x2.c:9:35: note: instantiated from:
#define macro_many_args3(x, y, z) macro_many_args2(x, \
                                  ^
x2.c:6:35: note: instantiated from:
#define macro_many_args2(x, y, z) macro_many_args1(x, \
                                  ^
x2.c:19:3: note: instantiated from:
    macro_args2(2),
    ~~~~~~~~~~~~^~
2 warnings generated.

The incorrect source locations of the arguments to the function style macro
manifest as a number of problems with these two diagnostics.

The first one shows that the warning location is at the start of the macro
rather than the argument to the macro which was actually used to produce the
error. Also, the intermediate notes don't point to where the function style
macro argument occurred within the definition; in this case, it isn't even the
correct line of the file.

The second has the same problems as the first, but compounded by the fact that
there is an entire macro involved in the error which isn't expanded at all; we
don't know what macro_args2 actually leads to.

With my patch for PR9279 we get about the best I would expect from Clang here:
% ./bin/clang -fsyntax-only x2.c
x2.c:16:5: warning: expression result unused [-Wunused-value]
    2,
    ^~
x2.c:10:52: note: instantiated from:
                                                   y, \
                                                   ^
x2.c:7:52: note: instantiated from:
                                                   y, \
                                                   ^
x2.c:5:35: note: instantiated from:
#define macro_many_args1(x, y, z) y
                                  ^
x2.c:21:17: warning: expression result unused [-Wunused-value]
    macro_args2(2),
    ~~~~~~~~~~~~^~~
x2.c:2:36: note: instantiated from:
#define macro_args2(x) macro_args1(x)
                                   ^
x2.c:1:24: note: instantiated from:
#define macro_args1(x) x
                       ^
x2.c:10:52: note: instantiated from:
                                                   y, \
                                                   ^
x2.c:7:52: note: instantiated from:
                                                   y, \
                                                   ^
x2.c:5:35: note: instantiated from:
#define macro_many_args1(x, y, z) y
                                  ^
2 warnings generated.

The test case is a stress test, but it highlights real problems we hit with
Clang diagnostics in real code. 

I've attached (an updated version of) my patch for PR9279 so that people can
replicate these. Note that fixing this bug also (almost necessarily) fixes
PR10214. I'm breaking them up as requested by Chris. More details on the patch,
the reasoning that led to it, performance analysis and memory consumption can
be read on PR9279 where it was originally proposed.

-- 
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