[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

There are some side effects: because -D is passed as command line options, it 
has `` in its filename, so `isWrittenInBuiltinFile` will not 
match it (`isWrittenInBuiltinFile` can match other built-in macros)...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D97743#2614899 , @MaskRay wrote:

> Move to driver

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9d117e7b2a39: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable 
(authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Preprocessor/unwind-tables.c


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ clang/test/Preprocessor/unwind-tables.c
@@ -0,0 +1,10 @@
+// RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s 
--check-prefix=NO
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | 
FileCheck %s --check-prefix=NO
+
+// RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
+// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | 
FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables 
-fexceptions | FileCheck %s
+
+// NO-NOT: #define __GCC_HAVE_DWARF2_CFI_ASM
+// CHECK: #define __GCC_HAVE_DWARF2_CFI_ASM 1
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -404,7 +404,7 @@
 /// master flag, -fexceptions and also language specific flags to 
enable/disable
 /// C++ and Objective-C exceptions. This makes it possible to for example
 /// disable C++ exceptions but enable Objective-C exceptions.
-static void addExceptionArgs(const ArgList , types::ID InputType,
+static bool addExceptionArgs(const ArgList , types::ID InputType,
  const ToolChain , bool KernelOrKext,
  const ObjCRuntime ,
  ArgStringList ) {
@@ -419,7 +419,7 @@
 Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
 Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
 Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
-return;
+return false;
   }
 
   // See if the user explicitly enabled exceptions.
@@ -462,6 +462,7 @@
 
   if (EH)
 CmdArgs.push_back("-fexceptions");
+  return EH;
 }
 
 static bool ShouldEnableAutolink(const ArgList , const ToolChain ,
@@ -4971,14 +4972,15 @@
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
-  bool AsynchronousUnwindTables =
+  bool UnwindTables =
   Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
options::OPT_fno_asynchronous_unwind_tables,
(TC.IsUnwindTablesDefault(Args) ||
 TC.getSanitizerArgs().needsUnwindTables()) &&
!Freestanding);
-  if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
-   AsynchronousUnwindTables))
+  UnwindTables = Args.hasFlag(options::OPT_funwind_tables,
+  options::OPT_fno_unwind_tables, UnwindTables);
+  if (UnwindTables)
 CmdArgs.push_back("-munwind-tables");
 
   // Prepare `-aux-target-cpu` and `-aux-target-feature` unless
@@ -6039,8 +6041,9 @@
 CmdArgs.push_back("-fapplication-extension");
 
   // Handle GCC-style exception args.
+  bool EH = false;
   if (!C.getDriver().IsCLMode())
-addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
+EH = addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
 
   // Handle exception personalities
   Arg *A = Args.getLastArg(
@@ -6600,6 +6603,10 @@
!TC.getTriple().isAndroid() && TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
+  if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
+  (EH || UnwindTables || DebugInfoKind != codegenoptions::NoDebugInfo))
+CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
+
   if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
 std::string Str = A->getAsString(Args);
 if (!TC.getTriple().isOSBinFormatELF())


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ clang/test/Preprocessor/unwind-tables.c
@@ -0,0 +1,10 @@
+// RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s --check-prefix=NO
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | FileCheck %s --check-prefix=NO
+
+// RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
+// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s
+
+// NO-NOT: 

[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 329441.
MaskRay added a comment.

Move to driver


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Preprocessor/unwind-tables.c


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ clang/test/Preprocessor/unwind-tables.c
@@ -0,0 +1,10 @@
+// RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s 
--check-prefix=NO
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | 
FileCheck %s --check-prefix=NO
+
+// RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
+// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | 
FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables 
-fexceptions | FileCheck %s
+
+// NO-NOT: #define __GCC_HAVE_DWARF2_CFI_ASM
+// CHECK: #define __GCC_HAVE_DWARF2_CFI_ASM 1
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -404,7 +404,7 @@
 /// master flag, -fexceptions and also language specific flags to 
enable/disable
 /// C++ and Objective-C exceptions. This makes it possible to for example
 /// disable C++ exceptions but enable Objective-C exceptions.
-static void addExceptionArgs(const ArgList , types::ID InputType,
+static bool addExceptionArgs(const ArgList , types::ID InputType,
  const ToolChain , bool KernelOrKext,
  const ObjCRuntime ,
  ArgStringList ) {
@@ -419,7 +419,7 @@
 Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
 Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
 Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
-return;
+return false;
   }
 
   // See if the user explicitly enabled exceptions.
@@ -462,6 +462,7 @@
 
   if (EH)
 CmdArgs.push_back("-fexceptions");
+  return EH;
 }
 
 static bool ShouldEnableAutolink(const ArgList , const ToolChain ,
@@ -4971,14 +4972,15 @@
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
-  bool AsynchronousUnwindTables =
+  bool UnwindTables =
   Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
options::OPT_fno_asynchronous_unwind_tables,
(TC.IsUnwindTablesDefault(Args) ||
 TC.getSanitizerArgs().needsUnwindTables()) &&
!Freestanding);
-  if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
-   AsynchronousUnwindTables))
+  UnwindTables = Args.hasFlag(options::OPT_funwind_tables,
+  options::OPT_fno_unwind_tables, UnwindTables);
+  if (UnwindTables)
 CmdArgs.push_back("-munwind-tables");
 
   // Prepare `-aux-target-cpu` and `-aux-target-feature` unless
