From 8ac15bf4dcec8f5569b308f0d0ac70a5f154af85 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 16 May 2018 21:45:39 +0000 Subject: [PATCH] [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. llvm-svn: 332531 --- llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 4 ++-- llvm/test/Transforms/InstCombine/unlocked-stdio.ll | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index bf912b0..5f5c415 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -1166,8 +1166,8 @@ Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File, 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"); diff --git a/llvm/test/Transforms/InstCombine/unlocked-stdio.ll b/llvm/test/Transforms/InstCombine/unlocked-stdio.ll index fa5a9fa..77eb918 100644 --- a/llvm/test/Transforms/InstCombine/unlocked-stdio.ll +++ b/llvm/test/Transforms/InstCombine/unlocked-stdio.ll @@ -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 -- 2.7.4