Skip to content

Add files list to json-messages output#535

Merged
sim642 merged 7 commits intomasterfrom
json-files
Jan 20, 2022
Merged

Add files list to json-messages output#535
sim642 merged 7 commits intomasterfrom
json-files

Conversation

@sim642
Copy link
Copy Markdown
Member

@sim642 sim642 commented Jan 14, 2022

Adds a list of analyzed (and dependency) files to the json-messages output used by GobPie.
It would be very useful for the latter when using compilation databases to know the list of files that Goblint read from the compilation database and analyzed. Otherwise GobPie would have to unnecessarily duplicate compilation database logic.

Moreover, what this list should also contain is all the dependency files, i.e. included headers (transitively!), because any change to those would also require reanalysis. This however is nontrivial and I currently see two possible ways to go about it:

  1. Extend CIL's #line etc pragma parser to not only change the current location inside its lexer, but record each filename encountered and expose that to Goblint. Just iterating over all locations inside the AST might be insufficient if the header file contains no definitions!
  2. Use the preprocessor with -M to ask it for all dependencies in Makefile format and parse that in Goblint.

@michael-schwarz Do you have a preference or any other idea?

TODO

  • Add included header files.

@sim642
Copy link
Copy Markdown
Member Author

sim642 commented Jan 17, 2022

I implemented the dependencies Makefile approach. With -MMD as an additional argument to the preprocessor, it creates a .d file on the side in Makefile format, listing all the included (non-system) dependencies of the preprocessed file in the same go. This is then parsed in Goblint and added to the json-messages output in the following way:

  "files": {
    "/home/simmo/Desktop/goblint-action-test/cmake-project/main.c": [
      "/home/simmo/dev/goblint/sv-comp/goblint/_opam/share/goblint/includes/assert.h",
      "/home/simmo/Desktop/goblint-action-test/cmake-project/lib/lib.h"
    ],
    "/home/simmo/dev/goblint/sv-comp/goblint/_opam/share/goblint/includes/stdlib.c":
      [],
    "/home/simmo/Desktop/goblint-action-test/cmake-project/lib/lib.c": [
      "/home/simmo/Desktop/goblint-action-test/cmake-project/lib/lib.h"
    ]
  },

Doing it in CIL might be a bit more general if we want to analyze already preprocessed programs that contain those line pragmas, because this wouldn't know about those. Although I don't think we should bother because we cannot reasonably handle such programs with GobPie etc anyway: the warning locations would be in possibly nonexistent physical files that were included, not in the physical file that was actually analyzed, so all the output would be a mess anyway.

@sim642 sim642 marked this pull request as ready for review January 17, 2022 09:37
@michael-schwarz
Copy link
Copy Markdown
Member

Looks good!

Would this information also be sufficient to make the pre-processing (and potentially parsing into CIL files) incremental, in that if no input files have changed, no new run of cpp or no new computation of a CIl file is neccessary?

In order to guarantee this, transitive dependencies would probably have to be considered as well...

@sim642
Copy link
Copy Markdown
Member Author

sim642 commented Jan 17, 2022

Would this information also be sufficient to make the pre-processing (and potentially parsing into CIL files) incremental, in that if no input files have changed, no new run of cpp or no new computation of a CIl file is neccessary?

I think it should be. The use case in GobPie is somewhat related.

In order to guarantee this, transitive dependencies would probably have to be considered as well...

This should cover all includes transitively, because they're inlined transitively during preprocessing, so the corresponding indirect dependency should be direct in this output.

@sim642 sim642 requested a review from karoliineh January 17, 2022 09:52
@sim642
Copy link
Copy Markdown
Member Author

sim642 commented Jan 20, 2022

Due to some MagpieBridge oddities this information cannot be used to its true extent in GobPie for the time being. But I'm merging it anyway since it might become useful.

@sim642 sim642 merged commit d054af3 into master Jan 20, 2022
@sim642 sim642 deleted the json-files branch January 20, 2022 08:32
sim642 added a commit that referenced this pull request Jan 20, 2022
sim642 added a commit that referenced this pull request Jan 20, 2022
michael-schwarz added a commit that referenced this pull request Feb 3, 2022
michael-schwarz added a commit that referenced this pull request Feb 3, 2022
michael-schwarz added a commit that referenced this pull request Feb 3, 2022
This reverts commit d054af3, reversing
changes made to 13193e7.
@sim642 sim642 added this to the v2.0.0 milestone Aug 12, 2022
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.

2 participants