[flang-commits] [flang] f97731c - [Flang][Unit Test] Move the declaration of kindMap to the class
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Mon Dec 13 08:14:25 PST 2021
Author: Kiran Chandramohan
Date: 2021-12-13T16:12:01Z
New Revision: f97731c76501788c61012156adfae138f4013500
URL: https://github.com/llvm/llvm-project/commit/f97731c76501788c61012156adfae138f4013500
DIFF: https://github.com/llvm/llvm-project/commit/f97731c76501788c61012156adfae138f4013500.diff
LOG: [Flang][Unit Test] Move the declaration of kindMap to the class
kindMap variable is declared in the Setup function but passed as
a reference to the firBuilder class. The firBuilder is declared in
the class and hence its lifetime exceeds that of kindMap. This can
lead to undefined behaviour. Move the kindMap variable into the class
to avoid this.
This is part of the upstreaming effort from the fir-dev branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D115631
Added:
Modified:
flang/unittests/Optimizer/Builder/CharacterTest.cpp
flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
Removed:
################################################################################
diff --git a/flang/unittests/Optimizer/Builder/CharacterTest.cpp b/flang/unittests/Optimizer/Builder/CharacterTest.cpp
index 7cf15b0365f7..563ee275bac1 100644
--- a/flang/unittests/Optimizer/Builder/CharacterTest.cpp
+++ b/flang/unittests/Optimizer/Builder/CharacterTest.cpp
@@ -16,7 +16,7 @@
struct CharacterTest : public testing::Test {
public:
void SetUp() override {
- fir::KindMapping kindMap(&context,
+ kindMap = std::make_unique<fir::KindMapping>(&context,
"i10:80,l3:24,a1:8,r54:Double,c20:X86_FP80,r11:PPC_FP128,"
"r12:FP128,r13:X86_FP80,r14:Double,r15:Float,r16:Half,r23:BFloat");
mlir::OpBuilder builder(&context);
@@ -32,12 +32,13 @@ struct CharacterTest : public testing::Test {
builder.setInsertionPointToStart(entryBlock);
fir::support::loadDialects(context);
- firBuilder = std::make_unique<fir::FirOpBuilder>(mod, kindMap);
+ firBuilder = std::make_unique<fir::FirOpBuilder>(mod, *kindMap);
}
fir::FirOpBuilder &getBuilder() { return *firBuilder; }
mlir::MLIRContext context;
+ std::unique_ptr<fir::KindMapping> kindMap;
std::unique_ptr<fir::FirOpBuilder> firBuilder;
};
diff --git a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
index 8cc2446055dd..348438238a7a 100644
--- a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
+++ b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
@@ -15,9 +15,9 @@
struct DoLoopHelperTest : public testing::Test {
public:
void SetUp() {
- fir::KindMapping kindMap(&context);
+ kindMap = std::make_unique<fir::KindMapping>(&context);
mlir::OpBuilder builder(&context);
- firBuilder = new fir::FirOpBuilder(builder, kindMap);
+ firBuilder = new fir::FirOpBuilder(builder, *kindMap);
fir::support::loadDialects(context);
}
void TearDown() { delete firBuilder; }
@@ -25,6 +25,7 @@ struct DoLoopHelperTest : public testing::Test {
fir::FirOpBuilder &getBuilder() { return *firBuilder; }
mlir::MLIRContext context;
+ std::unique_ptr<fir::KindMapping> kindMap;
fir::FirOpBuilder *firBuilder;
};
More information about the flang-commits
mailing list