[llvm-branch-commits] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-06 Thread Matt Arsenault via llvm-branch-commits


@@ -2220,6 +2220,14 @@ 
CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
   RValue rvalue = CGF.EmitCall(MSI.CallInfo, Callee, Return, ActualArgs,
&CallSite);
 
+  // Set type identifier metadata of indirect calls for call graph section.
+  if (CGM.getCodeGenOpts().CallGraphSection && Method && CallSite &&

arsenm wrote:

I don't think CallSite can be null here 

https://github.com/llvm/llvm-project/pull/87573
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] [compiler-rt] Allow running tests without installing first (PR #83088)

2024-04-06 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/83088

>From 3c41df9f8fd00d86fe500d9b67e51d15a690209b Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Mon, 26 Feb 2024 16:59:08 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/cmake/Modules/CompilerRTCompile.cmake | 7 ++-
 compiler-rt/test/dfsan/reaches_function.c | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake 
b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
index 64e7acb9afd833..8c804acb44ae4d 100644
--- a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
@@ -70,9 +70,14 @@ function(clang_compile object_file source)
   if (TARGET CompilerRTUnitTestCheckCxx)
 list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
   endif()
+  string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+  if (is_cxx)
+set(compiler ${COMPILER_RT_TEST_COMPILER})
+  else()
+set(compiler ${COMPILER_RT_TEST_CXX_COMPILER})
+  endif()
   if(COMPILER_RT_STANDALONE_BUILD)
 # Only add global flags in standalone build.
-string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
 if(is_cxx)
   string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
 else()
diff --git a/compiler-rt/test/dfsan/reaches_function.c 
b/compiler-rt/test/dfsan/reaches_function.c
index 9e2bcee935b2ac..afcd08cee76a0e 100644
--- a/compiler-rt/test/dfsan/reaches_function.c
+++ b/compiler-rt/test/dfsan/reaches_function.c
@@ -32,7 +32,7 @@ void my_dfsan_reaches_function_callback(dfsan_label label, 
dfsan_origin origin,
 __attribute__((noinline)) uint64_t add(uint64_t *a, uint64_t *b) {
 
   return *a + *b;
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
add.dfsan
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] add.dfsan
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 3]]:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
 
   dfsan_set_label(8, &a, sizeof(a));
   uint64_t c = add(&a, &b);
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
main
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] main
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at

>From c4cb96509ce30182f4fecdd21bf36f6dd94e8d68 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Sun, 3 Mar 2024 14:09:59 -0800
Subject: [PATCH 2/2] fix python formatting

Created using spr 1.3.6-beta.1
---
 compiler-rt/test/lit.common.cfg.py|  7 +--
 compiler-rt/test/safestack/lit.cfg.py | 10 --
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index 5d96bf7e1a58a7..aef07427acf2e4 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -34,6 +34,7 @@ def get_path_from_clang(args, allow_failure):
 lit_config.fatal(msg)
 return path, clang_cmd
 
