diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -429,7 +429,6 @@ Changed |= setOnlyReadsMemory(F, 1); return Changed; case LibFunc_feof: - case LibFunc_free: case LibFunc_fseek: case LibFunc_ftell: case LibFunc_fgetc: @@ -446,6 +445,10 @@ Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); return Changed; + case LibFunc_free: + // Free is nothrow but does capture the argument. + Changed |= setDoesNotThrow(F); + return Changed; case LibFunc_ferror: Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll --- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll +++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll @@ -451,7 +451,8 @@ ; CHECK: declare i64 @fread(i8* nocapture, i64, i64, %opaque* nocapture) [[G1]] declare i64 @fread(i8*, i64, i64, %opaque*) -; CHECK: declare void @free(i8* nocapture) [[G3:#[0-9]+]] +; Make sure there is *no* nocapture here. +; CHECK: declare void @free(i8*) [[G3:#[0-9]+]] declare void @free(i8*) ; CHECK: declare double @frexp(double, i32* nocapture) [[G1]]