Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/lang-c-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.c.cir
// RUN: FileCheck --check-prefix=CIR-C --input-file=%t.c.cir %s

// CIR-CPP: module attributes {{{.*}}cir.lang = #cir.lang<cxx>{{.*}}}
// CIR-C: module attributes {{{.*}}cir.lang = #cir.lang<c>{{.*}}}
// CIR-CPP: module{{.*}} attributes {{{.*}}cir.lang = #cir.lang<cxx>{{.*}}}
// CIR-C: module{{.*}} attributes {{{.*}}cir.lang = #cir.lang<c>{{.*}}}

int main() {
return 0;
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CIR/CodeGen/module-filename.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s

// Normally, we try to avoid checking the filename of a test, but that's the
// entire point of this test, so we use a wildcard for the path but check the
// filename.
// CIR: module @"{{.*}}module-filename.cpp"

int main() {
return 0;
}
12 changes: 6 additions & 6 deletions clang/test/CIR/CodeGen/opt-info-attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

void f() {}

// CHECK-O0: module attributes
// CHECK-O0: module{{.*}} attributes
// CHECK-O0-NOT: cir.opt_info
// CHECK-O1: module attributes {{.+}}cir.opt_info = #cir.opt_info<level = 1, size = 0>{{.+}}
// CHECK-O2: module attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 0>{{.+}}
// CHECK-O3: module attributes {{.+}}cir.opt_info = #cir.opt_info<level = 3, size = 0>{{.+}}
// CHECK-Os: module attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 1>{{.+}}
// CHECK-Oz: module attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 2>{{.+}}
// CHECK-O1: module{{.*}} attributes {{.+}}cir.opt_info = #cir.opt_info<level = 1, size = 0>{{.+}}
// CHECK-O2: module{{.*}} attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 0>{{.+}}
// CHECK-O3: module{{.*}} attributes {{.+}}cir.opt_info = #cir.opt_info<level = 3, size = 0>{{.+}}
// CHECK-Os: module{{.*}} attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 1>{{.+}}
// CHECK-Oz: module{{.*}} attributes {{.+}}cir.opt_info = #cir.opt_info<level = 2, size = 2>{{.+}}