+
 def find_compiler_libdir():
 """
 Returns the path to library resource directory used
@@ -186,8 +187,10 @@ def push_dynamic_library_lookup_path(config, new_path):
 if test_cc_resource_dir != local_build_resource_dir:
 if config.test_standalone_build_libs and config.compiler_id == "Clang":
 if lit_config.debug:
-lit_config.note(f'Overriding test compiler resource dir to use '
-f'libraries in "{config.compiler_rt_libdir}"')
+lit_config.note(
+f"Overriding test compiler resource dir to use "
+f'libraries in "{config.compiler_rt_libdir}"'
+)
 # Ensure that we use the just-built static libraries when linking by
 # overriding the Clang resource directory. Additionally, we want to use
 # the builtin headers shipped with clang (e.g. stdint.h), so we
diff --git a/compiler-rt/test/safestack/lit.cfg.py 
b/compiler-rt/test/safestack/lit.cfg.py
index bdc316e2f6bc74..aadb8bf0d5c77b 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -13,10 +13,16 @@
 
 # Add clang substitutions.
 config.substitutions.append(
-("%clang_nosafestack ", config.clang + config.target_cflags + " -O0 
-fno-sanitize=safe-stack ")
+(
+  

[llvm-branch-commits] [compiler-rt] [compiler-rt] Allow running tests without installing first (PR #83088)

2024-04-06 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/83088

>From 3c41df9f8fd00d86fe500d9b67e51d15a690209b Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Mon, 26 Feb 2024 16:59:08 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/cmake/Modules/CompilerRTCompile.cmake | 7 ++-
 compiler-rt/test/dfsan/reaches_function.c | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake 
b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
index 64e7acb9afd833..8c804acb44ae4d 100644
--- a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
@@ -70,9 +70,14 @@ function(clang_compile object_file source)
   if (TARGET CompilerRTUnitTestCheckCxx)
 list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
   endif()
+  string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+  if (is_cxx)
+set(compiler ${COMPILER_RT_TEST_COMPILER})
+  else()
+set(compiler ${COMPILER_RT_TEST_CXX_COMPILER})
+  endif()
   if(COMPILER_RT_STANDALONE_BUILD)
 # Only add global flags in standalone build.
-string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
 if(is_cxx)
   string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
 else()
diff --git a/compiler-rt/test/dfsan/reaches_function.c 
b/compiler-rt/test/dfsan/reaches_function.c
index 9e2bcee935b2ac..afcd08cee76a0e 100644
--- a/compiler-rt/test/dfsan/reaches_function.c
+++ b/compiler-rt/test/dfsan/reaches_function.c
@@ -32,7 +32,7 @@ void my_dfsan_reaches_function_callback(dfsan_label label, 
dfsan_origin origin,
 __attribute__((noinline)) uint64_t add(uint64_t *a, uint64_t *b) {
 
   return *a + *b;
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
add.dfsan
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] add.dfsan
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 3]]:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
 
   dfsan_set_label(8, &a, sizeof(a));
   uint64_t c = add(&a, &b);
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
main
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] main
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at

>From c4cb96509ce30182f4fecdd21bf36f6dd94e8d68 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Sun, 3 Mar 2024 14:09:59 -0800
Subject: [PATCH 2/2] fix python formatting

Created using spr 1.3.6-beta.1
---
 compiler-rt/test/lit.common.cfg.py|  7 +--
 compiler-rt/test/safestack/lit.cfg.py | 10 --
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index 5d96bf7e1a58a7..aef07427acf2e4 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -34,6 +34,7 @@ def get_path_from_clang(args, allow_failure):
 lit_config.fatal(msg)
 return path, clang_cmd
 
+
 def find_compiler_libdir():
 """
 Returns the path to library resource directory used
@@ -186,8 +187,10 @@ def push_dynamic_library_lookup_path(config, new_path):
 if test_cc_resource_dir != local_build_resource_dir:
 if config.test_standalone_build_libs and config.compiler_id == "Clang":
 if lit_config.debug:
-lit_config.note(f'Overriding test compiler resource dir to use '
-f'libraries in "{config.compiler_rt_libdir}"')
+lit_config.note(
+f"Overriding test compiler resource dir to use "
+f'libraries in "{config.compiler_rt_libdir}"'
+)
 # Ensure that we use the just-built static libraries when linking by
 # overriding the Clang resource directory. Additionally, we want to use
 # the builtin headers shipped with clang (e.g. stdint.h), so we
diff --git a/compiler-rt/test/safestack/lit.cfg.py 
b/compiler-rt/test/safestack/lit.cfg.py
index bdc316e2f6bc74..aadb8bf0d5c77b 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -13,10 +13,16 @@
 
 # Add clang substitutions.
 config.substitutions.append(
-("%clang_nosafestack ", config.clang + config.target_cflags + " -O0 
-fno-sanitize=safe-stack ")
+(
+  

[llvm-branch-commits] [compiler-rt] [compiler-rt] Allow running tests without installing first (PR #83088)

2024-04-06 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/83088

>From 3c41df9f8fd00d86fe500d9b67e51d15a690209b Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Mon, 26 Feb 2024 16:59:08 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/cmake/Modules/CompilerRTCompile.cmake | 7 ++-
 compiler-rt/test/dfsan/reaches_function.c | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake 
b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
index 64e7acb9afd833..8c804acb44ae4d 100644
--- a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
@@ -70,9 +70,14 @@ function(clang_compile object_file source)
   if (TARGET CompilerRTUnitTestCheckCxx)
 list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
   endif()
+  string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+  if (is_cxx)
+set(compiler ${COMPILER_RT_TEST_COMPILER})
+  else()
+set(compiler ${COMPILER_RT_TEST_CXX_COMPILER})
+  endif()
   if(COMPILER_RT_STANDALONE_BUILD)
 # Only add global flags in standalone build.
-string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
 if(is_cxx)
   string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
 else()
diff --git a/compiler-rt/test/dfsan/reaches_function.c 
b/compiler-rt/test/dfsan/reaches_function.c
index 9e2bcee935b2ac..afcd08cee76a0e 100644
--- a/compiler-rt/test/dfsan/reaches_function.c
+++ b/compiler-rt/test/dfsan/reaches_function.c
@@ -32,7 +32,7 @@ void my_dfsan_reaches_function_callback(dfsan_label label, 
dfsan_origin origin,
 __attribute__((noinline)) uint64_t add(uint64_t *a, uint64_t *b) {
 
   return *a + *b;
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
add.dfsan
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] add.dfsan
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 3]]:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
 
   dfsan_set_label(8, &a, sizeof(a));
   uint64_t c = add(&a, &b);
-  // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] 
main
+  // CHECK: test/dfsan/reaches_function.c:[[# @LINE - 1]] main
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1002, Taint value was stored 
to memory at
   // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan 
{{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
   // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at

>From c4cb96509ce30182f4fecdd21bf36f6dd94e8d68 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Sun, 3 Mar 2024 14:09:59 -0800
Subject: [PATCH 2/3] fix python formatting

Created using spr 1.3.6-beta.1
---
 compiler-rt/test/lit.common.cfg.py|  7 +--
 compiler-rt/test/safestack/lit.cfg.py | 10 --
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index 5d96bf7e1a58a7..aef07427acf2e4 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -34,6 +34,7 @@ def get_path_from_clang(args, allow_failure):
 lit_config.fatal(msg)
 return path, clang_cmd
 
+
 def find_compiler_libdir():
 """
 Returns the path to library resource directory used
@@ -186,8 +187,10 @@ def push_dynamic_library_lookup_path(config, new_path):
 if test_cc_resource_dir != local_build_resource_dir:
 if config.test_standalone_build_libs and config.compiler_id == "Clang":
 if lit_config.debug:
-lit_config.note(f'Overriding test compiler resource dir to use '
-f'libraries in "{config.compiler_rt_libdir}"')
+lit_config.note(
+f"Overriding test compiler resource dir to use "
+f'libraries in "{config.compiler_rt_libdir}"'
+)
 # Ensure that we use the just-built static libraries when linking by
 # overriding the Clang resource directory. Additionally, we want to use
 # the builtin headers shipped with clang (e.g. stdint.h), so we
diff --git a/compiler-rt/test/safestack/lit.cfg.py 
b/compiler-rt/test/safestack/lit.cfg.py
index bdc316e2f6bc74..aadb8bf0d5c77b 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -13,10 +13,16 @@
 
 # Add clang substitutions.
 config.substitutions.append(
-("%clang_nosafestack ", config.clang + config.target_cflags + " -O0 
-fno-sanitize=safe-stack ")
+(
+  

[llvm-branch-commits] [clang] [Serialization] Introduce OnDiskHashTable for specializations (PR #83233)

2024-04-06 Thread Chuanqi Xu via llvm-branch-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/83233

>From f87a54e8ae2afc807cb275f5763691e06562ab0a Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 28 Feb 2024 11:41:53 +0800
Subject: [PATCH] [Serialization] Introduce OnDiskHashTable for specializations

Following up for https://github.com/llvm/llvm-project/pull/83108

This follows the suggestion literally from
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1951172457

which introduces OnDiskHashTable for specializations based on D41416.

Note that I didn't polish this patch to reduce the diff from D41416 to
it easier to review. I'll make the polishing patch later. So that we can
focus what we're doing in this patch and focus on the style in the next
patch.
---
 clang/include/clang/AST/ExternalASTSource.h   |  11 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   5 +
 clang/include/clang/Serialization/ASTReader.h |  34 ++-
 clang/include/clang/Serialization/ASTWriter.h |  13 +
 clang/lib/AST/DeclTemplate.cpp|  17 ++
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |  12 +
 clang/lib/Serialization/ASTReader.cpp | 145 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  27 ++
 clang/lib/Serialization/ASTReaderInternals.h  | 124 +
 clang/lib/Serialization/ASTWriter.cpp | 173 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  32 ++-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazilyTest.cpp  | 260 ++
 15 files changed, 852 insertions(+), 13 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazilyTest.cpp

diff --git a/clang/include/clang/AST/ExternalASTSource.h 
b/clang/include/clang/AST/ExternalASTSource.h
index 8e573965b0a336..af476aa8c57824 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -150,6 +150,17 @@ class ExternalASTSource : public 
RefCountedBase {
   virtual bool
   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
 
+  /// Load all the external specializations for the Decl \param D if \param
+  /// OnlyPartial is false. Otherwise, load all the external **partial**
+  /// specializations for the \param D.
+  virtual void LoadExternalSpecializations(const Decl *D, bool OnlyPartial);
+
+  /// Load all the specializations for the Decl \param D with the same template
+  /// args specified by \param TemplateArgs.
+  virtual void
+  LoadExternalSpecializations(const Decl *D,
+  ArrayRef TemplateArgs);
+
   /// Ensures that the table of all visible declarations inside this
   /// context is up to date.
   ///
diff --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index 2bf91cb5212c5e..f09f037da0556a 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -97,6 +97,12 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
   DeclarationName Name) override;
 
+  void LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
+
+  void
+  LoadExternalSpecializations(const Decl *D,
+  ArrayRef TemplateArgs) 
override;
+
   /// Ensures that the table of all visible declarations inside this
   /// context is up to date.
   void completeVisibleDeclsMap(const DeclContext *DC) override;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index f762116fea956c..20ae6d4bbbcb3f 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -698,6 +698,8 @@ enum ASTRecordTypes {
   /// Record code for an unterminated \#pragma clang assume_nonnull begin
   /// recorded in a preamble.
   PP_ASSUME_NONNULL_LOC = 67,
+
+  UPDATE_SPECIALIZATION = 68,
 };
 
 /// Record types used within a source manager block.
@@ -1523,6 +1525,9 @@ enum DeclCode {
   /// A HLSLBufferDecl record.
   DECL_HLSL_BUFFER,
 
+  // A decls specilization record.
+  DECL_SPECIALIZATIONS,
+
   /// An ImplicitConceptSpecializationDecl record.
   DECL_IMPLICIT_CONCEPT_SPECIALIZATION,
 
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 370d8037a4da17..5640e1eed00388 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -340,6 +340,9 @@ class ASTIdentifierLookupTrait;
 /// The on-disk hash table(s) used for DeclContext name lookup.
 struct DeclContextLookupTable;
 
+/// The on-disk hash table(s) used for specialization decls.
+struct LazySpecializationInfoLookupTable

[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-04-06 Thread Chuanqi Xu via llvm-branch-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/83237

>From 40012e175a6ab3420e2dcaa64538b210173d6950 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 28 Feb 2024 11:41:53 +0800
Subject: [PATCH 1/2] [Serialization] Code cleanups and polish 83233

---
 clang/include/clang/AST/DeclTemplate.h| 40 ++---
 clang/include/clang/AST/ExternalASTSource.h   |  4 +-
 .../clang/Sema/MultiplexExternalSemaSource.h  |  2 +-
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/include/clang/Serialization/ASTReader.h |  2 +-
 clang/lib/AST/DeclTemplate.cpp| 85 +--
 clang/lib/AST/ExternalASTSource.cpp   |  6 +-
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |  7 +-
 clang/lib/Serialization/ASTCommon.h   |  1 -
 clang/lib/Serialization/ASTReader.cpp | 17 ++--
 clang/lib/Serialization/ASTReaderDecl.cpp | 76 +
 clang/lib/Serialization/ASTReaderInternals.h  |  1 -
 clang/lib/Serialization/ASTWriter.cpp | 26 +-
 clang/lib/Serialization/ASTWriterDecl.cpp | 52 +---
 14 files changed, 87 insertions(+), 234 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 51caef54baac26..870c0d1bdd4610 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -256,8 +256,8 @@ class TemplateArgumentList final
   TemplateArgumentList(const TemplateArgumentList &) = delete;
   TemplateArgumentList &operator=(const TemplateArgumentList &) = delete;
 
-  /// Create hash for the given arguments.
-  static unsigned ComputeODRHash(ArrayRef Args);
+  /// Create stable hash for the given arguments across compiler invocations.
+  static unsigned ComputeStableHash(ArrayRef Args);
 
   /// Create a new template argument list that copies the given set of
   /// template arguments.
@@ -733,25 +733,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   }
 
   void anchor() override;
-  struct LazySpecializationInfo {
-uint32_t DeclID = ~0U;
-unsigned ODRHash = ~0U;
-bool IsPartial = false;
-LazySpecializationInfo(uint32_t ID, unsigned Hash = ~0U,
-   bool Partial = false)
-: DeclID(ID), ODRHash(Hash), IsPartial(Partial) {}
-LazySpecializationInfo() {}
-bool operator<(const LazySpecializationInfo &Other) const {
-  return DeclID < Other.DeclID;
-}
-bool operator==(const LazySpecializationInfo &Other) const {
-  assert((DeclID != Other.DeclID || ODRHash == Other.ODRHash) &&
- "Hashes differ!");
-  assert((DeclID != Other.DeclID || IsPartial == Other.IsPartial) &&
- "Both must be the same kinds!");
-  return DeclID == Other.DeclID;
-}
-  };
 
 protected:
   template  struct SpecEntryTraits {
@@ -795,16 +776,20 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 
   void loadLazySpecializationsImpl(bool OnlyPartial = false) const;
 
-  void loadLazySpecializationsImpl(llvm::ArrayRef Args,
+  bool loadLazySpecializationsImpl(llvm::ArrayRef Args,
TemplateParameterList *TPL = nullptr) const;
 
-  Decl *loadLazySpecializationImpl(LazySpecializationInfo &LazySpecInfo) const;
-
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  template 
+  typename SpecEntryTraits::DeclType *
+  findSpecializationLocally(llvm::FoldingSetVector &Specs,
+void *&InsertPos,
+ProfileArguments &&...ProfileArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -820,13 +805,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 llvm::PointerIntPair
   InstantiatedFromMember;
 
-/// If non-null, points to an array of specializations (including
-/// partial specializations) known only by their external declaration IDs.
-///
-/// The first value in the array is the number of specializations/partial
-/// specializations that follow.
-LazySpecializationInfo *LazySpecializations = nullptr;
-
 /// The set of "injected" template arguments used within this
 /// template.
 ///
diff --git a/clang/include/clang/AST/ExternalASTSource.h 
b/clang/include/clang/AST/ExternalASTSource.h
index af476aa8c57824..769abf44ecd430 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -157,7 +157,9 @@ class ExternalASTSource : public 
RefCountedBase {
 
   /// Load all the specializations for the Decl \param D with the same template
   /// args specified by \param TemplateArgs.
-  virtual void
+  ///
+  /// Return true if any new specializations get loaded. Return false 
otherwise.
+  virtual bool
   LoadExternalSpeci

[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-04-06 Thread Chuanqi Xu via llvm-branch-commits

ChuanqiXu9 wrote:

Thanks for the reduced test case. It is pretty helpful. I've added it to the 
current patch.

The root cause of the issue comes from an oversight in 
https://github.com/llvm/llvm-project/pull/83108/files#diff-dffd10772d07fb8c737cdf812839afa0173447c4812698c0c19618c34d92daddR806-R829.
 That we calculate the ODR Hash for class template specialization twice. Then 
for the example you described, the linear recursive computation becomes to 
somewhat similar to fibonacci computation:

```
wrap<40> -> wrap<39>  -> wrap<38> -> ...
  |-> wrap<38>
   -> wrap<39> -> wrap<38>
   -> wrap<38>
```

This test case passes quickly now after I remove the duplicated ODR computation.

https://github.com/llvm/llvm-project/pull/83237
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits