[llvm] r332531 - [InstCombine] Fix the signature of fgets_unlocked.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Wed May 16 14:45:40 PDT 2018
Author: d0k
Date: Wed May 16 14:45:39 2018
New Revision: 332531
URL: http://llvm.org/viewvc/llvm-project?rev=332531&view=rev
Log:
[InstCombine] Fix the signature of fgets_unlocked.
It returns a pointer, not an int. This miscompiles all code that uses
the return value of fgets.
Modified:
llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll
Modified: llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp?rev=332531&r1=332530&r2=332531&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp Wed May 16 14:45:39 2018
@@ -1166,8 +1166,8 @@ Value *llvm::emitFGetSUnlocked(Value *St
Module *M = B.GetInsertBlock()->getModule();
Constant *F =
- M->getOrInsertFunction("fgets_unlocked", B.getInt32Ty(), B.getInt8PtrTy(),
- B.getInt32Ty(), File->getType());
+ M->getOrInsertFunction("fgets_unlocked", B.getInt8PtrTy(),
+ B.getInt8PtrTy(), B.getInt32Ty(), File->getType());
inferLibFuncAttributes(*M->getFunction("fgets_unlocked"), *TLI);
CallInst *CI =
B.CreateCall(F, {castToCStr(Str, B), Size, File}, "fgets_unlocked");
Modified: llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll?rev=332531&r1=332530&r2=332531&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll Wed May 16 14:45:39 2018
@@ -100,7 +100,7 @@ define internal void @fgets_test() {
; CHECK-NEXT: [[BUF:%.*]] = alloca [10 x i8], align 1
; CHECK-NEXT: [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
; CHECK-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[BUF]], i64 0, i64 0
-; CHECK-NEXT: [[FGETS_UNLOCKED:%.*]] = call i32 @fgets_unlocked(i8* nonnull [[ARRAYDECAY]], i32 10, %struct._IO_FILE* [[CALL]])
+; CHECK-NEXT: [[FGETS_UNLOCKED:%.*]] = call i8* @fgets_unlocked(i8* nonnull [[ARRAYDECAY]], i32 10, %struct._IO_FILE* [[CALL]])
; CHECK-NEXT: ret void
;
%buf = alloca [10 x i8], align 1
More information about the llvm-commits
mailing list