llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/208377.diff


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Program.cpp (+5-1) 
- (modified) clang/lib/AST/ByteCode/Program.h (+1-1) 
- (added) clang/test/AST/ByteCode/module-dummy-redecl.cpp (+33) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index 1427724ec427c..d73011a8d8dc4 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -124,8 +124,12 @@ UnsignedOrNone Program::getOrCreateGlobal(const ValueDecl 
*VD,
   return std::nullopt;
 }
 
-unsigned Program::getOrCreateDummy(const DeclTy &D, bool IsConstexprUnknown) {
+unsigned Program::getOrCreateDummy(DeclTy D, bool IsConstexprUnknown) {
   assert(D);
+
+  if (const auto *VD = dyn_cast_if_present<VarDecl>(dyn_cast<const Decl *>(D)))
+    D = VD->getFirstDecl();
+
   // Dedup blocks since they are immutable and pointers cannot be compared.
   if (auto It = DummyVariables.find(D.getOpaqueValue());
       It != DummyVariables.end())
diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h
index c98c5c0e51a24..b0ef993258637 100644
--- a/clang/lib/AST/ByteCode/Program.h
+++ b/clang/lib/AST/ByteCode/Program.h
@@ -88,7 +88,7 @@ class Program final {
                                    const Expr *Init = nullptr);
 
   /// Returns or creates a dummy value for unknown declarations.
-  unsigned getOrCreateDummy(const DeclTy &D, bool IsConstexprUnknown = false);
+  unsigned getOrCreateDummy(DeclTy D, bool IsConstexprUnknown = false);
 
   /// Creates a global and returns its index.
   UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init,
diff --git a/clang/test/AST/ByteCode/module-dummy-redecl.cpp 
b/clang/test/AST/ByteCode/module-dummy-redecl.cpp
new file mode 100644
index 0000000000000..5519ac33c2a0a
--- /dev/null
+++ b/clang/test/AST/ByteCode/module-dummy-redecl.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t 
-fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple 
x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t 
-fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple 
x86_64-linux-gnu -fexperimental-new-constant-interpreter
+
+//--- module.modulemap
+module b { header "b.h" export * }
+module c { header "c.h" export * }
+
+//--- nonmodular.h
+template<typename T> int Z;
+
+//--- b.h
+#include "nonmodular.h"
+
+inline constexpr int *xP = &Z<decltype([] { static int n; return &n; }())>;
+
+//--- c.h
+#include "nonmodular.h"
+
+inline constexpr int *yP = &Z<decltype([] { static int n; return &n; }())>;
+
+
+//--- use.cpp
+#include "nonmodular.h"
+
+inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>;
+
+#include "b.h"
+#include "c.h"
+static_assert(xP == yP);

``````````

</details>


https://github.com/llvm/llvm-project/pull/208377
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to