[PATCH] D125868: [Driver] Recognize -std=gnu++20 enables C++ modules

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 18 03:12:27 PDT 2022


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

In addition to -std=c++20.
This used to result in wrong -cc1 flags produced by Driver


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125868

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cpp20-header-module.cpp
  clang/test/Modules/cxx20-and-header-modules.cpp


Index: clang/test/Modules/cxx20-and-header-modules.cpp
===================================================================
--- clang/test/Modules/cxx20-and-header-modules.cpp
+++ clang/test/Modules/cxx20-and-header-modules.cpp
@@ -2,9 +2,12 @@
 //
 // Check header modules are disabled by default in C++20 mode.
 // RUN: %clang -std=c++20 -fsyntax-only -fno-implicit-modules -fmodules-cache-path=%t -I%S/Inputs/cxx20-and-header-modules -fmodule-map-file=%S/Inputs/cxx20-and-header-modules/a.map %s
+// RUN: %clang -std=gnu++20 -fsyntax-only -fno-implicit-modules -fmodules-cache-path=%t -I%S/Inputs/cxx20-and-header-modules -fmodule-map-file=%S/Inputs/cxx20-and-header-modules/a.map %s
 //
 // Also run in the header modules mode.
 // RUN: %clang -std=c++20 -DBUILDING_MODULE -fmodules -fimplicit-modules -fmodules-cache-path=%t -I%S/Inputs/cxx20-and-header-modules -fmodule-map-file=%S/Inputs/cxx20-and-header-modules/a.map %s
+// RUN: rm -rf %t
+// RUN: %clang -std=gnu++20 -DBUILDING_MODULE -fmodules -fimplicit-modules -fmodules-cache-path=%t -I%S/Inputs/cxx20-and-header-modules -fmodule-map-file=%S/Inputs/cxx20-and-header-modules/a.map %s
 
 #define INCLUDING 1
 #include "a.h"
Index: clang/test/Driver/cpp20-header-module.cpp
===================================================================
--- clang/test/Driver/cpp20-header-module.cpp
+++ clang/test/Driver/cpp20-header-module.cpp
@@ -3,7 +3,11 @@
 // RUN: %clang -fmodules-ts -std=c++20 -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
 // RUN: %clang -std=c++20 -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
 // RUN: %clang -std=c++2a -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
+// RUN: %clang -std=c++2b -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
 // RUN: %clang_cl /std:c++latest /Zs -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
+// RUN: %clang -std=gnu++20 -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
+// RUN: %clang -std=gnu++2a -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
+// RUN: %clang -std=gnu++2b -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=NO_HEADER_MODULES
 //
 // NO_HEADER_MODULES-NOT: -fheader-modules
 // NO_HEADER_MODULES: -cc1
@@ -13,6 +17,10 @@
 // RUN: %clang -fmodules -fmodules-ts -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
 // RUN: %clang -fmodules -std=c++20 -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
 // RUN: %clang -fmodules -std=c++2a -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
+// RUN: %clang -fmodules -std=c++2b -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
+// RUN: %clang -fmodules -std=gnu++20 -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
+// RUN: %clang -fmodules -std=gnu++2a -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
+// RUN: %clang -fmodules -std=gnu++2b -fsyntax-only -v %s 2>&1 | FileCheck %s --check-prefix=HAS_HEADER_MODULES
 //
 // HAS_HEADER_MODULES-NOT: -fno-header-modules
 // HAS_HEADER_MODULES: -cc1
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6537,9 +6537,12 @@
 
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just assume that all languages do.
-  bool HaveModules =
-      Std && (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-              Std->containsValue("c++latest"));
+  bool HaveModules = Std && llvm::any_of(Std->getValues(), [](const char *S) {
+                       constexpr llvm::StringRef CPP_MODULES_STD[] = {
+                           "c++2a",   "c++20",   "c++2b",  "c++latest",
+                           "gnu++2a", "gnu++20", "gnu++2b"};
+                       return llvm::is_contained(CPP_MODULES_STD, S);
+                     });
   RenderModulesOptions(C, D, Args, Input, Output, CmdArgs, HaveModules);
 
   if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125868.430309.patch
Type: text/x-patch
Size: 4227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220518/48701d04/attachment-0001.bin>


More information about the cfe-commits mailing list