1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/lib/CodeGen/AsmPrinter
Ties Stuij 43c46fbb66 [CodeGen] emit inline asm clobber list warnings for reserved (cont)
Summary:
This is a continuation of https://reviews.llvm.org/D49727
Below the original text, current changes in the comments:

Currently, in line with GCC, when specifying reserved registers like sp or pc on an inline asm() clobber list, we don't always preserve the original value across the statement. And in general, overwriting reserved registers can have surprising results.

For example:

  extern int bar(int[]);
  
  int foo(int i) {
    int a[i]; // VLA
    asm volatile(
        "mov r7, #1"
      :
      :
      : "r7"
    );
  
    return 1 + bar(a);
  }

Compiled for thumb, this gives:

  $ clang --target=arm-arm-none-eabi -march=armv7a -c test.c -o - -S -O1 -mthumb
  ...
  foo:
          .fnstart
  @ %bb.0:                                @ %entry
          .save   {r4, r5, r6, r7, lr}
          push    {r4, r5, r6, r7, lr}
          .setfp  r7, sp, #12
          add     r7, sp, #12
          .pad    #4
          sub     sp, #4
          movs    r1, #7
          add.w   r0, r1, r0, lsl #2
          bic     r0, r0, #7
          sub.w   r0, sp, r0
          mov     sp, r0
          @APP
          mov.w   r7, #1
          @NO_APP
          bl      bar
          adds    r0, #1
          sub.w   r4, r7, #12
          mov     sp, r4
          pop     {r4, r5, r6, r7, pc}
  ...

r7 is used as the frame pointer for thumb targets, and this function needs to restore the SP from the FP because of the variable-length stack allocation a. r7 is clobbered by the inline assembly (and r7 is included in the clobber list), but LLVM does not preserve the value of the frame pointer across the assembly block.

This type of behavior is similar to GCC's and has been discussed on the bugtracker: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807 . No consensus seemed to have been reached on the way forward. Clang behavior has briefly been discussed on the CFE mailing (starting here: http://lists.llvm.org/pipermail/cfe-dev/2018-July/058392.html). I've opted for following Eli Friedman's advice to print warnings when there are reserved registers on the clobber list so as not to diverge from GCC behavior for now.

The patch uses MachineRegisterInfo's target-specific knowledge of reserved registers, just before we convert the inline asm string in the AsmPrinter.

If we find a reserved register, we print a warning:

  repro.c:6:7: warning: inline asm clobber list contains reserved registers: R7 [-Winline-asm]
        "mov r7, #1"
        ^

Reviewers: efriedma, olista01, javed.absar

Reviewed By: efriedma

Subscribers: eraman, kristof.beyls, llvm-commits

Differential Revision: https://reviews.llvm.org/D51165

llvm-svn: 341062
2018-08-30 12:52:35 +00:00
..
AccelTable.cpp DebugInfo: Fix skipping CUs in DWARFv5 debug_names table 2018-08-24 20:31:05 +00:00
AddressPool.cpp [DWARF] Basic support for producing DWARFv5 .debug_addr section 2018-08-01 05:48:06 +00:00
AddressPool.h [DWARF] Basic support for producing DWARFv5 .debug_addr section 2018-08-01 05:48:06 +00:00
ARMException.cpp Use assembler expressions to lay out the EH LSDA. 2018-02-09 17:00:25 +00:00
AsmPrinter.cpp [MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll 2018-08-29 17:28:34 +00:00
AsmPrinterDwarf.cpp Style update. NFC. 2018-03-29 23:32:54 +00:00
AsmPrinterHandler.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
AsmPrinterInlineAsm.cpp [CodeGen] emit inline asm clobber list warnings for reserved (cont) 2018-08-30 12:52:35 +00:00
ByteStreamer.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
CMakeLists.txt [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
CodeViewDebug.cpp [CodeView] Omit forward references for unnamed structs and unions 2018-06-11 01:39:34 +00:00
CodeViewDebug.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DbgEntityHistoryCalculator.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DbgEntityHistoryCalculator.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DebugHandlerBase.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DebugHandlerBase.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DebugLocEntry.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
DebugLocStream.cpp
DebugLocStream.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
DIE.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
DIEHash.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
DIEHash.h Fix -Wdocumentation warning. NFCI. 2018-07-18 09:07:54 +00:00
DIEHashAttributes.def
DwarfCFIException.cpp Move TargetLoweringObjectFile from CodeGen to Target to fix layering 2018-03-23 23:58:19 +00:00
DwarfCompileUnit.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfCompileUnit.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfDebug.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfDebug.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfException.h Use assembler expressions to lay out the EH LSDA. 2018-02-09 17:00:25 +00:00
DwarfExpression.cpp [Local] replaceAllDbgUsesWith: Update debug values before RAUW 2018-07-06 17:32:39 +00:00
DwarfExpression.h Remove trailing space 2018-07-30 19:41:25 +00:00
DwarfFile.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfFile.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfStringPool.cpp [DebugInfo] Reduce debug_str_offsets section size 2018-08-07 09:54:52 +00:00
DwarfStringPool.h [DebugInfo] Reduce debug_str_offsets section size 2018-08-07 09:54:52 +00:00
DwarfUnit.cpp [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
DwarfUnit.h [DebugInfo] Generate DWARF debug information for labels. (Fix leak problems) 2018-08-17 15:22:04 +00:00
EHStreamer.cpp [CodeGen] Change std::sort to llvm::sort in response to r327219 2018-04-06 18:08:42 +00:00
EHStreamer.h [CodeGen] Fix inconsistent declaration parameter name 2018-07-16 18:51:40 +00:00
ErlangGCPrinter.cpp Style update. NFC. 2018-03-29 23:32:54 +00:00
LLVMBuild.txt
OcamlGCPrinter.cpp Style update. NFC. 2018-03-29 23:32:54 +00:00
WinCFGuard.cpp
WinCFGuard.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
WinException.cpp Move TargetLoweringObjectFile from CodeGen to Target to fix layering 2018-03-23 23:58:19 +00:00
WinException.h Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00