]> granicus.if.org Git - llvm/commitdiff
[TLI] isdigit / isascii / toascii param type should match return type (PR30484)
authorSanjay Patel <spatel@rotateright.com>
Fri, 23 Sep 2016 18:44:09 +0000 (18:44 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 23 Sep 2016 18:44:09 +0000 (18:44 +0000)
We crash in LibCallSimplifier if we don't check the validity of the function signature properly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282278 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/TargetLibraryInfo.cpp
test/Transforms/InstCombine/simplify-libcalls.ll

index 98f23214c65ac7dfb19c0f004d9e6b47910f1f43..988ccaa0a4eb287a9ad54ccc55bea3145db7f2e5 100644 (file)
@@ -957,11 +957,14 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
   case LibFunc::ffs:
   case LibFunc::ffsl:
   case LibFunc::ffsll:
+    return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
+            FTy.getParamType(0)->isIntegerTy());
+
   case LibFunc::isdigit:
   case LibFunc::isascii:
   case LibFunc::toascii:
     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
-            FTy.getParamType(0)->isIntegerTy());
+            FTy.getReturnType() == FTy.getParamType(0));
 
   case LibFunc::fls:
   case LibFunc::flsl:
index 7cc67106137919a254082466949e6659fa16f720..bae2822164f11e74c04626a2127e36c62b8b9684 100644 (file)
@@ -141,5 +141,40 @@ define void @test9(i8* %x) {
   ret void
 }
 
+; PR30484 - https://llvm.org/bugs/show_bug.cgi?id=30484
+; These aren't the library functions you're looking for...
+
+declare i32 @isdigit(i8)
+declare i32 @isascii(i8)
+declare i32 @toascii(i8)
+
+define i32 @fake_isdigit(i8 %x) {
+; CHECK-LABEL: @fake_isdigit(
+; CHECK-NEXT:    [[Y:%.*]] = call i32 @isdigit(i8 %x)
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  %y = call i32 @isdigit(i8 %x)
+  ret i32 %y
+}
+
+define i32 @fake_isascii(i8 %x) {
+; CHECK-LABEL: @fake_isascii(
+; CHECK-NEXT:    [[Y:%.*]] = call i32 @isascii(i8 %x)
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  %y = call i32 @isascii(i8 %x)
+  ret i32 %y
+}
+
+define i32 @fake_toascii(i8 %x) {
+; CHECK-LABEL: @fake_toascii(
+; CHECK-NEXT:    [[Y:%.*]] = call i32 @toascii(i8 %x)
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  %y = call i32 @toascii(i8 %x)
+  ret i32 %y
+}
+
+
 attributes #0 = { nobuiltin }
 attributes #1 = { builtin }