[clang] c11ff4b - Define __GCC_HAVE_DWARF2_CFI_ASM if applicable
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 9 10:52:31 PST 2021
Author: Fangrui Song
Date: 2021-03-09T10:52:26-08:00
New Revision: c11ff4bbada3b5127a1f010e0a97a1e6e46fb61a
URL: https://github.com/llvm/llvm-project/commit/c11ff4bbada3b5127a1f010e0a97a1e6e46fb61a
DIFF: https://github.com/llvm/llvm-project/commit/c11ff4bbada3b5127a1f010e0a97a1e6e46fb61a.diff
LOG: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable
In -fno-exceptions -fno-asynchronous-unwind-tables -g0 mode,
GCC does not emit `.cfi_*` directives.
```
% diff <(gcc -fno-asynchronous-unwind-tables -dM -E a.c) <(gcc -dM -E a.c)
130a131
> #define __GCC_HAVE_DWARF2_CFI_ASM 1
```
This macro is useful because code can decide whether inline asm should include `.cfi_*` directives.
`.cfi_*` directives without `.cfi_startproc` can cause assembler errors
(integrated assembler: `this directive must appear between .cfi_startproc and .cfi_endproc directives`).
Differential Revision: https://reviews.llvm.org/D97743
Added:
clang/test/Preprocessor/unwind-tables.c
Modified:
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 2606e9f1b185..bd0240870706 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4355,6 +4355,11 @@ bool CompilerInvocation::CreateFromArgsImpl(
Res.getCodeGenOpts().Argv0 = Argv0;
Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
+ if ((T.isOSBinFormatELF() || T.isOSBinFormatMachO()) &&
+ (Res.getLangOpts()->Exceptions || Res.getCodeGenOpts().UnwindTables ||
+ Res.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo))
+ Res.getPreprocessorOpts().addMacroDef("__GCC_HAVE_DWARF2_CFI_ASM=1");
+
Success &= FixupInvocation(Res, Diags, Args, DashX);
return Success;
diff --git a/clang/test/Preprocessor/unwind-tables.c b/clang/test/Preprocessor/unwind-tables.c
new file mode 100644
index 000000000000..2f769761b6c6
--- /dev/null
+++ b/clang/test/Preprocessor/unwind-tables.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -munwind-tables -triple x86_64-windows
+// RUN: %clang_cc1 %s -verify -triple x86_64-unknown-elf
+
+// RUN: %clang_cc1 %s -verify -munwind-tables -DCFI_ASM -triple x86_64-unknown-elf
+// RUN: %clang_cc1 %s -verify -munwind-tables -DCFI_ASM -triple aarch64-apple-darwin
+// RUN: %clang_cc1 %s -verify -debug-info-kind=line-tables-only -DCFI_ASM -triple x86_64-unknown-elf
+// RUN: %clang_cc1 %s -verify -fexceptions -DCFI_ASM -triple x86_64-unknown-elf
+
+// expected-no-diagnostics
+
+#ifdef CFI_ASM
+ #if __GCC_HAVE_DWARF2_CFI_ASM != 1
+ #error "__GCC_HAVE_DWARF2_CFI_ASM not defined"
+ #endif
+#else
+ #ifdef __GCC_HAVE_DWARF2_CFI_ASM
+ #error "__GCC_HAVE_DWARF2_CFI_ASM defined"
+ #endif
+#endif
More information about the cfe-commits
mailing list