================
@@ -12,7 +12,10 @@
 using namespace clang;
 using namespace ssaf;
 
-LLVM_INSTANTIATE_REGISTRY(TUSummaryExtractorRegistry)
+// FIXME: LLVM_INSTANTIATE_REGISTRY can't be used here because it drops extra
+// type parameters.
+template class CLANG_EXPORT_TEMPLATE
+    llvm::Registry<TUSummaryExtractor, TUSummaryBuilder &>;
----------------
steakhal wrote:

For a minute, I was thinking of how to generalise this. My idea was to pass the 
parameter types as a variadic macro argument, however it has a couple of down 
sides:

 - It needs `c++20`.
 - No matter what, macros are ugly. Making them more complicated than they 
already are goes against first principles.
 - We are repeating parts of the declaration, and the original author clearly 
wanted to avoid this - hence the macro.

Frankly speaking, the more I think about this macro, the less I think it pulls 
its weight. IMO this macro shouldn't have existed in the first place, so I 
prefer what you propose here.

For the record, here is what I had in mind:
```c++
diff --git a/llvm/include/llvm/Support/Registry.h 
b/llvm/include/llvm/Support/Registry.h
@@ -146,12 +146,13 @@ public:
 /// Instantiate a registry class.
 #define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS)                              
\
   namespace llvm {                                                             
\
-  template class LLVM_ABI_EXPORT Registry<REGISTRY_CLASS::type>;               
\
+  template class LLVM_ABI_EXPORT                                               
\
+      Registry<REGISTRY_CLASS::type __VA_OPT__(, ) __VA_ARGS__>;               
\
   }
 #else
-#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS)                              
\
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS, ...)                         
\
   namespace llvm {                                                             
\
-  template class Registry<REGISTRY_CLASS::type>;                               
\
+  template class Registry<REGISTRY_CLASS::type __VA_OPT__(, ) __VA_ARGS__>;    
\
   }
 #endif
```

And:
```c++
diff --git a/clang/lib/Analysis/Scalable/TUSummary/ExtractorRegistry.cpp 
@@ -12,7 +12,7 @@
 using namespace clang;
 using namespace ssaf;
 
-LLVM_INSTANTIATE_REGISTRY(TUSummaryExtractorRegistry)
+LLVM_INSTANTIATE_REGISTRY(TUSummaryExtractorRegistry, TUSummaryBuilder &)
 
 bool ssaf::isTUSummaryExtractorRegistered(llvm::StringRef SummaryName) {
   for (const auto &Entry : TUSummaryExtractorRegistry::entries())
```

After this train of thought, I only have one problem left: How to avoid this 
from happening in the future?
The presence of the macro breeds this to happen again. I cannot think of a meta 
program to check and fail the build if this would happen again. It's a pity. 
Probably the best long-term action would be to replace all the uses of this 
macro to remove the temptation.

I think we should just merge this as-is. Thanks

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

Reply via email to