Skip to content

Add flag for root cause diagnostic output #258

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

Merged
merged 7 commits into from
Sep 9, 2020
Merged

Conversation

john-h-kastner
Copy link
Collaborator

This pull requests adds a command line flag to print the root cause of wildness information that was previously being used in the clangd interactive mode.

Example usage: cconv-standalone -alltypes -warn-root-cause fptrarrstructcallee.c > /dev/null

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "fptrarrstructcallee.c"
No compilation database found in /home/cc/checkedc-clang/clang/test/CheckedCRewriter or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
/home/cc/checkedc-clang/clang/test/CheckedCRewriter/fptrarrstructcallee.c:27:48: warning: Root cause of unchecked pointers: Inner pointer of a parameter to external function.
extern _Unchecked char *strcpy(char * restrict dest, const char * restrict src : itype(restrict _Nt_array_ptr<const char>));
                                               ^
/home/cc/checkedc-clang/clang/test/CheckedCRewriter/fptrarrstructcallee.c:27:25: warning: Root cause of unchecked pointers: Return value of an external function:strcpy
extern _Unchecked char *strcpy(char * restrict dest, const char * restrict src : itype(restrict _Nt_array_ptr<const char>));
                        ^
/home/cc/checkedc-clang/clang/test/CheckedCRewriter/fptrarrstructcallee.c:108:13: warning: Root cause of unchecked pointers: Cast from int to struct fptrarr *
        x = (struct fptrarr *) 5; 
            ^
3 warnings generated.

The default output with -warn-root-cause filters out root causes located in header files that are only responsible for one wild pointer. If you want to see all root causes, I've also added -warn-all-root-cause to disable this filtering.

I've also made two tweaks to constraint generation that improve the root cause output:

  1. Invalid casts should be reported one time instead of once at each pointer level
  2. Void pointer were being reported as var arg arrays.

// Limit emitted root causes to those that effect more than one pointer
// or are in the main file of the TU. Alternatively, don't filter causes
// if -warn-all-root-cause is passed.
if (WarnAllRootCause || SM.isInMainFile(SL)
Copy link
Member

Choose a reason for hiding this comment

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

If you are in the main file then you will output the warning even if there's just one wild pointer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case main file is per translation unit, so for converting vsftpd, the main files are all the c files passed in as command line arguments. The idea is that all wild pointers in these files are interesting whereas a wild pointer in an included header file that doesn't cause wildness anywhere else is generally not interesting.

Copy link
Member

@mwhicks1 mwhicks1 left a comment

Choose a reason for hiding this comment

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

Looks great! Merge when ready (only comments were about comments).

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

Successfully merging this pull request may close these issues.

2 participants