1 // RUN: %clang_analyze_cc1 \
2 // RUN: -analyzer-checker=core,apiModeling.llvm.ReturnValue \
3 // RUN: -analyzer-output=text -verify=class %s
5 struct Foo
{ int Field
; };
9 // We predefined the return value of 'MCAsmParser::Error' as true and we cannot
10 // take the false-branches which leads to a "garbage value" false positive.
11 namespace test_classes
{
16 bool parseFoo(Foo
&F
) {
18 // class-note@-1 {{Assuming the condition is false}}
19 // class-note@-2 {{Taking false branch}}
20 return MCAsmParser::Error();
24 // class-note@-1 {{The value 0 is assigned to 'F.Field'}}
25 return !MCAsmParser::Error();
26 // class-note@-1 {{'MCAsmParser::Error' returns true}}
32 // class-note@-1 {{Calling 'parseFoo'}}
33 // class-note@-2 {{Returning from 'parseFoo'}}
34 // class-note@-3 {{Taking false branch}}
39 // class-note@-1 {{Field 'Field' is equal to 0}}
40 // class-note@-2 {{Taking true branch}}
42 // no-warning: "The left operand of '==' is a garbage value" was here.
47 // class-warning@-1 {{Division by zero}}
48 // class-note@-2 {{Division by zero}}
51 } // namespace test_classes
54 // We predefined 'MCAsmParser::Error' as returning true, but now it returns
55 // false, which breaks our invariant. Test the notes.
56 namespace test_break
{
59 return false; // class-note {{'MCAsmParser::Error' returns false}}
63 bool parseFoo(Foo
&F
) {
65 // class-note@-1 {{Assuming the condition is false}}
66 // class-note@-2 {{Taking false branch}}
67 return !MCAsmParser::Error();
71 // class-note@-1 {{The value 0 is assigned to 'F.Field'}}
72 return MCAsmParser::Error();
73 // class-note@-1 {{Calling 'MCAsmParser::Error'}}
74 // class-note@-2 {{Returning from 'MCAsmParser::Error'}}
80 // class-note@-1 {{Calling 'parseFoo'}}
81 // class-note@-2 {{Returning from 'parseFoo'}}
82 // class-note@-3 {{Taking false branch}}
87 // class-warning@-1 {{Division by zero}}
88 // class-note@-2 {{Division by zero}}
91 } // namespace test_classes