[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-08 Thread Daniel Marjamäki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297283: [analyzer] Clarify 'uninitialized function argument' 
messages (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D30341?vs=90471=91012#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30341

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  cfe/trunk/test/Analysis/NewDelete-checker-test.cpp
  cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
  cfe/trunk/test/Analysis/malloc.m
  cfe/trunk/test/Analysis/misc-ps-region-store.m
  cfe/trunk/test/Analysis/misc-ps.m
  cfe/trunk/test/Analysis/null-deref-ps.c
  cfe/trunk/test/Analysis/nullptr.cpp
  cfe/trunk/test/Analysis/uninit-const.c
  cfe/trunk/test/Analysis/uninit-const.cpp
  cfe/trunk/test/Analysis/uninit-msg-expr.m
  cfe/trunk/test/Analysis/uninit-vals-ps.c
  cfe/trunk/test/Analysis/uninit-vals.cpp

Index: cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
===
--- cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
+++ cfe/trunk/test/Analysis/diagnostics/undef-value-param.m
@@ -45,8 +45,8 @@
 CreateRefUndef(, 4);
  //expected-note@-1{{Calling 'CreateRefUndef'}}
  //expected-note@-2{{Returning from 'CreateRefUndef'}}
-CFRelease(storeRef); //expected-warning {{Function call argument is an uninitialized value}}
- //expected-note@-1{{Function call argument is an uninitialized value}}
+CFRelease(storeRef); //expected-warning {{1st function call argument is an uninitialized value}}
+ //expected-note@-1{{1st function call argument is an uninitialized value}}
 }
 @end
 
@@ -918,12 +918,12 @@
 // CHECK-NEXT:  
 // CHECK-NEXT:  depth0
 // CHECK-NEXT:  extended_message
-// CHECK-NEXT:  Function call argument is an uninitialized value
+// CHECK-NEXT:  1st function call argument is an uninitialized value
 // CHECK-NEXT:  message
-// CHECK-NEXT:  Function call argument is an uninitialized value
+// CHECK-NEXT:  1st function call argument is an uninitialized value
 // CHECK-NEXT: 
 // CHECK-NEXT:
-// CHECK-NEXT:descriptionFunction call argument is an uninitialized value
+// CHECK-NEXT:description1st function call argument is an uninitialized value
 // CHECK-NEXT:categoryLogic error
 // CHECK-NEXT:typeUninitialized argument value
 // CHECK-NEXT:check_namecore.CallAndMessage
Index: cfe/trunk/test/Analysis/null-deref-ps.c
===
--- cfe/trunk/test/Analysis/null-deref-ps.c
+++ cfe/trunk/test/Analysis/null-deref-ps.c
@@ -286,7 +286,7 @@
 
 void pr4759() {
   int *p;
-  pr4759_aux(p); // expected-warning{{Function call argument is an uninitialized value}}
+  pr4759_aux(p); // expected-warning{{1st function call argument is an uninitialized value}}
 }
 
 // Relax function call arguments invalidation to be aware of const
Index: cfe/trunk/test/Analysis/uninit-const.c
===
--- cfe/trunk/test/Analysis/uninit-const.c
+++ cfe/trunk/test/Analysis/uninit-const.c
@@ -24,16 +24,16 @@
 void f_1(void) {
   int t;
   int* tp = // expected-note {{'tp' initialized here}}
-  doStuff_pointerToConstInt(tp);  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_pointerToConstInt(tp);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
+   // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
 
 void f_1_1(void) {
   int t;
   int* tp1 = 
   int* tp2 = tp1;// expected-note {{'tp2' initialized here}}
-  doStuff_pointerToConstInt(tp2);  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_pointerToConstInt(tp2);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
+   // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
 
 
@@ -45,8 +45,8 @@
   int t;
   int* p = f_2_sub();
   int* tp = p; // expected-note {{'tp' initialized here}}
-  doStuff_pointerToConstInt(tp); // expected-warning {{Function call argument is a pointer to uninitialized value}}
-  // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_pointerToConstInt(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
+  // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
 

[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Oh well, that's not good. Probably that's because we always highlight the 
current statement in path-sensitive reports. I guess we could improve upon that 
in the bug reporter.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-06 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

No the argument is not shown with tilde/column number.

Code example:

  void f(int x, ...);
  
  void dostuff() {
int x[10];
f(12,3,4,5,x[3],6,7,8);
  }

Output:

  C:\Users\danielm>\llvm\build\Debug\bin\clang -cc1 -analyze 
-analyzer-checker=core test3.c
  test3.c:6:3: warning: Function call argument is an uninitialized value
f(12,3,4,5,x[3],6,7,8);
^~


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

The code looks good to me, but i'm expressing a tiny doubt: regardless of the 
output format, the user always has the relevant argument highlighted anyway 
(column number, tilde-underlined in command line, blue-ish box in scan-build, 
etc.), so the only significant clarification i see is on test files, where the 
column is not obvious.

If having that information duplicated to the warning message is considered 
useful (easier to read, catchy), i'm ok with it :)

The definitive document on this debate is 
https://clang.llvm.org/diagnostics.html : it begins with explicitly encouraging 
highlights through column numbers and underlines, but it doesn't provide an 
opinion on including this info in the warning message. So i'm confused.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-03 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 90471.
danielmarjamaki added a comment.

Fix review comment


Repository:
  rL LLVM

https://reviews.llvm.org/D30341

Files:
  lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/diagnostics/undef-value-param.m
  test/Analysis/malloc.m
  test/Analysis/misc-ps-region-store.m
  test/Analysis/misc-ps.m
  test/Analysis/null-deref-ps.c
  test/Analysis/nullptr.cpp
  test/Analysis/uninit-const.c
  test/Analysis/uninit-const.cpp
  test/Analysis/uninit-msg-expr.m
  test/Analysis/uninit-vals-ps.c
  test/Analysis/uninit-vals.cpp

Index: test/Analysis/uninit-vals.cpp
===
--- test/Analysis/uninit-vals.cpp
+++ test/Analysis/uninit-vals.cpp
@@ -27,7 +27,7 @@
   // case with undefined values, too.
   c1.b.a = c2->b.a;
 #else
-  c1.b.a = c2->b.a; // expected-warning{{Function call argument is an uninitialized value}}
+  c1.b.a = c2->b.a; // expected-warning{{1st function call argument is an uninitialized value}}
 #endif
 }
 }
Index: test/Analysis/uninit-vals-ps.c
===
--- test/Analysis/uninit-vals-ps.c
+++ test/Analysis/uninit-vals-ps.c
@@ -14,7 +14,7 @@
 
 int f1_b() {
   int x;
-  return bar(x)+1;  // expected-warning{{Function call argument is an uninitialized value}}
+  return bar(x)+1;  // expected-warning{{1st function call argument is an uninitialized value}}
 }
 
 int f2() {
Index: test/Analysis/uninit-msg-expr.m
===
--- test/Analysis/uninit-msg-expr.m
+++ test/Analysis/uninit-msg-expr.m
@@ -52,5 +52,5 @@
 void f3() {
   NSMutableArray *aArray = [NSArray array];
   NSString *aString;
-  [aArray addObject:aString]; // expected-warning {{Argument in message expression is an uninitialized value}}
+  [aArray addObject:aString]; // expected-warning {{1st argument in message expression is an uninitialized value}}
 }
Index: test/Analysis/uninit-const.cpp
===
--- test/Analysis/uninit-const.cpp
+++ test/Analysis/uninit-const.cpp
@@ -66,8 +66,8 @@
   int  = t;
   int  = p;
   int  = s;  //expected-note {{'q' initialized here}}
-  doStuff6(q); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(q); //expected-warning {{1st function call argument is an uninitialized value}}
+   //expected-note@-1 {{1st function call argument is an uninitialized value}}
 }
 
 void doStuff6_3(int& q_, int *ptr_) {}
@@ -78,32 +78,32 @@
   int  = t;
   int  = p;
   int  = s;
-  doStuff6_3(q,ptr); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6_3(q,ptr); //expected-warning {{2nd function call argument is an uninitialized value}}
+   //expected-note@-1 {{2nd function call argument is an uninitialized value}}
 
 }
 
 void f6(void) {
   int k;   // expected-note {{'k' declared without an initial value}}
-  doStuff6(k); // expected-warning {{Function call argument is an uninitialized value}}
-   // expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(k); // expected-warning {{1st function call argument is an uninitialized value}}
+   // expected-note@-1 {{1st function call argument is an uninitialized value}}
 
 }
 
 
 
 void f5(void) {
   int t;
   int* tp = // expected-note {{'tp' initialized here}}
-  doStuff_uninit(tp);  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_uninit(tp);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
+   // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
 
 
 void f4(void) {
   int y;// expected-note {{'y' declared without an initial value}}
-  doStuff4(y);  // expected-warning {{Function call argument is an uninitialized value}}
-// expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff4(y);  // expected-warning {{1st function call argument is an uninitialized value}}
+// expected-note@-1 {{1st function call argument is an uninitialized value}}
 }
 
 void f3(void) {
@@ -123,6 +123,6 @@
 
 void f_uninit(void) {
   int x;
-  doStuff_uninit();  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_uninit();  // expected-warning {{1st function call 

[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-02 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

danielmarjamaki wrote:
> zaks.anna wrote:
> > danielmarjamaki wrote:
> > > zaks.anna wrote:
> > > > Have you considered using  llvm::raw_svector_ostream here as well as 
> > > > passing it an argument to describeUninitializedArgumentInCall? For 
> > > > example, see  MallocChecker.cpp.
> > > I changed so describeUninitializedArgumentInCall() returns an llvm::Twine 
> > > instead of std::string. hope you like it.
> > > 
> > I do not think it's safe to use llvm:Twine here. See 
> > http://llvm.org/docs/ProgrammersManual.html#the-twine-class
> > 
> > How about using llvm::raw_svector_ostream as I suggested?
> sure I can use llvm::raw_svector_ostream instead. I can try to update the 
> patch soon.
> 
> I just wonder how it is unsafe. I did consider if llvm::Twine would be safe. 
> Is there a particular return that you can point out? The function mostly 
> returns constant string literals. Those should be safe right? Then the 
> function also have a few returns like this:
> ```
> return llvm::Twine(ArgumentNumber + 1) +
>llvm::getOrdinalSuffix(ArgumentNumber + 1) +
>" function call argument is an uninitialized value";
> ```
> Yes we need to be careful for such code. However since 
> llvm::getOrdinalSuffix() returns a StringRef this particular code should be 
> safe right?
> 
> When the stream is used I have to tweak each return statement. I thought that 
> was a bit unfortunate. But it's not a biggie.
> 
After some more reading in the llvm::Twine docs I am also thinking that I 
misuse it. so I will change the code.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-02 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

zaks.anna wrote:
> danielmarjamaki wrote:
> > zaks.anna wrote:
> > > Have you considered using  llvm::raw_svector_ostream here as well as 
> > > passing it an argument to describeUninitializedArgumentInCall? For 
> > > example, see  MallocChecker.cpp.
> > I changed so describeUninitializedArgumentInCall() returns an llvm::Twine 
> > instead of std::string. hope you like it.
> > 
> I do not think it's safe to use llvm:Twine here. See 
> http://llvm.org/docs/ProgrammersManual.html#the-twine-class
> 
> How about using llvm::raw_svector_ostream as I suggested?
sure I can use llvm::raw_svector_ostream instead. I can try to update the patch 
soon.

I just wonder how it is unsafe. I did consider if llvm::Twine would be safe. Is 
there a particular return that you can point out? The function mostly returns 
constant string literals. Those should be safe right? Then the function also 
have a few returns like this:
```
return llvm::Twine(ArgumentNumber + 1) +
   llvm::getOrdinalSuffix(ArgumentNumber + 1) +
   " function call argument is an uninitialized value";
```
Yes we need to be careful for such code. However since llvm::getOrdinalSuffix() 
returns a StringRef this particular code should be safe right?

When the stream is used I have to tweak each return statement. I thought that 
was a bit unfortunate. But it's not a biggie.



Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-03-01 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

danielmarjamaki wrote:
> zaks.anna wrote:
> > Have you considered using  llvm::raw_svector_ostream here as well as 
> > passing it an argument to describeUninitializedArgumentInCall? For example, 
> > see  MallocChecker.cpp.
> I changed so describeUninitializedArgumentInCall() returns an llvm::Twine 
> instead of std::string. hope you like it.
> 
I do not think it's safe to use llvm:Twine here. See 
http://llvm.org/docs/ProgrammersManual.html#the-twine-class

How about using llvm::raw_svector_ostream as I suggested?


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-02-28 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki marked an inline comment as done.
danielmarjamaki added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

zaks.anna wrote:
> Have you considered using  llvm::raw_svector_ostream here as well as passing 
> it an argument to describeUninitializedArgumentInCall? For example, see  
> MallocChecker.cpp.
I changed so describeUninitializedArgumentInCall() returns an llvm::Twine 
instead of std::string. hope you like it.



Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-02-28 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 90030.
danielmarjamaki added a comment.

minor updates. Use llvm::getOrdinalNumber(). Use llvm::Twine.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341

Files:
  lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/diagnostics/undef-value-param.m
  test/Analysis/malloc.m
  test/Analysis/misc-ps-region-store.m
  test/Analysis/misc-ps.m
  test/Analysis/null-deref-ps.c
  test/Analysis/nullptr.cpp
  test/Analysis/uninit-const.c
  test/Analysis/uninit-const.cpp
  test/Analysis/uninit-msg-expr.m
  test/Analysis/uninit-vals-ps.c
  test/Analysis/uninit-vals.cpp

Index: test/Analysis/uninit-vals.cpp
===
--- test/Analysis/uninit-vals.cpp
+++ test/Analysis/uninit-vals.cpp
@@ -27,7 +27,7 @@
   // case with undefined values, too.
   c1.b.a = c2->b.a;
 #else
-  c1.b.a = c2->b.a; // expected-warning{{Function call argument is an uninitialized value}}
+  c1.b.a = c2->b.a; // expected-warning{{1st function call argument is an uninitialized value}}
 #endif
 }
 }
Index: test/Analysis/uninit-vals-ps.c
===
--- test/Analysis/uninit-vals-ps.c
+++ test/Analysis/uninit-vals-ps.c
@@ -14,7 +14,7 @@
 
 int f1_b() {
   int x;
-  return bar(x)+1;  // expected-warning{{Function call argument is an uninitialized value}}
+  return bar(x)+1;  // expected-warning{{1st function call argument is an uninitialized value}}
 }
 
 int f2() {
Index: test/Analysis/uninit-msg-expr.m
===
--- test/Analysis/uninit-msg-expr.m
+++ test/Analysis/uninit-msg-expr.m
@@ -52,5 +52,5 @@
 void f3() {
   NSMutableArray *aArray = [NSArray array];
   NSString *aString;
-  [aArray addObject:aString]; // expected-warning {{Argument in message expression is an uninitialized value}}
+  [aArray addObject:aString]; // expected-warning {{1st argument in message expression is an uninitialized value}}
 }
Index: test/Analysis/uninit-const.cpp
===
--- test/Analysis/uninit-const.cpp
+++ test/Analysis/uninit-const.cpp
@@ -66,8 +66,8 @@
   int  = t;
   int  = p;
   int  = s;  //expected-note {{'q' initialized here}}
-  doStuff6(q); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(q); //expected-warning {{1st function call argument is an uninitialized value}}
+   //expected-note@-1 {{1st function call argument is an uninitialized value}}
 }
 
 void doStuff6_3(int& q_, int *ptr_) {}
@@ -78,32 +78,32 @@
   int  = t;
   int  = p;
   int  = s;
-  doStuff6_3(q,ptr); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6_3(q,ptr); //expected-warning {{2nd function call argument is an uninitialized value}}
+   //expected-note@-1 {{2nd function call argument is an uninitialized value}}
 
 }
 
 void f6(void) {
   int k;   // expected-note {{'k' declared without an initial value}}
-  doStuff6(k); // expected-warning {{Function call argument is an uninitialized value}}
-   // expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(k); // expected-warning {{1st function call argument is an uninitialized value}}
+   // expected-note@-1 {{1st function call argument is an uninitialized value}}
 
 }
 
 
 
 void f5(void) {
   int t;
   int* tp = // expected-note {{'tp' initialized here}}
-  doStuff_uninit(tp);  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_uninit(tp);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
+   // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
 
 
 void f4(void) {
   int y;// expected-note {{'y' declared without an initial value}}
-  doStuff4(y);  // expected-warning {{Function call argument is an uninitialized value}}
-// expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff4(y);  // expected-warning {{1st function call argument is an uninitialized value}}
+// expected-note@-1 {{1st function call argument is an uninitialized value}}
 }
 
 void f3(void) {
@@ -123,6 +123,6 @@
 
 void f_uninit(void) {
   int x;
-  doStuff_uninit();  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_uninit();  

[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-02-24 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

I agree this can clarify the error message quite a bit!




Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:160
   if (ParamDecl->getType()->isPointerType()) {
-Message = "Function call argument is a pointer to uninitialized value";
+Message = "Function call argument number '" +
+  std::to_string(ArgumentNumber+1) +

Let's use llvm::getOrdinalSuffix() so that we write "1st argument" instead of 
"argument number '1'".



Comment at: lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp:211
   // Generate a report for this bug.
-  StringRef Desc =
-  describeUninitializedArgumentInCall(Call, IsFirstArgument);
+  std::string Desc =
+  describeUninitializedArgumentInCall(Call, ArgumentNumber);

Have you considered using  llvm::raw_svector_ostream here as well as passing it 
an argument to describeUninitializedArgumentInCall? For example, see  
MallocChecker.cpp.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341



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


[PATCH] D30341: [analyzer] clarify error messages about uninitialized function arguments

2017-02-24 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki created this revision.

This patch clarify the error messages about uninitialized function arguments.

It can be really hard to see the problem if there are 10-20 arguments like:

  printf("debug:", a, b.c, d, e, ...);

with no info about which argument is uninitialized and with a complicated path 
to investigate it's hard to see the bug.


Repository:
  rL LLVM

https://reviews.llvm.org/D30341

Files:
  lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/diagnostics/undef-value-param.m
  test/Analysis/malloc.m
  test/Analysis/misc-ps-region-store.m
  test/Analysis/misc-ps.m
  test/Analysis/null-deref-ps.c
  test/Analysis/nullptr.cpp
  test/Analysis/uninit-const.c
  test/Analysis/uninit-const.cpp
  test/Analysis/uninit-msg-expr.m
  test/Analysis/uninit-vals-ps.c
  test/Analysis/uninit-vals.cpp

Index: test/Analysis/uninit-vals.cpp
===
--- test/Analysis/uninit-vals.cpp
+++ test/Analysis/uninit-vals.cpp
@@ -27,7 +27,7 @@
   // case with undefined values, too.
   c1.b.a = c2->b.a;
 #else
-  c1.b.a = c2->b.a; // expected-warning{{Function call argument is an uninitialized value}}
+  c1.b.a = c2->b.a; // expected-warning{{Function call argument number '1' is an uninitialized value}}
 #endif
 }
 }
Index: test/Analysis/uninit-vals-ps.c
===
--- test/Analysis/uninit-vals-ps.c
+++ test/Analysis/uninit-vals-ps.c
@@ -14,7 +14,7 @@
 
 int f1_b() {
   int x;
-  return bar(x)+1;  // expected-warning{{Function call argument is an uninitialized value}}
+  return bar(x)+1;  // expected-warning{{Function call argument number '1' is an uninitialized value}}
 }
 
 int f2() {
Index: test/Analysis/uninit-msg-expr.m
===
--- test/Analysis/uninit-msg-expr.m
+++ test/Analysis/uninit-msg-expr.m
@@ -52,5 +52,5 @@
 void f3() {
   NSMutableArray *aArray = [NSArray array];
   NSString *aString;
-  [aArray addObject:aString]; // expected-warning {{Argument in message expression is an uninitialized value}}
+  [aArray addObject:aString]; // expected-warning {{Argument number '1' in message expression is an uninitialized value}}
 }
Index: test/Analysis/uninit-const.cpp
===
--- test/Analysis/uninit-const.cpp
+++ test/Analysis/uninit-const.cpp
@@ -66,8 +66,8 @@
   int  = t;
   int  = p;
   int  = s;  //expected-note {{'q' initialized here}}
-  doStuff6(q); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(q); //expected-warning {{Function call argument number '1' is an uninitialized value}}
+   //expected-note@-1 {{Function call argument number '1' is an uninitialized value}}
 }
 
 void doStuff6_3(int& q_, int *ptr_) {}
@@ -78,32 +78,32 @@
   int  = t;
   int  = p;
   int  = s;
-  doStuff6_3(q,ptr); //expected-warning {{Function call argument is an uninitialized value}}
-   //expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6_3(q,ptr); //expected-warning {{Function call argument number '2' is an uninitialized value}}
+   //expected-note@-1 {{Function call argument number '2' is an uninitialized value}}
 
 }
 
 void f6(void) {
   int k;   // expected-note {{'k' declared without an initial value}}
-  doStuff6(k); // expected-warning {{Function call argument is an uninitialized value}}
-   // expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff6(k); // expected-warning {{Function call argument number '1' is an uninitialized value}}
+   // expected-note@-1 {{Function call argument number '1' is an uninitialized value}}
 
 }
 
 
 
 void f5(void) {
   int t;
   int* tp = // expected-note {{'tp' initialized here}}
-  doStuff_uninit(tp);  // expected-warning {{Function call argument is a pointer to uninitialized value}}
-   // expected-note@-1 {{Function call argument is a pointer to uninitialized value}}
+  doStuff_uninit(tp);  // expected-warning {{Function call argument number '1' is a pointer to uninitialized value}}
+   // expected-note@-1 {{Function call argument number '1' is a pointer to uninitialized value}}
 }
 
 
 void f4(void) {
   int y;// expected-note {{'y' declared without an initial value}}
-  doStuff4(y);  // expected-warning {{Function call argument is an uninitialized value}}
-// expected-note@-1 {{Function call argument is an uninitialized value}}
+  doStuff4(y);  // expected-warning {{Function call argument number '1' is an uninitialized value}}
+// expected-note@-1 {{Function call argument number '1' is an uninitialized value}}
 }
 
 void f3(void) {