@@ -6039,8 +6041,9 @@
 CmdArgs.push_back("-fapplication-extension");
 
   // Handle GCC-style exception args.
+  bool EH = false;
   if (!C.getDriver().IsCLMode())
-addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
+EH = addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
 
   // Handle exception personalities
   Arg *A = Args.getLastArg(
@@ -6600,6 +6603,10 @@
!TC.getTriple().isAndroid() && TC.useIntegratedAs()))
 CmdArgs.push_back("-faddrsig");
 
+  if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
+  (EH || UnwindTables || DebugInfoKind != codegenoptions::NoDebugInfo))
+CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
+
   if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
 std::string Str = A->getAsString(Args);
 if (!TC.getTriple().isOSBinFormatELF())


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ clang/test/Preprocessor/unwind-tables.c
@@ -0,0 +1,10 @@
+// RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s --check-prefix=NO
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | FileCheck %s --check-prefix=NO
+
+// RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
+// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s
+// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s
+
+// NO-NOT: #define __GCC_HAVE_DWARF2_CFI_ASM
+// CHECK: #define __GCC_HAVE_DWARF2_CFI_ASM 1
Index: clang/lib/Driver/ToolChains/Clang.cpp

[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D97743#2614480 , @MaskRay wrote:

> In D97743#2613629 , @jansvoboda11 
> wrote:
>
>> Could the logic be implemented in the driver?
>>
>> LGTM regardless.
>
> No. `Res` is a `clang::CompilerInvocation` object. `CompilerInvocation` is 
> not in the driver... `-D` `-U` and `__CET__` are implemented in this file, 
> too.

Right. I meant if it would be possible to move the logic to the driver and pass 
`-D__GCC_HAVE_DWARF2_CFI_ASM=1` explicitly from the driver to `-cc1`, keeping 
`CompilerInvocation` as simple as possible.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D97743#2614827 , @thakis wrote:

> Still broken: http://45.33.8.238/linux/41278/step_7.txt

b4948c27d2e40586c0c4fa7cbf20b9c40a9f7584 


The green Harbomaster misled me..


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Still broken: http://45.33.8.238/linux/41278/step_7.txt


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D97743#2614792 , @thakis wrote:

> This seems to break tests everywhere: 
> http://45.33.8.238/linux/41275/step_7.txt

My bad. Fixed by df67d3526962ae51446b1390e7c40e045e580ec2 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This seems to break tests everywhere: http://45.33.8.238/linux/41275/step_7.txt


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc11ff4bbada3: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable 
(authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Preprocessor/unwind-tables.c


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ 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
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4355,6 +4355,11 @@
   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;


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ 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
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4355,6 +4355,11 @@
   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;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D97743#2613629 , @jansvoboda11 
wrote:

> Could the logic be implemented in the driver?
>
> LGTM regardless.

No. `Res` is a `clang::CompilerInvocation` object. `CompilerInvocation` is not 
in the driver...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

Could the logic be implemented in the driver?

LGTM regardless.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-04 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

@jansvoboda11 :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97743: Define __GCC_HAVE_DWARF2_CFI_ASM if applicable

2021-03-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 327320.
MaskRay retitled this revision from "Define __GCC_HAVE_DWARF2_CFI_ASM to 1 on 
ELF/Mach-O if CC1 -munwind-tables is specified" to "Define 
__GCC_HAVE_DWARF2_CFI_ASM if applicable".
MaskRay edited the summary of this revision.
MaskRay added a comment.

Check -g and exceptions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97743/new/

https://reviews.llvm.org/D97743

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Preprocessor/unwind-tables.c


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ 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
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4350,6 +4350,11 @@
   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;


Index: clang/test/Preprocessor/unwind-tables.c
===
--- /dev/null
+++ 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
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4350,6 +4350,11 @@
   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;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits