================
@@ -1440,4 +1471,48 @@ TEST_F(PointerFlowTest, ReturnRefPtr) {
   EXPECT_EQ(*Sum, makeEdges(__LINE__, {{{"foo", 1U, true}, {"f", 1U, true}}}));
 }
 
+//////////////////////////////////////////////////////////////
+//          System-header contributor opt-out gate.         //
+//          Spec: tu-summary-extraction,                    //
+//          "System-header contributor opt-out flag".       //
+//////////////////////////////////////////////////////////////
+
+// Default: ExtractFromSystemHeaders == true. A function decl in a
+// `#pragma clang system_header`-marked included header IS enumerated
+// as a contributor and produces an EntitySummary.
+TEST_F(PointerFlowTest, SystemHeader_ExtractDefault) {
+  const char *SysHeader = "int *sys_gp; void sys_fn(int *p) { sys_gp = p; }\n";
+  const char *Main = R"cpp(
+    #include <sys.h>
+    int *user_gp;
+    void user_fn(int *p) { user_gp = p; }
+  )cpp";
+  ASSERT_TRUE(setUpTestWithSystemHeader(Main, SysHeader,
+                                        /*ExtractFromSystemHeaders=*/true));
+  // sys_fn is in a system header but the default (extract-true) enumerates
+  // it as a contributor — summary is non-null.
+  EXPECT_NE(getEntitySummary("sys_fn"), nullptr);
+  // user_fn is enumerated either way (positive control).
+  EXPECT_NE(getEntitySummary("user_fn"), nullptr);
+}
+
+// Opt-out: ExtractFromSystemHeaders == false. The system-header decl
+// is NOT enumerated; getEntitySummary returns nullptr for it. The
+// user-source decl is still enumerated (gate is per-decl, not TU-wide).
+TEST_F(PointerFlowTest, SystemHeader_SkipOptOut) {
+  const char *SysHeader = "int *sys_gp; void sys_fn(int *p) { sys_gp = p; }\n";
+  const char *Main = R"cpp(
+    #include <sys.h>
+    int *user_gp;
+    void user_fn(int *p) { user_gp = p; }
+  )cpp";
+  ASSERT_TRUE(setUpTestWithSystemHeader(Main, SysHeader,
+                                        /*ExtractFromSystemHeaders=*/false));
+  // sys_fn lives in a system header and is skipped at the
+  // ContributorFinder layer when ExtractFromSystemHeaders == false.
+  // getEntitySummary returns nullptr (no summary was built for it).
+  EXPECT_EQ(getEntitySummary("sys_fn"), nullptr);
+  // user_fn is in non-system code so the gate does not fire for it.
+  EXPECT_NE(getEntitySummary("user_fn"), nullptr);
----------------
steakhal wrote:

```suggestion
  EXPECT_FALSE(getEntitySummary("sys_fn")); // 'sys_fn' is skipped.
  EXPECT_TRUE(getEntitySummary("user_fn")); // 'user_fn' is still present.
```

To clarify how I look at this, why am I spelling comments here while in 
contrast pretty much everywhere else I suggested dropping them is because here 
these expectations don't match, thus people may be puzzled if this is just a 
typo. It is not. And this highlights the difference compared to the previous 
test.
I think this should be enough to decipher the expected behavior in the future 
if this test ever breaks.

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

Reply via email to