Repository: ShiftLeftSecurity/codepropertygraph (language: python)

Issue:
New C frontend: `METHOD` stubs for external methods not present
We're probably just not running all the necessary enhancements passed:

```
cpg.call("memcpy").l
res9: Int = 1114
```
but
```
cpg.method("memcpy").size
res10: Int = 0
```



Discussion / hints:
This seems to only be true for `joern-scan`. Looking...

Fix patch:
diff --git a/c2cpg/src/main/scala/io/shiftleft/c2cpg/C2Cpg.scala b/c2cpg/src/main/scala/io/shiftleft/c2cpg/C2Cpg.scala
index 649d2a3e6..836537956 100644
--- a/c2cpg/src/main/scala/io/shiftleft/c2cpg/C2Cpg.scala
+++ b/c2cpg/src/main/scala/io/shiftleft/c2cpg/C2Cpg.scala
@@ -41,7 +41,7 @@ class C2Cpg {
     val cpg = newEmptyCpg(Some(config.outputPath))
     val sourceFileNames = SourceFiles.determine(config.inputPaths, config.sourceFileExtensions)
 
-    new MetaDataPass(cpg, Languages.C, Some(metaDataKeyPool)).createAndApply()
+    new MetaDataPass(cpg, Languages.NEWC, Some(metaDataKeyPool)).createAndApply()
     val headerFileFinder = new HeaderFileFinder(config.inputPaths.toList)
     val astCreationPass =
       new AstCreationPass(sourceFileNames, cpg, functionKeyPool, config, createParseConfig(config), headerFileFinder)
diff --git a/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/codedumper/CodeDumper.scala b/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/codedumper/CodeDumper.scala
index 0bee091ef..492b78d1a 100644
--- a/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/codedumper/CodeDumper.scala
+++ b/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/codedumper/CodeDumper.scala
@@ -26,7 +26,7 @@ object CodeDumper {
     }
 
     val node = location.node.get
-    if (language.isEmpty || !Set(Languages.C).contains(language.get)) {
+    if (language.isEmpty || !Set(Languages.C, Languages.NEWC).contains(language.get)) {
       logger.info("dump not supported for this language or language not set in CPG")
       return ""
     }
diff --git a/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/layers/Scpg.scala b/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/layers/Scpg.scala
index 13297d565..477295395 100644
--- a/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/layers/Scpg.scala
+++ b/semanticcpg/src/main/scala/io/shiftleft/semanticcpg/layers/Scpg.scala
@@ -155,6 +155,21 @@ class Scpg(optionsUnused: LayerCreatorOptions = null) extends LayerCreator {
           new CdgPass(cpg),
           new NamespaceCreator(cpg),
         )
+      case Languages.NEWC =>
+        Iterator(
+          new TypeDeclStubCreator(cpg),
+          new MethodStubCreator(cpg),
+          new MethodDecoratorPass(cpg),
+          new Linker(cpg),
+          new FileCreationPass(cpg),
+          new StaticCallLinker(cpg),
+          new MemberAccessLinker(cpg),
+          new MethodExternalDecoratorPass(cpg),
+          new ContainsEdgePass(cpg),
+          new NamespaceCreator(cpg),
+          new CfgDominatorPass(cpg),
+          new CdgPass(cpg),
+        )
       case _ => Iterator()
     }
   }


Test patch:
diff --git a/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/querying/NodeTypeStartersTests.scala b/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/querying/NodeTypeStartersTests.scala
index e1804ae82..8b4bd8eb2 100644
--- a/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/querying/NodeTypeStartersTests.scala
+++ b/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/querying/NodeTypeStartersTests.scala
@@ -1,7 +1,7 @@
 package io.shiftleft.c2cpg.querying
 
 import io.shiftleft.c2cpg.testfixtures.CCodeToCpgSuite
-import io.shiftleft.codepropertygraph.generated.NodeTypes
+import io.shiftleft.codepropertygraph.generated.{Languages, NodeTypes}
 import io.shiftleft.semanticcpg.language._
 
 /**
@@ -82,7 +82,7 @@ class NodeTypeStartersTests extends CCodeToCpgSuite {
   }
 
   "should allow retrieving of meta data" in {
-    cpg.metaData.language.l shouldBe List("C")
+    cpg.metaData.language.l shouldBe List(Languages.NEWC)
   }
 
   "should allow retrieving all nodes" in {
diff --git a/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/standard/MetaDataTests.scala b/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/standard/MetaDataTests.scala
index 9753d25f7..eeb17fc2c 100644
--- a/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/standard/MetaDataTests.scala
+++ b/c2cpg-tests/src/test/scala/io/shiftleft/c2cpg/standard/MetaDataTests.scala
@@ -1,6 +1,7 @@
 package io.shiftleft.c2cpg.standard
 
 import io.shiftleft.c2cpg.testfixtures.CCodeToCpgSuite
+import io.shiftleft.codepropertygraph.generated.Languages
 import io.shiftleft.semanticcpg.language._
 
 class MetaDataTests extends CCodeToCpgSuite {
@@ -12,7 +13,7 @@ class MetaDataTests extends CCodeToCpgSuite {
 
   "should contain exactly one node with all mandatory fields set" in {
     val List(x) = cpg.metaData.l
-    x.language shouldBe "C"
+    x.language shouldBe Languages.NEWC
     x.version shouldBe "0.1"
     x.overlays shouldBe List("semanticcpg")
     // C-frontend does not set hash for entire CPG.