@@ -337,4 +337,75 @@ void test_constant_value_and_case_range(bool b)
337337 // should not be guarded by `foo() = 40..50`
338338 use (x);
339339 }
340- }
340+ }
341+
342+ void chk ();
343+
344+ bool testNotNull1 (void * input) {
345+ return input != nullptr ;
346+ }
347+
348+ bool testNotNull2 (void * input) {
349+ if (input == nullptr ) return false ;
350+ return true ;
351+ }
352+
353+ int getNumOrDefault (int * number) {
354+ return number == nullptr ? 0 : *number;
355+ }
356+
357+ char returnAIfNoneAreNull (char * s1, char * s2) {
358+ if (!s1 || !s2) return ' \0 ' ;
359+ return ' a' ;
360+ }
361+
362+ enum class Status { SUCCESS = 1 , FAILURE = 2 };
363+
364+ Status testEnumWrapper (bool flag) {
365+ return flag ? Status::SUCCESS : Status::FAILURE;
366+ }
367+
368+ void testWrappers (void * p, int * i, char * s, bool b) {
369+ if (testNotNull1 (p)) {
370+ chk (); // $ guarded='p:not null' guarded='call to testNotNull1:true'
371+ } else {
372+ chk (); // $ guarded=p:null guarded='call to testNotNull1:false'
373+ }
374+
375+ if (testNotNull2 (p)) {
376+ chk (); // $ guarded='call to testNotNull2:true' MISSING: guarded='p:not null'
377+ } else {
378+ chk (); // $ guarded='call to testNotNull2:false'
379+ }
380+
381+ if (0 == getNumOrDefault (i)) {
382+ chk (); // $ guarded='0 == call to getNumOrDefault:true' guarded='call to getNumOrDefault:0'
383+ } else {
384+ chk (); // $ guarded='0 == call to getNumOrDefault:false' guarded='call to getNumOrDefault:not 0' guarded='i:not null'
385+ }
386+
387+ if (' \0 ' == returnAIfNoneAreNull (s, " suffix" )) {
388+ chk (); // $ guarded='0 == call to returnAIfNoneAreNull:true' guarded='call to returnAIfNoneAreNull:0'
389+ } else {
390+ chk (); // $ guarded='0 == call to returnAIfNoneAreNull:false' guarded='call to returnAIfNoneAreNull:not 0' MISSING: guarded='s:not null'
391+ }
392+
393+ switch (testEnumWrapper (b)) {
394+ case Status::SUCCESS:
395+ chk (); // $ guarded='call to testEnumWrapper=SUCCESS:true' guarded='call to testEnumWrapper:1' guarded=b:true
396+ break ;
397+ case Status::FAILURE:
398+ chk (); // $ guarded='call to testEnumWrapper=FAILURE:true' guarded='call to testEnumWrapper:2' guarded=b:false
399+ break ;
400+ }
401+ }
402+
403+ void ensureNotNull (void * o) {
404+ if (!o) throw 42 ;
405+ }
406+
407+ void testExceptionWrapper (void * s) {
408+ chk (); // nothing guards here
409+ ensureNotNull (s);
410+ chk (); // $ MISSING: guarded='call to ensureNotNull:no exception' guarded='s:not null'
411+ }
0 commit comments