================
@@ -104,29 +104,33 @@ template <typename ExtractorFnT>
 void extractAndAddSummaries(TUSummaryExtractor &Extractor,
                             TUSummaryBuilder &Builder, ASTContext &Ctx,
                             ExtractorFnT ExtractFn,
-                            const char *ExtractorName = "") {
+                            llvm::StringRef ExtractorName = {}) {
   llvm::DenseMap<const NamedDecl *, std::vector<const NamedDecl *>>
       Contributors;
   findContributors(Ctx, Contributors);
   for (const auto &[Cano, Decls] : Contributors) {
+    assert(Decls.size() > 0 && !Decls[0]->isImplicit() &&
+           "guaranteed by 'findContributors'");
+    const NamedDecl *Rep = Cano->isImplicit() ? Decls[0] : Cano;
+
     // Templates are skipped, but their instantiations are handled. The idea
     // is that we can conclude facts about a template through all of its
     // instantiations.
-    if (Cano->isTemplated())
+    if (Rep->isTemplated())
       continue;
 
     auto Summary = ExtractFn(Decls);
     assert(Summary);
     if (Summary->empty())
       continue;
 
-    if (auto Id = Extractor.addEntity(Cano)) {
+    if (auto Id = Extractor.addEntity(Rep)) {
       if (!Builder.addSummary(*Id, std::move(Summary)).second)
         logWarningFromError(makeErrAtNode(
-            Ctx, Cano, "dropping duplicate %s summary for entity %s",
-            ExtractorName, Cano->getNameAsString().c_str()));
+            Ctx, Rep, "dropping duplicate %s summary for entity %s",
+            ExtractorName.data(), Rep->getNameAsString().c_str()));
----------------
steakhal wrote:

I don't think `StringRef::data()` is guaranteed to be null-terminated. For 
example, if the StringRef was constructed with an explicit size.

Since this is on the error path (cold path), I think it would make more sense 
to use `ExtractorName.str().c_str()` and not take out chances.

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

Reply via email to