]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Handle error header names in modules [PR107594]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 27 Jan 2024 11:46:44 +0000 (22:46 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 30 Jan 2024 03:48:53 +0000 (14:48 +1100)
When there are no include paths while preprocessing a header-name token,
an empty STRING_CST is returned. This patch ensures this is handled when
attempting to create a module for this name.

PR c++/107594

gcc/cp/ChangeLog:

* module.cc (get_module): Bail on empty name.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/module.cc

index 840c7ef6dabd1e5ba71649227bcb4431bd732543..3c2fef0e3f4b8b1439f62757c37c94cb882c1df2 100644 (file)
@@ -14050,6 +14050,12 @@ get_primary (module_state *parent)
 module_state *
 get_module (tree name, module_state *parent, bool partition)
 {
+  /* We might be given an empty NAME if preprocessing fails to handle
+     a header-name token.  */
+  if (name && TREE_CODE (name) == STRING_CST
+      && TREE_STRING_LENGTH (name) == 0)
+    return nullptr;
+
   if (partition)
     {
       if (!parent)