clang behaves differently with gcc when compiling
a file with -H option, gcc will omit the "./", but
clang will not. I fix it to make clang more
compatible with gcc.
Details
Diff Detail
Event Timeline
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
56 | Formatting |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | Need remove ";" ? |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | This was fixed but no test was added? |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | The extra semicolon would have caused the body of the 'if' to execute unconditionally. Did any existing test case fail for that in your local testing? Or did you not test with that mistake? |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | i fixed the mistake in the updated patch. I ran the test in 'clang_H_opt.c' alone for this patch. The extra semicolon caused the body of if to exeute always, which didn't cause the test to fail. |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 |
That is the question. |
Do you mean "\\" separator? i build llvm on windows, and use clang to complie file with -H option. The output pathname also use "/" as path separator, so i think we don't need to consider the "\\" separator.
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | No. I just run alll the tests for clang, and all of them can pass even if the extra semicolon exits. If we want to add a test to cover that error, we have to add a headerfile outside the 'test/Driver' directory. Do we need to add the test to cover that error? |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | Then yes please, do add test coverage for that bug :) |
lib/Frontend/HeaderIncludeGen.cpp | ||
---|---|---|
55 | test for that bug has been added in the new patch |
I was thinking about a testcase like:
// RUN: %clang -H -fsyntax-only %s 2>&1 | FileCheck %s #include "..\Index\Inputs\empty.h" #include ".\Inputs\empty.h" // CHECK: . // CHECK-SAME: ??? // CHECK: . // CHECK-NOT: ??? // CHECK-SAME: ???
with some provision for running it in a Windows environment.
Not sure what the expected behavior should be, hence the ???
Firstly, on linux
write the clang_H_opt.c file as
#include "../Index/Inputs/empty.h" #include "Inputs/empty.h" #include "./Inputs/empty.h" #include "././Inputs/empty.h"
Then compile it with command gcc -H -fsyntax-only clang_H_opt.c 2>&1,
output:
. ../Index/Inputs/empty.h . Inputs/empty.h . ./Inputs/empty.h . ././Inputs/empty.h
compile it with command clang -H -fsyntax-only clang_H_opt.c 2>&1 will get the same result . So i think there is no need to simplify the existing pathname in #include directive.
Secondly, on Win2019
write the clang_H_opt.c file as
#include "..\Index\Inputs\empty.h" #include "Inputs/empty.h" #include ".\Inputs/empty.h" #include ".\.\Inputs/empty.h"
compile it with clang,
output:
. ..\\Index\\Inputs\\empty.h . Inputs\\empty.h . .\\Inputs\\empty.h . .\\.\\Inputs\\empty.h
i think the output is appropriate.
I think the test needs a bit more work. It's essentially checking the same thing twice to exercise the Windows path separators.
It looks like there's already a test for -H in FrontEnd/print-header-includes.c. That also demonstrates the use of --check-prefix to handle target-specific stuff. Maybe you could fold this into there?
I'm not active in the project, so I don't feel comfortable accepting. See if you can find a contributor to sign it off.
Need remove ";" ?