balazske added a comment.

From the beginning on in this patch I assumed that the location of the bug 
report should be the end of the bug path. But this is probably a wrong 
approach, specially if the bug report has uniqueing location. In that case the 
uniqueing location may be a better place for the bug report. Specially for 
resource leak it is not bad if the report is located at the allocation site 
(still there is a bug path that shows the full path and place of leak). So 
another approach can be to allow only bug equivalence classes where the reports 
have same locations. If this is not true the checker should be fixed that 
generates the reports.

The behavior with `RefLeakReport` is correct if the indicated location in 
minimal output mode should be the end of the bug path. Otherwise it is not 
correct, the report has a different location (allocation site) than the end of 
the path (return point) and we want to see this in minimal mode (or not?). 
Still there is problem, in text output mode the summary line indicates not the 
correct place but the end of the bug path:
before the patch:

  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
    CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
                        ^
  1 warning generated.
  
  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c -analyzer-output 
text
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: note: 
Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object 
of type 'CGColorSpaceRef' with a +1 retain count
    CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:10:3: note: 
Reference count incremented. The object now has a +2 retain count
    CGColorSpaceRetain(X);
    ^~~~~~~~~~~~~~~~~~~~~
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: note: 
Object leaked: object allocated and stored into 'X' is not referenced later in 
this execution path and has a retain count of +2
  }
  ^
  1 warning generated.

after the patch:

  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  1 warning generated.
  
  $ clang -cc1 -internal-isystem 
~/clang/llvm1/build/Debug/lib/clang/11.0.0/include -nostdsysteminc -analyze 
-analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region 
~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c -analyzer-output 
text
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: warning: 
Potential leak of an object stored into 'X' [osx.cocoa.RetainCount]
  }
  ^
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:9:23: note: 
Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object 
of type 'CGColorSpaceRef' with a +1 retain count
    CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // 
expected-warning{{leak}}
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:10:3: note: 
Reference count incremented. The object now has a +2 retain count
    CGColorSpaceRetain(X);
    ^~~~~~~~~~~~~~~~~~~~~
  ~/clang/llvm1/llvm-project/clang/test/Analysis/CGColorSpace.c:11:1: note: 
Object leaked: object allocated and stored into 'X' is not referenced later in 
this execution path and has a retain count of +2
  }
  ^
  1 warning generated.

So it should be clarified how this should work, have the end of the bug path or 
the "location" of the bug report as display location of the bug report.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83961/new/

https://reviews.llvm.org/D83961



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to