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: unassignedclangb...@nondot.org
          Reporter: chaos2...@gmail.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to