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

Evan Wilde via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 17 09:38:09 PST 2024


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


More information about the cfe-commits mailing list