Skip to content

improve update_cc_test_checks.py for template #102505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yxsamliu
Copy link
Collaborator

@yxsamliu yxsamliu commented Aug 8, 2024

Teach update_cc_test_checks.py to add check line for template function instantiation.

Teach update_cc_test_checks.py to add check line for template function
instantiation.
@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-testing-tools

Author: Yaxun (Sam) Liu (yxsamliu)

Changes

Teach update_cc_test_checks.py to add check line for template function instantiation.


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

1 Files Affected:

  • (modified) llvm/utils/update_cc_test_checks.py (+31-19)
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index 3ffb07ddf6ad8..25c72e283cd9a 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -69,6 +69,7 @@ def parse_clang_ast_json(node, loc, search):
             "TranslationUnitDecl",
             "CXXRecordDecl",
             "ClassTemplateSpecializationDecl",
+            "FunctionTemplateDecl",
         ):
             # Specializations must use the loc from the specialization, not the
             # template, and search for the class's spelling as the specialization
@@ -89,6 +90,7 @@ def parse_clang_ast_json(node, loc, search):
             "CXXConstructorDecl",
             "CXXDestructorDecl",
             "CXXConversionDecl",
+            "FunctionTemplateDecl",
         ):
             return
         if loc is None:
@@ -105,25 +107,35 @@ def parse_clang_ast_json(node, loc, search):
             )
             return
 
-        # If there is no 'inner' object, it is a function declaration and we can
-        # skip it. However, function declarations may also contain an 'inner' list,
-        # but in that case it will only contains ParmVarDecls. If we find an entry
-        # that is not a ParmVarDecl, we know that this is a function definition.
-        has_body = False
-        if "inner" in node:
-            for i in node["inner"]:
-                if i.get("kind", "ParmVarDecl") != "ParmVarDecl":
-                    has_body = True
-                    break
-        if not has_body:
-            common.debug("Skipping function without body:", node["name"], "@", loc)
-            return
-        spell = node["name"]
-        if search is None:
-            search = spell
-        mangled = node.get("mangledName", spell)
-        ret[int(line) - 1].append((spell, mangled, search))
-
+        # If this is a FunctionTemplateDecl, we need to extract the mangled name
+        # of the template instantiation(s)
+        if node_kind == "FunctionTemplateDecl":
+            for inner in node.get("inner", []):
+                if inner["kind"] == "FunctionDecl":
+                    spell = inner["name"]
+                    mangled = inner.get("mangledName", spell)
+                    if search is None:
+                        search = spell
+                    ret[int(line) - 1].append((spell, mangled, search))
+        else:
+            # If there is no 'inner' object, it is a function declaration and we can
+            # skip it. However, function declarations may also contain an 'inner' list,
+            # but in that case it will only contains ParmVarDecls. If we find an entry
+            # that is not a ParmVarDecl, we know that this is a function definition.
+            has_body = False
+            if "inner" in node:
+                for i in node["inner"]:
+                    if i.get("kind", "ParmVarDecl") != "ParmVarDecl":
+                        has_body = True
+                        break
+            if not has_body:
+                common.debug("Skipping function without body:", node["name"], "@", loc)
+                return
+            spell = node["name"]
+            if search is None:
+                search = spell
+            mangled = node.get("mangledName", spell)
+            ret[int(line) - 1].append((spell, mangled, search))
     ast = json.loads(stdout)
     if ast["kind"] != "TranslationUnitDecl":
         common.error("Clang AST dump JSON format changed?")

Copy link
Member

@Artem-B Artem-B left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in principle.

Do we have any tests for this script?

@arichardson
Copy link
Member

Do you have a test case for this? If so it would be good to add it to the existing set of tests (e.g. a test function that did not have test checks before)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants