[clang] [clang][deps] Don't treat ObjC method args as module directives (PR #97654)

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 17:07:40 PDT 2024


================
@@ -970,6 +970,26 @@ ort \
   EXPECT_EQ(Directives[1].Kind, cxx_export_module_decl);
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {
+  SmallVector<char, 128> Out;
+  SmallVector<dependency_directives_scan::Token, 4> Tokens;
+  SmallVector<Directive, 4> Directives;
+
+  StringRef Source = R"(
+    @interface SomeObjcClass
+      - (void)func:(int)otherData
+              module:(int)module
+              import:(int)import;
+    @end
+  )";
+
+  ASSERT_FALSE(
+      minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives));
+  // `module :` and `import :` not followed by an identifier are not treated as
+  // directive lines because they can be method argument decls.
+  EXPECT_EQ(Directives.size(), 2u); // 2 for the EOF tokens.
----------------
akyrtzi wrote:

This would be a bit more clear if you checked against the `Out` variable, which contains a "pretty-printed" string of the directives that were found, something like this:

```
TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {
  SmallVector<char, 128> Out;

  StringRef Source = R"(
    @interface SomeObjcClass
      - (void)func:(int)otherData
              module:(int)module
              import:(int)import;
    @end
  )";

  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
  // `module :` and `import :` not followed by an identifier are not treated as
  // directive lines because they can be method argument decls.
  EXPECT_STREQ("", Out.data());
}
```

https://github.com/llvm/llvm-project/pull/97654


More information about the cfe-commits mailing list