aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenModule.cpp
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-09-29 10:27:34 -0700
committerGitHub <noreply@github.com>2025-09-29 10:27:34 -0700
commit782ab835dcc8f6b55c6053cc38dd299830e4ffed (patch)
tree9b0fc40e80b8e4731bae525c44125203ccc4229b /clang/lib/CIR/CodeGen/CIRGenModule.cpp
parent0251fd9a72c550bcab4906d9223c96aeb593ce57 (diff)
downloadllvm-782ab835dcc8f6b55c6053cc38dd299830e4ffed.zip
llvm-782ab835dcc8f6b55c6053cc38dd299830e4ffed.tar.gz
llvm-782ab835dcc8f6b55c6053cc38dd299830e4ffed.tar.bz2
[CIR] Set the module name to the input filename (#160934)
This sets the MLIR module name to the main filename (according to the SourceManager), if one is available. The module name gets used when creating global init functions, so we will need it to be set.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index eef23a0..c977ff9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -119,6 +119,19 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
cir::OptInfoAttr::get(&mlirContext,
cgo.OptimizationLevel,
cgo.OptimizeSize));
+ // Set the module name to be the name of the main file. TranslationUnitDecl
+ // often contains invalid source locations and isn't a reliable source for the
+ // module location.
+ FileID mainFileId = astContext.getSourceManager().getMainFileID();
+ const FileEntry &mainFile =
+ *astContext.getSourceManager().getFileEntryForID(mainFileId);
+ StringRef path = mainFile.tryGetRealPathName();
+ if (!path.empty()) {
+ theModule.setSymName(path);
+ theModule->setLoc(mlir::FileLineColLoc::get(&mlirContext, path,
+ /*line=*/0,
+ /*column=*/0));
+ }
}
CIRGenModule::~CIRGenModule() = default;