llvm.org GIT mirror llvm / e0b4696
[FunctionAttrs] Remove readonly and writeonly assertion There are scenarios where mutually recursive functions may cause the SCC to contain both read only and write only functions. This removes an assertion when adding read attributes which caused a crash with a the provided test case, and instead just doesn't add the attributes. Patch by Luke Lau <luke.lau@intel.com> Differential Revision: https://reviews.llvm.org/D60761 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366090 91177308-0d34-0410-b5e6-96231b3b80d8 Johannes Doerfert a month ago
2 changed file(s) with 25 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
260260 }
261261 }
262262
263 // If the SCC contains both functions that read and functions that write, then
264 // we cannot add readonly attributes.
265 if (ReadsMemory && WritesMemory)
266 return false;
267
263268 // Success! Functions in this SCC do not access memory, or only read memory.
264269 // Give them the appropriate attribute.
265270 bool MadeChange = false;
266271
267 assert(!(ReadsMemory && WritesMemory) &&
268 "Function marked read-only and write-only");
269272 for (Function *F : SCCNodes) {
270273 if (F->doesNotAccessMemory())
271274 // Already perfect!
0 ; RUN: opt -S -functionattrs < %s | FileCheck %s
1 ; RUN: opt -S -passes=function-attrs < %s | FileCheck %s
2
3 @i = global i32 0
4
5 define void @foo() {
6 ; CHECK-LABEL: define void @foo() #0 {
7 store i32 1, i32* @i
8 call void @bar()
9 ret void
10 }
11
12 define void @bar() {
13 ; CHECK-LABEL: define void @bar() #0 {
14 %i = load i32, i32* @i
15 call void @foo()
16 ret void
17 }
18
19 ; CHECK: attributes #0 = { nofree nounwind }