@@ -1584,18 +1584,22 @@ static const llvm::sys::fs::UniqueID BUILTIN_ASSERT_H_UID(2, 1);
15841584static const llvm::sys::fs::UniqueID BUILTIN_INCLUDE_DIR_UID (2 , 2 );
15851585
15861586// A VFS file that serves static string content (used for builtin headers).
1587+ // The UID is passed explicitly so each builtin file has a stable, distinct ID.
15871588class BuiltinVFSFile : public llvm ::vfs::File {
15881589 llvm::StringRef name;
15891590 llvm::StringRef content;
1591+ llvm::sys::fs::UniqueID uid;
15901592
15911593public:
1592- BuiltinVFSFile (llvm::StringRef n, llvm::StringRef c) : name(n), content(c) {}
1594+ BuiltinVFSFile (llvm::StringRef n, llvm::StringRef c,
1595+ llvm::sys::fs::UniqueID u)
1596+ : name(n), content(c), uid(u) {}
15931597
15941598 llvm::ErrorOr<llvm::vfs::Status> status () override {
15951599 llvm::sys::TimePoint<> time;
1596- return llvm::vfs::Status (
1597- name, BUILTIN_ASSERT_H_UID , time, 0 , 0 , content. size () ,
1598- llvm::sys::fs::file_type::regular_file, llvm::sys::fs::perms::all_all);
1600+ return llvm::vfs::Status (name, uid, time, 0 , 0 , content. size (),
1601+ llvm::sys::fs::file_type::regular_file ,
1602+ llvm::sys::fs::perms::all_all);
15991603 }
16001604
16011605 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
@@ -1700,7 +1704,8 @@ class CtxVFS : public llvm::vfs::FileSystem {
17001704 return std::make_unique<BuiltinVFSFile>(
17011705 llvm::StringRef (BUILTIN_ASSERT_H_PATH ),
17021706 llvm::StringRef (BUILTIN_ASSERT_H_CONTENT ,
1703- sizeof (BUILTIN_ASSERT_H_CONTENT ) - 1 ));
1707+ sizeof (BUILTIN_ASSERT_H_CONTENT ) - 1 ),
1708+ BUILTIN_ASSERT_H_UID );
17041709 }
17051710 auto res = ctx.read_vfs_file (toStr (Path.str ()));
17061711 if (!res.is_ok ()) {
@@ -1785,9 +1790,12 @@ static void parse_file(RefMut<Ctx> ctx) {
17851790 incPath.c_str (), ArgumentInsertPosition::BEGIN ));
17861791 }
17871792
1788- // Add the builtin include directory last so it ends up first in the
1789- // command line (highest priority). This ensures our wrapper assert.h
1790- // is found before any system assert.h.
1793+ // Append the builtin include directory adjuster last. Because each adjuster
1794+ // uses ArgumentInsertPosition::BEGIN, later-appended adjusters insert their
1795+ // flags before earlier ones. The last adjuster therefore places its flags
1796+ // first in the final command line, giving the builtin directory the highest
1797+ // include-path priority. This ensures our wrapper assert.h is found before
1798+ // any user or system assert.h.
17911799 Tool.appendArgumentsAdjuster (getInsertArgumentAdjuster (
17921800 {" -I" , BUILTIN_INCLUDE_DIR }, ArgumentInsertPosition::BEGIN ));
17931801
0 commit comments