paulkirth updated this revision to Diff 496553. paulkirth added a comment. Address comments.
- improve FileCheck directive in test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D143692/new/ https://reviews.llvm.org/D143692 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/emulated-tls.cpp Index: clang/test/Driver/emulated-tls.cpp =================================================================== --- clang/test/Driver/emulated-tls.cpp +++ clang/test/Driver/emulated-tls.cpp @@ -29,6 +29,10 @@ // RUN: %clang -### -target i686-pc-openbsd %s -femulated-tls -fno-emulated-tls 2>&1 \ // RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### --target=riscv64-linux-android %s -fno-emulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=RISCV %s +// RUN: %clang -### --target=riscv64-linux-android %s -fno-emulated-tls -femulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=RISCV-ERROR %s // Default without -f[no-]emulated-tls, will be decided by the target triple. // DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls" @@ -40,3 +44,6 @@ // NOEMU: "-cc1" {{.*}}"-fno-emulated-tls" // NOEMU-NOT: "-cc1" {{.*}}"-femulated-tls" + +// RISCV-NOT: error: unsupported option '-fno-emulated-tls' for target 'riscv64-unknown-linux-android' +// RISCV-ERROR: error: unsupported option '-femulated-tls' for target 'riscv64-unknown-linux-android' Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6164,8 +6164,19 @@ Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs); - Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, - options::OPT_fno_emulated_tls); + + if (Arg *A = Args.getLastArg(options::OPT_femulated_tls, + options::OPT_fno_emulated_tls)) { + // LLVM does not support Emulated TLS for some architectures, like RISCV + // So issue an error to avoid subtle problems in codegen if the flags are + // incompatible. see https://github.com/llvm/llvm-project/issues/59500 + if (!Triple.supportsEmulatedTLS() && + A->getOption().getID() == options::OPT_femulated_tls) + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getAsString(Args) << TripleStr; + A->render(Args, CmdArgs); + } + Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ); if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
Index: clang/test/Driver/emulated-tls.cpp =================================================================== --- clang/test/Driver/emulated-tls.cpp +++ clang/test/Driver/emulated-tls.cpp @@ -29,6 +29,10 @@ // RUN: %clang -### -target i686-pc-openbsd %s -femulated-tls -fno-emulated-tls 2>&1 \ // RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### --target=riscv64-linux-android %s -fno-emulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=RISCV %s +// RUN: %clang -### --target=riscv64-linux-android %s -fno-emulated-tls -femulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=RISCV-ERROR %s // Default without -f[no-]emulated-tls, will be decided by the target triple. // DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls" @@ -40,3 +44,6 @@ // NOEMU: "-cc1" {{.*}}"-fno-emulated-tls" // NOEMU-NOT: "-cc1" {{.*}}"-femulated-tls" + +// RISCV-NOT: error: unsupported option '-fno-emulated-tls' for target 'riscv64-unknown-linux-android' +// RISCV-ERROR: error: unsupported option '-femulated-tls' for target 'riscv64-unknown-linux-android' Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6164,8 +6164,19 @@ Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs); - Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, - options::OPT_fno_emulated_tls); + + if (Arg *A = Args.getLastArg(options::OPT_femulated_tls, + options::OPT_fno_emulated_tls)) { + // LLVM does not support Emulated TLS for some architectures, like RISCV + // So issue an error to avoid subtle problems in codegen if the flags are + // incompatible. see https://github.com/llvm/llvm-project/issues/59500 + if (!Triple.supportsEmulatedTLS() && + A->getOption().getID() == options::OPT_femulated_tls) + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getAsString(Args) << TripleStr; + A->render(Args, CmdArgs); + } + Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ); if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits