LukasScheucher / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

StripPathPrefixAndGetAssociatedIncludeMap fails to differntiate absolute and relative paths on Win32 #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I've been playing with iwyu (r22 from the svn repository), running on Win7. I 
have a trivial fix from my first evening's hacking.

StripPathPrefixAndGetAssociatedIncludeMap is incorrectly differentiating 
between absolute and relative paths on Win32. With this input:

C:\dev\test_iwyu>type test.cpp
#include <math.h>
#include <stdio.h>
#include <string.h>

int main()
{
  printf( "Hello: %f\n", sinf(0.0f) );
}

I see this output:

C:\dev\test_iwyu>include-what-you-use test.cpp

test.cpp should add these lines:
#include "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include/math.h"
#include "c:\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\include/stdio.h"

test.cpp should remove these lines:
- #include <math.h>  // lines 1-1
- #include <stdio.h>  // lines 2-2
- #include <string.h>  // lines 3-3

The full include-list for test.cpp:
#include "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include/math.h"
#include "c:\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\include/stdio.h"

---

There's clearly a couple of issues here, but one that's easy to fix is iwyu 
turning the angle-bracket/system includes into quoted/'user' includes. Other 
issues aside, I'd expect to see this output:

C:\dev\test_iwyu>include-what-you-use test.cpp
test.cpp should add these lines:
#include <c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include/math.h>
#include <c:\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\include/stdio.h>

test.cpp should remove these lines:
- #include <math.h>  // lines 1-1
- #include <stdio.h>  // lines 2-2
- #include <string.h>  // lines 3-3

The full include-list for test.cpp:
#include <c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include/math.h>
#include <c:\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\include/stdio.h>

---

The attached patch should fix this. I'm using llvm::sys::path::is_relative() 
rather than checking for a leading "/". I'm on the lookout for any other issues 
along these lines...

(The bigger issue of <math.h> becoming absolute, i.e. the '// TODO(csilvers): 
get a full list of include dirs from the compiler.' is for another night :)

Regards,
Paul

Original issue reported on code.google.com by paul.hol...@gmail.com on 16 Feb 2011 at 11:48

Attachments:

GoogleCodeExporter commented 8 years ago
(BTW, although they have similar descriptions, this is a separate bug to Issue 
#5)

Original comment by paul.hol...@gmail.com on 16 Feb 2011 at 11:51

GoogleCodeExporter commented 8 years ago
Thanks!  I've applied the patch in r26

Original comment by csilv...@gmail.com on 17 Feb 2011 at 1:52