[PATCH] D66439: [LibFunc] "free" captures the pointer operand
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 14:08:31 PDT 2019
jdoerfert created this revision.
jdoerfert added reviewers: sanjoy, arsenm, hfinkel.
Herald added subscribers: bollu, hiraditya, wdng.
Herald added a project: LLVM.
jdoerfert added reviewers: reames, fhahn.
We used to mark the free operand as "nocapture", though, arguably, there
is no reason "free" could not put the pointer value in a "free-table",
thereby effectively "capturing" it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66439
Files:
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Index: llvm/test/Transforms/InferFunctionAttrs/annotate.ll
===================================================================
--- llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ 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]]
Index: llvm/lib/Transforms/Utils/BuildLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66439.215980.patch
Type: text/x-patch
Size: 1393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/7bb36701/attachment.bin>
More information about the llvm-commits
mailing list