OSDN Git Service

[InferAttributes] Don't access parameters that don't exist.
authorMichael Kuperstein <mkuper@google.com>
Tue, 20 Sep 2016 23:10:31 +0000 (23:10 +0000)
committerMichael Kuperstein <mkuper@google.com>
Tue, 20 Sep 2016 23:10:31 +0000 (23:10 +0000)
Check for the correct number of parameters before querying their type.
This fixes PR30455.

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

lib/Analysis/TargetLibraryInfo.cpp
test/Transforms/InferFunctionAttrs/pr30455.ll [new file with mode: 0644]

index 2a47390..98f2321 100644 (file)
@@ -847,10 +847,10 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
   case LibFunc::stat64:
   case LibFunc::lstat64:
   case LibFunc::statvfs64:
-    return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() &&
+    return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
             FTy.getParamType(1)->isPointerTy());
   case LibFunc::dunder_isoc99_sscanf:
-    return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() &&
+    return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
             FTy.getParamType(1)->isPointerTy());
   case LibFunc::fopen64:
     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
diff --git a/test/Transforms/InferFunctionAttrs/pr30455.ll b/test/Transforms/InferFunctionAttrs/pr30455.ll
new file mode 100644 (file)
index 0000000..e12e58b
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -inferattrs -S | FileCheck %s
+%struct.statvfs64 = type { i32 }
+
+; Function Attrs: norecurse uwtable
+define i32 @foo() {
+entry:
+  %st = alloca %struct.statvfs64, align 4
+  %0 = bitcast %struct.statvfs64* %st to i8*
+  ret i32 0
+}
+
+; CHECK: declare i32 @statvfs64(%struct.statvfs64*){{$}}
+declare i32 @statvfs64(%struct.statvfs64*)