[llvm] r282038 - [InferAttributes] Don't access parameters that don't exist.

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 16:10:31 PDT 2016


Author: mkuper
Date: Tue Sep 20 18:10:31 2016
New Revision: 282038

URL: http://llvm.org/viewvc/llvm-project?rev=282038&view=rev
Log:
[InferAttributes] Don't access parameters that don't exist.

Check for the correct number of parameters before querying their type.
This fixes PR30455.


Added:
    llvm/trunk/test/Transforms/InferFunctionAttrs/pr30455.ll
Modified:
    llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp

Modified: llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=282038&r1=282037&r2=282038&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp Tue Sep 20 18:10:31 2016
@@ -847,10 +847,10 @@ bool TargetLibraryInfoImpl::isValidProto
   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() &&

Added: llvm/trunk/test/Transforms/InferFunctionAttrs/pr30455.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferFunctionAttrs/pr30455.ll?rev=282038&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InferFunctionAttrs/pr30455.ll (added)
+++ llvm/trunk/test/Transforms/InferFunctionAttrs/pr30455.ll Tue Sep 20 18:10:31 2016
@@ -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*)




More information about the llvm-commits mailing list