-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
Description
While performing static analysis using Clang analyzer, the plist reports contains macros that present in the bug path of a particular report. These macros are not formatted properly and are presented as is. This often makes them unreadable in case they are large and covoluted . For eg.
For the file
#include <stdio.h>
#define dummy_unformatted \
do { \
int x = 1; \
int y = 2; \
if (x < y) { \
printf("unformatted macro with bad spacing\n"); \
} \
} while (0)
#define DIVISION(a, b) (a / b)
int demo_function(int a, int b) {
dummy_unformatted;
printf("DIVISON of %d / %d is: %d\n", a, b, DIVISION(a,b));
return 0;
}
int main(){
int num1 = 10;
int num2 = 0;
demo_function(num1, num2);
return 0;
}
The macro_expansions
displayed on running analysis is
<key>expansion</key>
<key>expansion</key><string>do {int x =1;int y =2;if (x <y ){printf ("unformatted macro with bad spacing\n");}}while (0)</string>
<key>location</key>
<dict>
The command used to run the analysis is
clang --analyze -Xclang -analyzer-output=plist -Xclang -analyzer-config -Xclang expand-macros=true -I. file1.c
Ideally it should display something more readable
<key>expansion</key>
<string>do {
int x = 1;
int y = 2;
if (x < y) {
printf("unformatted macro with bad spacing\n");
}
} while (0)</string>
<key>location</key>
<dict>
It would be really helpful if there was a command line option to turn on macro formating in the plist files.
If there is no problem, I intend to work on this issue.