[llvm] e62912b - [LLParser] Delete temp CallInst when error occurs

Qiu Chaofan via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 20:48:24 PDT 2020


Author: Qiu Chaofan
Date: 2020-06-16T11:41:25+08:00
New Revision: e62912b19063937a55e10064266888c0534b2211

URL: https://github.com/llvm/llvm-project/commit/e62912b19063937a55e10064266888c0534b2211
DIFF: https://github.com/llvm/llvm-project/commit/e62912b19063937a55e10064266888c0534b2211.diff

LOG: [LLParser] Delete temp CallInst when error occurs

Only functions with floating-point return type accepts fast-math flags.
When adding such flags to function returning integer, we'll see a crash,
because there's still an undeleted value referencing the argument. This
patch manually removes the temporary instruction when error occurs.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D78355

Added: 
    llvm/test/CodeGen/Generic/fast-math-flags.ll

Modified: 
    llvm/lib/AsmParser/LLParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 117ec2ccc9ee..4e75ca4ae535 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -6964,9 +6964,11 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
   CI->setTailCallKind(TCK);
   CI->setCallingConv(CC);
   if (FMF.any()) {
-    if (!isa<FPMathOperator>(CI))
+    if (!isa<FPMathOperator>(CI)) {
+      CI->deleteValue();
       return Error(CallLoc, "fast-math-flags specified for call without "
                    "floating-point scalar or vector return type");
+    }
     CI->setFastMathFlags(FMF);
   }
   CI->setAttributes(PAL);

diff  --git a/llvm/test/CodeGen/Generic/fast-math-flags.ll b/llvm/test/CodeGen/Generic/fast-math-flags.ll
new file mode 100644
index 000000000000..73460aa5d008
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/fast-math-flags.ll
@@ -0,0 +1,10 @@
+; RUN: not llc < %s 2>&1 | FileCheck %s
+
+; CHECK: error: fast-math-flags specified for call without floating-point scalar or vector return type
+define i64 @test_lrintf(float %f) {
+entry:
+  %0 = tail call fast i64 @llvm.lrint.i64.f32(float %f)
+  ret i64 %0
+}
+
+declare i64 @llvm.lrint.i64.f32(float)


        


More information about the llvm-commits mailing list