[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Evan Wilde via cfe-commits

etcwilde wrote:

Here, I'd missed adding `vt_gen` as something that one could pick up through 
the cmake config. Can you try a standalone build with the changes here? 
https://github.com/llvm/llvm-project/pull/109817
Thanks.

https://github.com/llvm/llvm-project/pull/109601
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Evan Wilde via cfe-commits

etcwilde wrote:

This drops the dependency edge between the compile step and generating 
`GenVT.inc` though. There was already a (indirect) dependency between the link 
step of `clangCodeGen` and generating `GetnVT.inc`.
Perhaps LLVM should export `vt_gen` like it does `intrinsics_gen` so that 
standalone builds can pick it up?

https://github.com/llvm/llvm-project/pull/109601
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (PR #109306)

2024-09-19 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde closed 
https://github.com/llvm/llvm-project/pull/109306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add missing deps edge: CodeGenAction.cpp.o -> GenVT.inc (PR #109306)

2024-09-19 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde created 
https://github.com/llvm/llvm-project/pull/109306

CodeGenAction.cpp.o depends on generating GenVT.inc before trying to compile it 
through the following header chain:

```
GenVT.inc
MachineValueType.h
LowLevelType.h
MachineMemOperand.h
MachineInstr.h
MachineBasicBlock.h
MachineFunctionPass.h
MachineOptimizationRemarkEmitter.h
CodeGenAction.cpp
```

There is a dependency edge through LLVMCodeGenTypes, but that edge is applied 
to the clangCodeGen link step, not the compile step of the files that make up 
clangCodeGen. Usually the compile and link are close enough in the build that 
GenVT.inc is scheduled early enough that it exists by the time we're compiling 
CodeGenAction.cpp.o, but on machines with high core counts, it seems to be more 
prevalent that the scheduling works out just right to expose the missing edge. 
I've only been able to reproduce this on machines with at least 64 cores (but 
even then it was not reliable).

Additionally, llvm-tblgen depends on GenVT.inc, so to see the missing 
dependency edge, one must be using a pre-built tablegen binary.

Adding the missing dependency edge to ensure that GenVT.inc is generated before 
trying to compile CodeGenAction.cpp.o.

Found by inspecting the dependency graph generated from Ninja with:

```sh
cmake -G 'Ninja' \
  ...
  -DLLVM_TABLEGEN= \
  -DCLANG_TABLEGEN= \
  -DLLVM_ENABLE_PROJECTS=clang \
  ...

ninja -t graph \
  tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CodeGenAction.cpp.o | 
dot -Tpdf > CodeGenAction.pdf
```

>From 351362ad191a03d4b8dfcb0be330ee846956fe19 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Thu, 19 Sep 2024 08:45:49 -0700
Subject: [PATCH] Add missing deps edge: CodeGenAction -> GenVT

CodeGenAction.cpp.o depends on generating GenVT.inc before trying to
compile it through the following header chain:

```
GenVT.inc
MachineValueType.h
LowLevelType.h
MachineMemOperand.h
MachineInstr.h
MachineBasicBlock.h
MachineFunctionPass.h
MachineOptimizationRemarkEmitter.h
CodeGenAction.cpp
```

There is a dependency edge through LLVMCodeGenTypes, but that edge is
applied to the clangCodeGen link step, not the compile step of the files
that make up clangCodeGen. Usually the compile and link are close enough
in the build that GenVT.inc is scheduled early enough that it exists by
the time we're compiling CodeGenAction.cpp.o, but on machines with high
core counts, it seems to be more prevalent that the scheduling works out
just right to expose the missing edge. I've only been able to reproduce
this on machines with at least 64 cores (but even then it was not
reliable).

Additionally, llvm-tblgen depends on GenVT.inc, so to see the missing
dependency edge, one must be using a pre-built tablegen binary.

Adding the missing dependency edge to ensure that GenVT.inc is generated
before trying to compile CodeGenAction.cpp.o.

Found by inspecting the dependency graph generated from Ninja with:

```sh
cmake -G 'Ninja' \
  ...
  -DLLVM_TABLEGEN= \
  -DCLANG_TABLEGEN= \
  -DLLVM_ENABLE_PROJECTS=clang \
  ...

ninja -t graph \
  tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CodeGenAction.cpp.o | 
dot -Tpdf > CodeGenAction.pdf
```
---
 clang/lib/CodeGen/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index aa0c871c5352a8..868ec847b9634b 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -144,6 +144,7 @@ add_clang_library(clangCodeGen
   VarBypassDetector.cpp
 
   DEPENDS
+  vt_gen
   intrinsics_gen
   ClangDriverOptions
   # These generated headers are included transitively.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-08-02 Thread Evan Wilde via cfe-commits

etcwilde wrote:

> We can't really help you with whatever is wrong with Debian's packages unless 
> it is a bug caused by our build configurations. The change you're proposing 
> in this PR could just as easily be impacted in some distro's packages.

The exported target is new and hasn't been in a release yet. It should be in 
LLVM-19 once it's released and Debian gets updated. Of course, this is also 
true of any other new thing that gets added now anyway.

I am a little confused about what your goal is with the path manipulations 
though. The part of IWYU that is 
[linked](https://github.com/include-what-you-use/include-what-you-use/blob/master/CMakeLists.txt#L54)
 above is looking for the `clang-resource-headers` target if one exists, or 
trying to find the include directory. I'm not familiar with how IWYU works 
either though. It kind of looks like it's embedding a copy of clang (sort of 
like how Swift does), in which case, it should embed the resource headers that 
match that clang and you should know where you're installing them. If that's 
not the case and it's invoking `clang` somewhere, then passing 
`-print-resource-dir` to that clang will give you the resource directory, and 
then the headers are under the `include` directory there. But in both cases, 
from what I can tell, you're asking about where the headers are, which is what 
the `clang-resource-headers` target contains. What other bits are you looking 
for in the resource directory?

https://github.com/llvm/llvm-project/pull/97197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-07-25 Thread Evan Wilde via cfe-commits

etcwilde wrote:

> That forces us back to the original discussion about exporting 
> CLANG_RESOURCE_DIR

The path is already available through the exported `clang-resource-header` 
imported interface target.

https://github.com/llvm/llvm-project/pull/97197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-07-12 Thread Evan Wilde via cfe-commits

etcwilde wrote:

So, Swift actually has/had a similar issue. We embed a copy of clang in Swift, 
so we needed to find the corresponding clang resource headers and install them 
with our compiler which is why I wrote 
https://github.com/llvm/llvm-project/pull/88317 to expose them. It adds the 
clang-resource-headers as an interface library to the ClangConfig.cmake that 
gets loaded when you do `find_package(Clang CONFIG)`. "Linking" against that 
interface library adds the clang-resource-header location to your include 
search paths.

```cmake
# Find 'ClangConfig.cmake' and import its targets
find_package(Clang CONFIG REQUIRED)

# Pass the location as a header-search path to "SomeLibrary"
target_link_libraries(SomeLibrary PRIVATE clang-resource-headers)

# Alternatively, if you just want the location, it's available as a 
target-property:
get_target_property(CLANG_IMPORT_HEADERS clang-resource-headers 
INTERFACE_INCLUDE_DIRECTORIES)
```

To install the `ClangConfig.cmake` and the clang cmake exports files in the 
LLVM build/install, I believe the install component is `clang-cmake-exports`.

https://github.com/llvm/llvm-project/pull/97197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix missing installed header (PR #95979)

2024-06-20 Thread Evan Wilde via cfe-commits

etcwilde wrote:

@danielotero Thank you for your contribution.

https://github.com/llvm/llvm-project/pull/95979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix missing installed header (PR #95979)

2024-06-20 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde closed 
https://github.com/llvm/llvm-project/pull/95979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix missing installed header (PR #95979)

2024-06-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde approved this pull request.

Nice find. That's kind of horrifying. I'm fine with flipping the file order to 
avoid the source file caching bug in CMake.
CC @compnerd since he also knows CMake and may have opinions.

https://github.com/llvm/llvm-project/pull/95979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Revert "NFC: Make clang resource headers an interface library (#88317)" (PR #89266)

2024-04-20 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde closed 
https://github.com/llvm/llvm-project/pull/89266
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Revert "NFC: Make clang resource headers an interface library (#88317)" (PR #89266)

2024-04-20 Thread Evan Wilde via cfe-commits

etcwilde wrote:

Great, glad to hear that you figured out what was happening. I wasn't sure how 
the target would end up in the clang-export list and not be defined since the 
bit of code that adds it to the clang-export list isn't conditionalized any 
differently than the creation of the target itself.

https://github.com/llvm/llvm-project/pull/89266
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Revert "NFC: Make clang resource headers an interface library (#88317)" (PR #89266)

2024-04-18 Thread Evan Wilde via cfe-commits

etcwilde wrote:

@ayermolo, one idea might be to see if `clang-resource-headers` is in the 
install distribution list? I'm not seeing a matching `get_property` in a 
CMakeLists.txt that matches the above error exactly, so I'm not sure how to 
reproduce this or how you're picking up the clang-resource-headers target.

https://github.com/llvm/llvm-project/pull/89266
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] Revert "NFC: Make clang resource headers an interface library (#88317)" (PR #89266)

2024-04-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde created 
https://github.com/llvm/llvm-project/pull/89266

This reverts commit 8d468c132eed7ffe34d601b224220efd51655eb3.

@ayermolo reports seeing the following error when the clang-resource-headers 
are a library instead of a custom target:
```
CMake Error at CMakeLists.txt:86 (get_property):
  get_property could not find TARGET clang-resource-headers.  Perhaps it has
  not yet been created.
```
I don't see this line in the LLVM repository, and I'm not sure how it worked as 
a custom target since this change doesn't affect whether or not the CMake 
target is generated, nor does it impact the order that targets are created in. 

>From 9b16756a69ddbce1e586535e931f7c2b923ff2ba Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Thu, 18 Apr 2024 09:58:52 -0700
Subject: [PATCH 1/2] Revert "NFC: Make clang resource headers an interface
 library (#88317)"

This reverts commit 8d468c132eed7ffe34d601b224220efd51655eb3.
---
 clang/lib/Headers/CMakeLists.txt | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index e6ae4e19e81db9..97104ccd8db59c 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -437,14 +437,14 @@ foreach( f ${generated_files} )
 endforeach( f )
 
 function(add_header_target target_name file_list)
-  add_library(${target_name} INTERFACE ${file_list})
+  add_custom_target(${target_name} DEPENDS ${file_list})
   set_target_properties(${target_name} PROPERTIES
 FOLDER "Misc"
 RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
 endfunction()
 
 # The catch-all clang-resource-headers target
-add_library(clang-resource-headers INTERFACE ${out_files})
+add_custom_target("clang-resource-headers" ALL DEPENDS ${out_files})
 set_target_properties("clang-resource-headers" PROPERTIES
   FOLDER "Misc"
   RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
@@ -501,10 +501,6 @@ add_header_target("windows-resource-headers" 
${windows_only_files})
 add_header_target("utility-resource-headers" ${utility_files})
 
 get_clang_resource_dir(header_install_dir SUBDIR include)
-target_include_directories(clang-resource-headers INTERFACE
-  $
-  $)
-set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS clang-resource-headers)
 
 #
 # Install rules for the catch-all clang-resource-headers target

>From 216f7532bc9160634a338f1ff09c06b911f1ff53 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Thu, 18 Apr 2024 09:59:16 -0700
Subject: [PATCH 2/2] Revert "[lldb] Fix the standalone Xcode build after
 #88317"

This reverts commit a855eea7fe86ef09a87f6251b3b711b821ae32bf.
---
 lldb/cmake/modules/LLDBFramework.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/cmake/modules/LLDBFramework.cmake 
b/lldb/cmake/modules/LLDBFramework.cmake
index f915839f6b45a5..81fc596ef4244e 100644
--- a/lldb/cmake/modules/LLDBFramework.cmake
+++ b/lldb/cmake/modules/LLDBFramework.cmake
@@ -119,7 +119,7 @@ add_custom_command(TARGET liblldb POST_BUILD
 if(NOT APPLE_EMBEDDED)
   if (TARGET clang-resource-headers)
 add_dependencies(liblldb clang-resource-headers)
-set(clang_resource_headers_dir 
$)
+set(clang_resource_headers_dir 
$)
   else()
 set(clang_resource_headers_dir ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}/include)
 if(NOT EXISTS ${clang_resource_headers_dir})

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] NFC: Make clang resource headers an interface library (PR #88317)

2024-04-12 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde closed 
https://github.com/llvm/llvm-project/pull/88317
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] NFC: Make clang resource headers an interface library (PR #88317)

2024-04-10 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/88317

>From 753df93a4fc054328c0b7caacc1064c283ced8ec Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Thu, 14 Mar 2024 18:11:24 -0700
Subject: [PATCH] Make clang resource headers an interface library

Making the clang resource headers into an interface library means that
we can attach the header search paths to the library. Targets that
"link" against this library will automatically have the appropriate
paths added to their header search paths to find them.
---
 clang/lib/Headers/CMakeLists.txt | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 97104ccd8db59c..e6ae4e19e81db9 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -437,14 +437,14 @@ foreach( f ${generated_files} )
 endforeach( f )
 
 function(add_header_target target_name file_list)
-  add_custom_target(${target_name} DEPENDS ${file_list})
+  add_library(${target_name} INTERFACE ${file_list})
   set_target_properties(${target_name} PROPERTIES
 FOLDER "Misc"
 RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
 endfunction()
 
 # The catch-all clang-resource-headers target
-add_custom_target("clang-resource-headers" ALL DEPENDS ${out_files})
+add_library(clang-resource-headers INTERFACE ${out_files})
 set_target_properties("clang-resource-headers" PROPERTIES
   FOLDER "Misc"
   RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
@@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" 
${windows_only_files})
 add_header_target("utility-resource-headers" ${utility_files})
 
 get_clang_resource_dir(header_install_dir SUBDIR include)
+target_include_directories(clang-resource-headers INTERFACE
+  $
+  $)
+set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS clang-resource-headers)
 
 #
 # Install rules for the catch-all clang-resource-headers target

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] NFC: Make clang resource headers an interface library (PR #88317)

2024-04-10 Thread Evan Wilde via cfe-commits


@@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" 
${windows_only_files})
 add_header_target("utility-resource-headers" ${utility_files})
 
 get_clang_resource_dir(header_install_dir SUBDIR include)
+target_include_directories(clang-resource-headers INTERFACE
+  $

etcwilde wrote:

Good point. I think I was trying to see if I could remove one set of header 
copies, but didn't actually remove that bit. Let me point it at the 
intermediate directory in the build directory instead which should only contain 
the headers for the targets we've configured LLVM for.

https://github.com/llvm/llvm-project/pull/88317
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] NFC: Make clang resource headers an interface library (PR #88317)

2024-04-10 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde created 
https://github.com/llvm/llvm-project/pull/88317

Making the clang resource headers into an interface library instead of a custom 
target means that we can attach the header search paths to the library. Targets 
that "link" against this library will automatically have the appropriate paths 
added to their header search paths to find them. Then downstream projects that 
embed a copy of clang can query the generated `ClangTargets.cmake` file for the 
header location instead of attempting to compute them.

>From de73a407bdf589d98c1c5a250100318fa2dfbe45 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Thu, 14 Mar 2024 18:11:24 -0700
Subject: [PATCH] Make clang resource headers an interface library

Making the clang resource headers into an interface library means that
we can attach the header search paths to the library. Targets that
"link" against this library will automatically have the appropriate
paths added to their header search paths to find them.
---
 clang/lib/Headers/CMakeLists.txt | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 97104ccd8db59c..0367f611526f41 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -437,14 +437,14 @@ foreach( f ${generated_files} )
 endforeach( f )
 
 function(add_header_target target_name file_list)
-  add_custom_target(${target_name} DEPENDS ${file_list})
+  add_library(${target_name} INTERFACE ${file_list})
   set_target_properties(${target_name} PROPERTIES
 FOLDER "Misc"
 RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
 endfunction()
 
 # The catch-all clang-resource-headers target
-add_custom_target("clang-resource-headers" ALL DEPENDS ${out_files})
+add_library(clang-resource-headers INTERFACE ${out_files})
 set_target_properties("clang-resource-headers" PROPERTIES
   FOLDER "Misc"
   RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
@@ -501,6 +501,10 @@ add_header_target("windows-resource-headers" 
${windows_only_files})
 add_header_target("utility-resource-headers" ${utility_files})
 
 get_clang_resource_dir(header_install_dir SUBDIR include)
+target_include_directories(clang-resource-headers INTERFACE
+  $
+  $)
+set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS clang-resource-headers)
 
 #
 # Install rules for the catch-all clang-resource-headers target

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-19 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde closed 
https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-19 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/82084

>From 0d01d10b4f162694a0de205fc2cf9ffd1adf54e0 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 43 +++
 clang/test/Preprocessor/sysroot-prefix.c  | 25 +
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2a21a9d619dc0b..0df6a82ccd8933 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   &Opts](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() && "Unexpected empty search path flag!");
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3202,16 +3218,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3229,12 +3236,18 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(PrefixHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
-Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+Opts.AddPath(PrefixHeaderPath(A), frontend::Quoted, false, true);
+
+  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) {
+if (A->getOption().matches(OPT_iwithsysroot)) {
+  Opts.AddPath(A->getValue(), frontend::System, false,
+   /*IgnoreSysRoot=*/false);
+  continue;
+}
+Opts.AddPath(PrefixHeaderPath(A), frontend::System, false, true);
+  }
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..eff71f5e3d5a36 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,16 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_NO_SYSROOT %s
+// RUN: %clang_cc1 -v -iquote=/usr/include -isysroot /var/empty

[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-19 Thread Evan Wilde via cfe-commits


@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   &Opts](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() != 0 && "Unexpected empty search path flag!");

etcwilde wrote:

Heh, that's all the Swift I've been writing lately coming through.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/82084

>From 9e665d05743022350e06f4ea357ecfecde82efb8 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 43 +++
 clang/test/Preprocessor/sysroot-prefix.c  | 25 +
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2a21a9d619dc0b..650e05b2bf33a0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   &Opts](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() != 0 && "Unexpected empty search path flag!");
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3202,16 +3218,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3229,12 +3236,18 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(PrefixHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
-Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+Opts.AddPath(PrefixHeaderPath(A), frontend::Quoted, false, true);
+
+  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) {
+if (A->getOption().matches(OPT_iwithsysroot)) {
+  Opts.AddPath(A->getValue(), frontend::System, false,
+   /*IgnoreSysRoot=*/false);
+  continue;
+}
+Opts.AddPath(PrefixHeaderPath(A), frontend::System, false, true);
+  }
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..eff71f5e3d5a36 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,16 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_NO_SYSROOT %s
+// RUN: %clang_cc1 -v -iquote=/usr/include -isysroot /var/

[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

> I think that Prefix or Expand would both be better than Convert. We aren't 
> really converting this.

There, changed to `PrefixHeaderPath`.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

Maybe? The thing coming from `Args.filtered` should be populated though? Even 
if it isn't, we shouldn't be entering the `for`-loop though. Perhaps 
`Args.filtered` should result in iterator that emits a const reference? That 
seems like a bigger, unrelated change though.

Added an assert and a test case. The arg parser will error out earlier if 
nothing is passed to `-I`; `argument to '-I' is missing`. Is that sufficient?

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde edited 
https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits


@@ -3256,12 +3262,14 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(ConvertHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
+Opts.AddPath(ConvertHeaderPath(A), frontend::Quoted, false, true);
+  for (const auto *A : Args.filtered(OPT_iwithsysroot))
 Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+ /*IgnoreSysRoot=*/false);
+  for (const auto *A : Args.filtered(OPT_isystem))

etcwilde wrote:

Fixed

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-03-18 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde updated 
https://github.com/llvm/llvm-project/pull/82084

>From 4c147d0508df51ca713b182dd8b85130cafb1f6c Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 43 +++
 clang/test/Preprocessor/sysroot-prefix.c  | 25 +
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2a21a9d619dc0b..650e05b2bf33a0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto PrefixHeaderPath = [IsSysrootSpecified,
+   &Opts](const llvm::opt::Arg *A,
+  bool IsFramework = false) -> std::string {
+assert(A->getNumValues() != 0 && "Unexpected empty search path flag!");
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3202,16 +3218,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3229,12 +3236,18 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(PrefixHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
-Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+Opts.AddPath(PrefixHeaderPath(A), frontend::Quoted, false, true);
+
+  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) {
+if (A->getOption().matches(OPT_iwithsysroot)) {
+  Opts.AddPath(A->getValue(), frontend::System, false,
+   /*IgnoreSysRoot=*/false);
+  continue;
+}
+Opts.AddPath(PrefixHeaderPath(A), frontend::System, false, true);
+  }
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..5c84380e5c6a07 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,16 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_NO_SYSROOT %s
+// RUN: %clang_cc1 -v -iquote=/usr/include -isysroot /var/

[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Evan Wilde via cfe-commits


@@ -3229,16 +3244,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(ConvertHeaderPath(A, IsFramework), Group, IsFramework,

etcwilde wrote:

I had considered doing something like checking whether the first character is 
an `=` and if the sysroot option is set and passing `true` to `IgnoreSysRoot` 
when that's the case. It unfortunately does not match behavior. I don't know 
how useful it is, but `--sysroot /foo/bar -isystem=baz` will result in the 
searchpath `/foo/barbaz` in gcc. (that's actually a good testcase, I should add 
that).

Given that we still need to strip the leading `=` from the searchpath with 
`-isystem` though not with `-iwithsysroot`, and that we want to match the `-I=` 
behavior, I decided to stick with this to minimize the impact of the patch. I 
could try to hunt down all of the places where the `UserEntries` list is 
iterated and ensure that they're doing the appropriate sysroot prefixing for 
the corresponding flags.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

I just followed the whims of `git clang-format` here. ¯\\\_(ツ)\_/¯

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-16 Thread Evan Wilde via cfe-commits


@@ -3256,12 +3262,14 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(ConvertHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
+Opts.AddPath(ConvertHeaderPath(A), frontend::Quoted, false, true);
+  for (const auto *A : Args.filtered(OPT_iwithsysroot))
 Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+ /*IgnoreSysRoot=*/false);
+  for (const auto *A : Args.filtered(OPT_isystem))

etcwilde wrote:

Good catch, it was not.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-16 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,

etcwilde wrote:

I don't love this name. Perhaps `ExpandHeaderSysroot`?

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-16 Thread Evan Wilde via cfe-commits

https://github.com/etcwilde created 
https://github.com/llvm/llvm-project/pull/82084

Clang supported header searchpaths of the form `-I =/path`, relative to the 
sysroot if one is passed, but did not implement that behavior for `-iquote`, 
`-isystem`, or `-idirafter`.

This implements the `=` portion of the behavior implemented by GCC for these 
flags described in https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html.

>From 37bcd5380893cb489c012508613919fa05254a94 Mon Sep 17 00:00:00 2001
From: Evan Wilde 
Date: Fri, 16 Feb 2024 16:39:10 -0800
Subject: [PATCH] Support sysroot-relative header search paths

Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 36 ++-
 clang/test/Preprocessor/sysroot-prefix.c  | 14 +
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index bcb31243056b7e..4b5667f6ae5a5d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
+  SmallString<32> Buffer;
+  llvm::sys::path::append(Buffer, Opts.Sysroot,
+  llvm::StringRef(A->getValue()).substr(1));
+  return std::string(Buffer);
+}
+return A->getValue();
+  };
+
   for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
 if (A->getOption().matches(OPT_index_header_map)) {
   // -index-header-map applies to the next -I or -F.
@@ -3229,16 +3244,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(ConvertHeaderPath(A, IsFramework), Group, IsFramework,
  /*IgnoreSysroot*/ true);
 IsIndexHeaderMap = false;
   }
@@ -3256,12 +3262,14 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   }
 
   for (const auto *A : Args.filtered(OPT_idirafter))
-Opts.AddPath(A->getValue(), frontend::After, false, true);
+Opts.AddPath(ConvertHeaderPath(A), frontend::After, false, true);
   for (const auto *A : Args.filtered(OPT_iquote))
-Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
-  for (const auto *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
+Opts.AddPath(ConvertHeaderPath(A), frontend::Quoted, false, true);
+  for (const auto *A : Args.filtered(OPT_iwithsysroot))
 Opts.AddPath(A->getValue(), frontend::System, false,
- !A->getOption().matches(OPT_iwithsysroot));
+ /*IgnoreSysRoot=*/false);
+  for (const auto *A : Args.filtered(OPT_isystem))
+Opts.AddPath(ConvertHeaderPath(A), frontend::System, false, true);
   for (const auto *A : Args.filtered(OPT_iframework))
 Opts.AddPath(A->getValue(), frontend::System, true, true);
   for (const auto *A : Args.filtered(OPT_iframeworkwithsysroot))
diff --git a/clang/test/Preprocessor/sysroot-prefix.c 
b/clang/test/Preprocessor/sysroot-prefix.c
index 08c72f53b44e9f..ce19790819b732 100644
--- a/clang/test/Preprocessor/sysroot-prefix.c
+++ b/clang/test/Preprocessor/sysroot-prefix.c
@@ -4,6 +4,12 @@
 // RUN: %clang_cc1 -v -isysroot /var/empty -I =null -E %s -o /dev/null 2>&1 | 
FileCheck -check-prefix CHECK-ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty -isysroot /var/empty/root -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SYSROOT_NULL %s
 // RUN: %clang_cc1 -v -isysroot /var/empty/root -isysroot /var/empty -I =null 
-E %s -o /dev/null 2>&1 | FileCheck -check-prefix 
CHECK-ISYSROOT_ISYSROOT_SWAPPED_SYSROOT_NULL %s
+// RUN: %clang_cc1 -v -isystem=/usr/include -isysroot /var/empty -E %s -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-ISYSROOT_ISYSTEM_SYSROOT %s
+// RUN: %clang_cc1 -v -isystem=/

[clang] e4ad1f9 - [NFC] Remove extra semicolons in clang/lib/APINotes/APINotesFormat.h

2023-07-21 Thread Evan Wilde via cfe-commits

Author: Evan Wilde
Date: 2023-07-21T16:19:53-07:00
New Revision: e4ad1f976d1209b8ff233e6aab924f92b7484c2d

URL: 
https://github.com/llvm/llvm-project/commit/e4ad1f976d1209b8ff233e6aab924f92b7484c2d
DIFF: 
https://github.com/llvm/llvm-project/commit/e4ad1f976d1209b8ff233e6aab924f92b7484c2d.diff

LOG: [NFC] Remove extra semicolons in clang/lib/APINotes/APINotesFormat.h

There are some trailing semicolons on namespaces in
clang/lib/APINotes/APINotesFormat.h. These result in warnings while
building and don't need to be there.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D105049

Added: 


Modified: 
clang/lib/APINotes/APINotesFormat.h

Removed: 




diff  --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index 6b76ecfc2567d9..a0a5efe8f9be17 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -220,7 +220,7 @@ using TagDataLayout =
   // below)
  llvm::BCBlob // map from name to tag information
  >;
-}; // namespace tag_block
+} // namespace tag_block
 
 namespace typedef_block {
 enum { TYPEDEF_DATA = 1 };
@@ -231,7 +231,7 @@ using TypedefDataLayout =
   // below)
  llvm::BCBlob // map from name to typedef information
  >;
-}; // namespace typedef_block
+} // namespace typedef_block
 
 namespace enum_constant_block {
 enum { ENUM_CONSTANT_DATA = 1 };



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d7b4594 - [NFC][clang] Fix format in UnsafeBufferUsage.cpp

2023-07-16 Thread Evan Wilde via cfe-commits

Author: Evan Wilde
Date: 2023-07-16T22:45:29-07:00
New Revision: d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8

URL: 
https://github.com/llvm/llvm-project/commit/d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8
DIFF: 
https://github.com/llvm/llvm-project/commit/d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8.diff

LOG: [NFC][clang] Fix format in UnsafeBufferUsage.cpp

There were two whitespaces on an otherwise empty that were causing the
bots to fail due to formatting issues. Deleting extra whitespace now.

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index c8c1452a8f5543..142c56beddafea 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1809,7 +1809,7 @@ createOverloadsForFixedParams(unsigned ParmIdx, StringRef 
NewTyText,
   // FIXME: need to make this conflict checking better:
   if (hasConflictingOverload(FD))
 return std::nullopt;
-  
+
   const SourceManager &SM = Ctx.getSourceManager();
   const LangOptions &LangOpts = Ctx.getLangOpts();
   // FIXME Respect indentation of the original code.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits