[llvm-bugs] [Bug 42984] New: RISCV interrupt attribute doesn't preserve caller-saved registers when calling functions

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 13 08:28:36 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42984

            Bug ID: 42984
           Summary: RISCV interrupt attribute doesn't preserve
                    caller-saved registers when calling functions
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chaos2007 at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Created attachment 22373
  --> https://bugs.llvm.org/attachment.cgi?id=22373&action=edit
Sample test case of expected behavior

There seem to be 2 cases of the interrupt attribute being tested.
1.  A minimal interrupt where only the registers being used are preserved.
2.  An interrupt that preserves all registers since it is making a function
call.
However, there is also the case of:
3.  An interrupt that contains some logic, as well as making function calls. 
It needs to preserve caller-saved registers before making function calls.

I have attached a sample test case for what I expect would happen.

Below I have included a sample c file that illustrates the behavior:
extern int foo();
extern void otherfoo();

extern int c;

__attribute__((interrupt)) void foo_with_call_interrupt(void) {
        int x = foo();
        otherfoo();
        c = x;
}

A quick explanation of the C file.
1. I make a call to a function that returns an integer, this will now be in reg
a0.
2. I then make a call to another function, this function could have trashed reg
a0.
3. I try and use the integer returned from the first function.  Reg a0 was
never preserved, so we are running off of undefined behavior.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190813/1d51844b/attachment.html>


More information about the llvm-bugs mailing list