Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3808,6 +3808,10 @@ Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree); Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); + // Forward flags for OpenMP + Args.AddLastArg(CmdArgs, options::OPT_fopenmp); + Args.AddLastArg(CmdArgs, options::OPT_fopenmp_EQ); + const SanitizerArgs &Sanitize = getToolChain().getSanitizerArgs(); Sanitize.addArgs(Args, CmdArgs); @@ -6267,9 +6271,7 @@ Args.AddAllArgs(CmdArgs, options::OPT_L); LibOpenMP UsedOpenMPLib = LibUnknown; - if (Args.hasArg(options::OPT_fopenmp)) { - UsedOpenMPLib = LibGOMP; - } else if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { + if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { UsedOpenMPLib = llvm::StringSwitch(A->getValue()) .Case("libgomp", LibGOMP) .Case("libiomp5", LibIOMP5) @@ -6277,6 +6279,8 @@ if (UsedOpenMPLib == LibUnknown) getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << A->getValue(); + } else if (Args.hasArg(options::OPT_fopenmp)) { + UsedOpenMPLib = LibIOMP5; } switch (UsedOpenMPLib) { case LibGOMP: @@ -7992,16 +7996,16 @@ linkSanitizerRuntimeDeps(ToolChain, CmdArgs); LibOpenMP UsedOpenMPLib = LibUnknown; - if (Args.hasArg(options::OPT_fopenmp)) { - UsedOpenMPLib = LibGOMP; - } else if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { + if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { UsedOpenMPLib = llvm::StringSwitch(A->getValue()) - .Case("libgomp", LibGOMP) - .Case("libiomp5", LibIOMP5) - .Default(LibUnknown); + .Case("libgomp", LibGOMP) + .Case("libiomp5", LibIOMP5) + .Default(LibUnknown); if (UsedOpenMPLib == LibUnknown) D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getOption().getName() << A->getValue(); + } else if (Args.hasArg(options::OPT_fopenmp)) { + UsedOpenMPLib = LibIOMP5; } switch (UsedOpenMPLib) { case LibGOMP: Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1632,11 +1632,12 @@ Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel); } - // Check if -fopenmp= is specified. + // Check if -fopenmp or -fopenmp= is specified. + Opts.OpenMP = Args.hasArg(options::OPT_fopenmp); if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { Opts.OpenMP = llvm::StringSwitch(A->getValue()) - .Case("libiomp5", true) - .Default(false); + .Case("libiomp5", true) + .Default(false); } // Record whether the __DEPRECATED define was requested. Index: test/OpenMP/linking.c =================================================================== --- test/OpenMP/linking.c +++ test/OpenMP/linking.c @@ -5,14 +5,14 @@ // RUN: -fopenmp -target i386-unknown-linux \ // RUN: | FileCheck --check-prefix=CHECK-LD-32 %s // CHECK-LD-32: "{{.*}}ld{{(.exe)?}}" -// CHECK-LD-32: "-lgomp" "-lrt" "-lgcc" +// CHECK-LD-32: "-liomp5" "-lgcc" // CHECK-LD-32: "-lpthread" "-lc" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -fopenmp -target x86_64-unknown-linux \ // RUN: | FileCheck --check-prefix=CHECK-LD-64 %s // CHECK-LD-64: "{{.*}}ld{{(.exe)?}}" -// CHECK-LD-64: "-lgomp" "-lrt" "-lgcc" +// CHECK-LD-64: "-liomp5" "-lgcc" // CHECK-LD-64: "-lpthread" "-lc" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ @@ -54,18 +54,16 @@ // CHECK-LIB-LD-64: error: unsupported argument 'lib' to option 'fopenmp=' // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ -// RUN: -fopenmp -fopenmp=libiomp5 -target i386-unknown-linux \ -// RUN: | FileCheck --check-prefix=CHECK-LD-WARN-32 %s -// CHECK-LD-WARN-32: warning: argument unused during compilation: '-fopenmp=libiomp5' -// CHECK-LD-WARN-32: "{{.*}}ld{{(.exe)?}}" -// CHECK-LD-WARN-32: "-lgomp" "-lrt" "-lgcc" -// CHECK-LD-WARN-32: "-lpthread" "-lc" +// RUN: -fopenmp -fopenmp=libgomp -target i386-unknown-linux \ +// RUN: | FileCheck --check-prefix=CHECK-LD-OVERRIDE-32 %s +// CHECK-LD-OVERRIDE-32: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD-OVERRIDE-32: "-lgomp" "-lrt" "-lgcc" +// CHECK-LD-OVERRIDE-32: "-lpthread" "-lc" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ -// RUN: -fopenmp -fopenmp=libiomp5 -target x86_64-unknown-linux \ -// RUN: | FileCheck --check-prefix=CHECK-LD-WARN-64 %s -// CHECK-LD-WARN-64: warning: argument unused during compilation: '-fopenmp=libiomp5' -// CHECK-LD-WARN-64: "{{.*}}ld{{(.exe)?}}" -// CHECK-LD-WARN-64: "-lgomp" "-lrt" "-lgcc" -// CHECK-LD-WARN-64: "-lpthread" "-lc" +// RUN: -fopenmp -fopenmp=libgomp -target x86_64-unknown-linux \ +// RUN: | FileCheck --check-prefix=CHECK-LD-OVERRIDE-64 %s +// CHECK-LD-OVERRIDE-64: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc" +// CHECK-LD-OVERRIDE-64: "-lpthread" "-lc" // Index: test/OpenMP/openmp_common.c =================================================================== --- test/OpenMP/openmp_common.c +++ test/OpenMP/openmp_common.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s #pragma omp // expected-error {{expected an OpenMP directive}} #pragma omp unknown_directive // expected-error {{expected an OpenMP directive}} Index: test/OpenMP/predefined_macro.c =================================================================== --- test/OpenMP/predefined_macro.c +++ test/OpenMP/predefined_macro.c @@ -1,33 +1,19 @@ // RUN: %clang_cc1 -fopenmp=libiomp5 -verify -DFOPENMP -o - %s +// RUN: %clang_cc1 -fopenmp -verify -DFOPENMP -o - %s // RUN: %clang_cc1 -verify -o - %s +// RUN: %clang_cc1 -verify -fopenmp -fopenmp=libgomp -o - %s // expected-no-diagnostics #ifdef FOPENMP -// -fopenmp=libiomp5 option is specified +// -fopenmp=libiomp5 or -fopenmp option is specified #ifndef _OPENMP #error "No _OPENMP macro is defined with -fopenmp option" #elsif _OPENMP != 201307 #error "_OPENMP has incorrect value" #endif //_OPENMP #else -// No -fopenmp=libiomp5 option is specified +// No -fopenmp=libiomp5 or -fopenmp option is specified #ifdef _OPENMP #error "_OPENMP macro is defined without -fopenmp option" #endif // _OPENMP #endif // FOPENMP -// RUN: %clang_cc1 -fopenmp=libiomp5 -verify -DFOPENMP -o - %s -// RUN: %clang_cc1 -verify -o - %s -// expected-no-diagnostics -#ifdef FOPENMP -// -fopenmp=libiomp5 option is specified -#ifndef _OPENMP -#error "No _OPENMP macro is defined with -fopenmp option" -#elsif _OPENMP != 201307 -#error "_OPENMP has incorrect value" -#endif // _OPENMP -#else -// No -fopenmp=libiomp5 option is specified -#ifdef _OPENMP -#error "_OPENMP macro is defined without -fopenmp option" -#endif // _OPENMP -#endif // FOPENMP