Why does the mayWriteToMemory() of function call always get true?

I write a function which returns an integer on C code like below.

define dso_local i32 @division(i32 %a, i32 %b) #0 {
  %div = sdiv i32 %a, %b
  ret i32 %div

define dso_local i32 @main() #0 {
  %call = call i32 @division(i32 9999, i32 30000)
  ret i32 0

And the instruction %call = call i32 @division(i32 9999, i32 30000) of mayWriteToMemory() will return True.
I don’t know why this function will write to memory. I know that function call will do some changes on program pointer and set value on some registers. But I think those set or changes are relative with register instead of memory.

So, why a function call are assumed to write memory? Even a write a function which returns void will be assumed writing to memory.

Those calls check for function attributes (like readonly) and give you the safe answer if there aren’t any.

It’s another pass’s job to deeply inspect functions and work out which attributes should apply (for example you can run opt --attributor on your example and LLVM will infer readnone which is even stronger).

Thanks for your reply.

now I using the command opt -passes=function-attrs then the attribute of the function will be readnone.