[llvm] [MIR] Replace bespoke DIExpression parser (PR #96827)
Scott Linder via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 13:50:24 PDT 2024
================
@@ -411,4 +412,49 @@ TEST(AsmParserTest, InvalidDataLayoutStringCallback) {
EXPECT_EQ(Mod2->getDataLayout(), FixedDL);
}
+TEST(AsmParserTest, DIExpressionAtBeginningWithSlotMappingParsing) {
+ LLVMContext Ctx;
+ SMDiagnostic Error;
+ StringRef Source =
+ "%st = type { i32, i32 }\n"
+ "@v = common global [50 x %st] zeroinitializer, align 16\n"
+ "%0 = type { i32, i32, i32, i32 }\n"
+ "@g = common global [50 x %0] zeroinitializer, align 16\n"
+ "define void @marker4(i64 %d) {\n"
+ "entry:\n"
+ " %conv = trunc i64 %d to i32\n"
+ " store i32 %conv, ptr getelementptr inbounds "
+ " ([50 x %st], ptr @v, i64 0, i64 0, i32 0), align 16\n"
+ " store i32 %conv, ptr getelementptr inbounds "
+ " ([50 x %0], ptr @g, i64 0, i64 0, i32 0), align 16\n"
+ " ret void\n"
+ "}";
+ SlotMapping Mapping;
+ auto Mod = parseAssemblyString(Source, Error, Ctx, &Mapping);
+ ASSERT_TRUE(Mod != nullptr);
+ auto &M = *Mod;
+ unsigned Read;
+
+ DIExpression *Expr;
+
+ Expr = parseDIExpressionAtBeginning("i32", Read, Error, M, &Mapping);
+ ASSERT_FALSE(Expr);
+
+ Expr = parseDIExpressionAtBeginning("!DIExpression()", Read, Error, M, &Mapping);
+ ASSERT_TRUE(Expr);
+ ASSERT_EQ(Expr->getNumElements(), 0);
+
+ Expr = parseDIExpressionAtBeginning("!DIExpression(0)", Read, Error, M, &Mapping);
+ ASSERT_TRUE(Expr);
+ ASSERT_EQ(Expr->getNumElements(), 1);
+
+ Expr = parseDIExpressionAtBeginning("!DIExpression(DW_OP_LLVM_fragment, 0, 1)", Read, Error, M, &Mapping);
+ ASSERT_TRUE(Expr);
+ ASSERT_EQ(Expr->getNumElements(), 3);
+
+ Expr = parseDIExpressionAtBeginning("(DW_OP_LLVM_fragment, 0, 1)", Read, Error, M, &Mapping);
+ ASSERT_TRUE(Expr);
+ ASSERT_EQ(Expr->getNumElements(), 3);
----------------
slinder1 wrote:
So this and the change of an `assert` in the parser to an `if` are to bridge the gap between the respective lexers for the MIParser (which consumes the `!DIExpression` token already by the time it would call `parseDIExpressionAtBeginning`) and LLParser (which does not consume the `!DIExpression` token by the time it would call `parseDIExpression`).
The alternative is to make both agree, so e.g. MIParser could just `peek` at the token or LLParser could `lex` it. I don't have a strong opinion on which approach is best.
https://github.com/llvm/llvm-project/pull/96827
More information about the llvm-commits
mailing list