Skip to content

[clang-sa] Macro definitions of header TUs not included in the plist file #140845

Open
@ankurkraj

Description

@ankurkraj

When analyzing a particular file ( using CTU ) . For a macro that is part of the bug-path - the definition of the macro is not included in the plist reports , if the macro is not called in the parent file but in any other intermediate file

Versions:
clang-14,clang-18,clang-20,main branch binaries

Steps to reproduce the behaviour:

Following is a relatively simpler representation of the workflow

file1.c -> calls demo_function(10,0) defined in file2.c
file2.c -> uses macro DIVISION(a,b) in demo_function(int a, int b), macro DIVISION is defined in file3.h
file3.h -> defines DIVISION(a,b) as ((a)/(b))

I have followed the steps for PCH analysis The command I used was

clang --analyze -Xclang -analyzer-config -Xclang experimental-enable-naive-ctu-analysis=true -Xclang -analyzer-config -Xclang ctu-dir=. -Xclang -analyzer-config -Xclang ctu-phase1-inlining=all -Xclang -analyzer-config -Xclang expand-macros=true  -Xclang -analyzer-output=pl
ist-multi-file  -I. file1.c file2.c file3.c

The result displayed on the screen includes the macro definition but the plist files do not contain these value

In file included from file1.c:1:
file2.c:15:50: warning: Division by zero [core.DivideZero]
    printf("Division of %d / %d is: %d\n", a, b, DIVISION(a,b));
                                                 ^~~~~~~~~~~~~
file3.h:10:29: note: expanded from macro 'DIVISION'
#define DIVISION(a, b) ((a) / (b))
                        ~~~~^~~~~
1 warning generated.

The expected behavious is to have the macro included in the plist file,
This is present , but only in the cases when the entry function of the bug contains the MACRO,

for eg. If in the above case, file2.c directly calls the demo_function(10,0) function in its main, the macro definition is found in that case

Is this an expected behaviour or a bug ? Are there any configurations I can tweak to bring the desirable results ?

If this is the expected behaviour, Is there any heuristic behind this decision to only display the macros for first file ?

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions