[clang] [clang] use absolute path for builtin headers during module compilation (PR #68023)
Richard Howell via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 2 12:24:26 PDT 2023
https://github.com/rmaz created https://github.com/llvm/llvm-project/pull/68023
When including builtin headers as part of a system module, ensure we use absolute paths to those headers. Otherwise the module will fail to compile when specifying relative resource directories.
>From 6803c872fad2533673884f059912c0aeb645eadc Mon Sep 17 00:00:00 2001
From: Richard Howell <rhow at fb.com>
Date: Mon, 2 Oct 2023 11:10:52 -0700
Subject: [PATCH] [clang] use absolute path for builtin headers during module
compilation
When including builtin headers as part of a system module, ensure
we use absolute paths to those headers. Otherwise the module will
fail to compile when specifying relative resource directories.
---
clang/lib/Lex/ModuleMap.cpp | 4 ++++
.../test/Modules/Inputs/builtin-headers/module.modulemap | 3 +++
clang/test/Modules/relative-resource-dir.m | 8 ++++++++
3 files changed, 15 insertions(+)
create mode 100644 clang/test/Modules/Inputs/builtin-headers/module.modulemap
create mode 100644 clang/test/Modules/relative-resource-dir.m
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index e8437572ebf4bf6..75dd76a63063274 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -348,6 +348,10 @@ bool ModuleMap::resolveAsBuiltinHeader(
if (!File)
return false;
+ // Ensure the path to the module directory is absolute, otherwise
+ // builtin headers will fail to resolve when using relative resource
+ // directory paths without a -I.
+ llvm::sys::fs::make_absolute(Path);
auto Role = headerKindToRole(Header.Kind);
Module::Header H = {Header.FileName, std::string(Path.str()), *File};
addHeader(Mod, H, Role);
diff --git a/clang/test/Modules/Inputs/builtin-headers/module.modulemap b/clang/test/Modules/Inputs/builtin-headers/module.modulemap
new file mode 100644
index 000000000000000..78a5b730dc6a925
--- /dev/null
+++ b/clang/test/Modules/Inputs/builtin-headers/module.modulemap
@@ -0,0 +1,3 @@
+module ModuleWithBuiltinHeader [system] {
+ header "float.h"
+}
\ No newline at end of file
diff --git a/clang/test/Modules/relative-resource-dir.m b/clang/test/Modules/relative-resource-dir.m
new file mode 100644
index 000000000000000..1d38fe922e71849
--- /dev/null
+++ b/clang/test/Modules/relative-resource-dir.m
@@ -0,0 +1,8 @@
+// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir` && \
+// RUN: mkdir -p %t && rm -rf %t/resource-dir && \
+// RUN: cp -R $EXPECTED_RESOURCE_DIR %t/resource-dir
+// RUN: cd %t && %clang -cc1 -x objective-c -fmodules -fmodule-format=obj \
+// RUN: -fimplicit-module-maps -fmodules-cache-path=%t.mcp \
+// RUN: -fbuiltin-headers-in-system-modules -resource-dir resource-dir \
+// RUN: -emit-module %S/Inputs/builtin-headers/module.modulemap \
+// RUN: -fmodule-name=ModuleWithBuiltinHeader -o %t.pcm
More information about the cfe-commits
mailing list