1
- // RUN: %clang_analyze_cc1 -verify %s\
1
+ // RUN: %clang_analyze_cc1 -w - verify %s\
2
2
// RUN: -analyzer-checker=core,unix.Malloc\
3
3
// RUN: -analyzer-checker=debug.ExprInspection -std=c++11
4
- // RUN: %clang_analyze_cc1 -verify %s\
4
+ // RUN: %clang_analyze_cc1 -w - verify %s\
5
5
// RUN: -analyzer-checker=core,unix.Malloc\
6
6
// RUN: -analyzer-checker=debug.ExprInspection -std=c++17
7
7
@@ -397,6 +397,151 @@ void u32_string() {
397
397
clang_analyzer_eval (U' \0 ' == arr[2 ]); // expected-warning{{TRUE}}
398
398
}
399
399
} // namespace CXX14_char_array_single_string_clause
400
+
401
+ namespace CXX17_designated_clauses {
402
+ struct S {
403
+ int foo;
404
+ int bar;
405
+ };
406
+ void one_designated_one_not () {
407
+ S direct{1 , .bar = 13 };
408
+ clang_analyzer_eval (1 == direct.foo ); // expected-warning{{TRUE}}
409
+ clang_analyzer_eval (13 == direct.bar ); // expected-warning{{TRUE}}
410
+
411
+ S copy = {1 , .bar = 13 };
412
+ clang_analyzer_eval (1 == copy.foo ); // expected-warning{{TRUE}}
413
+ clang_analyzer_eval (13 == copy.bar ); // expected-warning{{TRUE}}
414
+
415
+ S *ptr = new S{1 , .bar = 13 };
416
+ clang_analyzer_eval (1 == ptr->foo ); // expected-warning{{TRUE}}
417
+ clang_analyzer_eval (13 == ptr->bar ); // expected-warning{{TRUE}}
418
+ delete ptr;
419
+
420
+ S slot;
421
+ S *place = new (&slot) S{1 , .bar = 13 };
422
+ clang_analyzer_eval (1 == place->foo ); // expected-warning{{TRUE}}
423
+ clang_analyzer_eval (13 == place->bar ); // expected-warning{{TRUE}}
424
+ }
425
+ void all_designated () {
426
+ S direct{ .foo = 13 , .bar = 1 };
427
+ clang_analyzer_eval (13 == direct.foo ); // expected-warning{{TRUE}}
428
+ clang_analyzer_eval (1 == direct.bar ); // expected-warning{{TRUE}}
429
+
430
+ S copy = { .foo = 13 , .bar = 1 };
431
+ clang_analyzer_eval (13 == copy.foo ); // expected-warning{{TRUE}}
432
+ clang_analyzer_eval (1 == copy.bar ); // expected-warning{{TRUE}}
433
+
434
+ S *ptr = new S{ .foo = 13 , .bar = 1 };
435
+ clang_analyzer_eval (13 == ptr->foo ); // expected-warning{{TRUE}}
436
+ clang_analyzer_eval (1 == ptr->bar ); // expected-warning{{TRUE}}
437
+ delete ptr;
438
+
439
+ S slot;
440
+ S *place = new (&slot) S{ .foo = 13 , .bar = 1 };
441
+ clang_analyzer_eval (13 == place->foo ); // expected-warning{{TRUE}}
442
+ clang_analyzer_eval (1 == place->bar ); // expected-warning{{TRUE}}
443
+ }
444
+
445
+ class PubClass {
446
+ public:
447
+ int foo;
448
+ int bar;
449
+ };
450
+ void public_class_designated_initializers () {
451
+ PubClass direct{
452
+ .foo = 13 ,
453
+ .bar = 1 ,
454
+ };
455
+ clang_analyzer_eval (13 == direct.foo ); // expected-warning{{TRUE}}
456
+ clang_analyzer_eval (1 == direct.bar ); // expected-warning{{TRUE}}
457
+
458
+ PubClass copy = {
459
+ .foo = 13 ,
460
+ .bar = 1 ,
461
+ };
462
+ clang_analyzer_eval (13 == copy.foo ); // expected-warning{{TRUE}}
463
+ clang_analyzer_eval (1 == copy.bar ); // expected-warning{{TRUE}}
464
+
465
+ PubClass *ptr = new PubClass{
466
+ .foo = 13 ,
467
+ .bar = 1 ,
468
+ };
469
+ clang_analyzer_eval (13 == ptr->foo ); // expected-warning{{TRUE}}
470
+ clang_analyzer_eval (1 == ptr->bar ); // expected-warning{{TRUE}}
471
+ delete ptr;
472
+
473
+ PubClass slot;
474
+ PubClass *place = new (&slot) PubClass{
475
+ .foo = 13 ,
476
+ .bar = 1 ,
477
+ };
478
+ clang_analyzer_eval (13 == place->foo ); // expected-warning{{TRUE}}
479
+ clang_analyzer_eval (1 == place->bar ); // expected-warning{{TRUE}}
480
+ }
481
+
482
+ struct Three {
483
+ int x;
484
+ int y;
485
+ int z;
486
+ };
487
+ void designated_initializers_with_gaps () {
488
+ Three direct{
489
+ .x = 13 ,
490
+ .z = 1 ,
491
+ };
492
+ clang_analyzer_eval (13 == direct.x ); // expected-warning{{TRUE}}
493
+ clang_analyzer_eval (0 == direct.y ); // expected-warning{{TRUE}}
494
+ clang_analyzer_eval (1 == direct.z ); // expected-warning{{TRUE}}
495
+
496
+ Three copy = {
497
+ .x = 13 ,
498
+ .z = 1 ,
499
+ };
500
+ clang_analyzer_eval (13 == copy.x ); // expected-warning{{TRUE}}
501
+ clang_analyzer_eval (0 == copy.y ); // expected-warning{{TRUE}}
502
+ clang_analyzer_eval (1 == copy.z ); // expected-warning{{TRUE}}
503
+
504
+ Three *ptr = new Three{
505
+ .x = 13 ,
506
+ .z = 1 ,
507
+ };
508
+ clang_analyzer_eval (13 == ptr->x ); // expected-warning{{TRUE}}
509
+ clang_analyzer_eval (0 == ptr->y ); // expected-warning{{TRUE}}
510
+ clang_analyzer_eval (1 == ptr->z ); // expected-warning{{TRUE}}
511
+ delete ptr;
512
+
513
+ Three slot;
514
+ Three *place = new (&slot) Three{
515
+ .x = 13 ,
516
+ .z = 1 ,
517
+ };
518
+ clang_analyzer_eval (13 == place->x ); // expected-warning{{TRUE}}
519
+ clang_analyzer_eval (0 == place->y ); // expected-warning{{TRUE}}
520
+ clang_analyzer_eval (1 == place->z ); // expected-warning{{TRUE}}
521
+ }
522
+
523
+ struct Inner {
524
+ int bar;
525
+ };
526
+ struct Nested {
527
+ int foo;
528
+ Inner inner;
529
+ int baz;
530
+ };
531
+ void nested_aggregates () {
532
+ auto N1 = new Nested{.baz = 14 };
533
+ clang_analyzer_eval (0 == N1->foo ); // expected-warning{{TRUE}}
534
+ clang_analyzer_eval (0 == N1->inner .bar ); // expected-warning{{TRUE}}
535
+ clang_analyzer_eval (14 == N1->baz ); // expected-warning{{TRUE}}
536
+
537
+ auto N2 = new Nested{1 , {.bar = 2 }, 3 };
538
+ clang_analyzer_eval (1 == N2->foo ); // expected-warning{{TRUE}}
539
+ clang_analyzer_eval (2 == N2->inner .bar ); // expected-warning{{TRUE}}
540
+ clang_analyzer_eval (3 == N2->baz ); // expected-warning{{TRUE}}
541
+
542
+ escape (N1,N2);
543
+ }
544
+ } // namespace CXX17_designated_clauses
400
545
#endif // __cplusplus >= 201703L
401
546
402
547
// Common across different C++ versions
@@ -477,44 +622,6 @@ void none_designated_swapped() {
477
622
clang_analyzer_eval (1 == place->foo ); // expected-warning{{TRUE}}
478
623
clang_analyzer_eval (13 == place->bar ); // expected-warning{{TRUE}}
479
624
}
480
- void one_designated_one_not () {
481
- S direct{1 , .bar = 13 };
482
- clang_analyzer_eval (1 == direct.foo ); // expected-warning{{TRUE}}
483
- clang_analyzer_eval (13 == direct.bar ); // expected-warning{{TRUE}}
484
-
485
- S copy = {1 , .bar = 13 };
486
- clang_analyzer_eval (1 == copy.foo ); // expected-warning{{TRUE}}
487
- clang_analyzer_eval (13 == copy.bar ); // expected-warning{{TRUE}}
488
-
489
- S *ptr = new S{1 , .bar = 13 };
490
- clang_analyzer_eval (1 == ptr->foo ); // expected-warning{{TRUE}}
491
- clang_analyzer_eval (13 == ptr->bar ); // expected-warning{{TRUE}}
492
- delete ptr;
493
-
494
- S slot;
495
- S *place = new (&slot) S{1 , .bar = 13 };
496
- clang_analyzer_eval (1 == place->foo ); // expected-warning{{TRUE}}
497
- clang_analyzer_eval (13 == place->bar ); // expected-warning{{TRUE}}
498
- }
499
- void all_designated () {
500
- S direct{ .foo = 13 , .bar = 1 };
501
- clang_analyzer_eval (13 == direct.foo ); // expected-warning{{TRUE}}
502
- clang_analyzer_eval (1 == direct.bar ); // expected-warning{{TRUE}}
503
-
504
- S copy = { .foo = 13 , .bar = 1 };
505
- clang_analyzer_eval (13 == copy.foo ); // expected-warning{{TRUE}}
506
- clang_analyzer_eval (1 == copy.bar ); // expected-warning{{TRUE}}
507
-
508
- S *ptr = new S{ .foo = 13 , .bar = 1 };
509
- clang_analyzer_eval (13 == ptr->foo ); // expected-warning{{TRUE}}
510
- clang_analyzer_eval (1 == ptr->bar ); // expected-warning{{TRUE}}
511
- delete ptr;
512
-
513
- S slot;
514
- S *place = new (&slot) S{ .foo = 13 , .bar = 1 };
515
- clang_analyzer_eval (13 == place->foo ); // expected-warning{{TRUE}}
516
- clang_analyzer_eval (1 == place->bar ); // expected-warning{{TRUE}}
517
- }
518
625
519
626
class DefaultCtor {
520
627
public:
@@ -542,43 +649,6 @@ void const_lvalue_ref_list_init() {
542
649
clang_analyzer_eval (1 == copy.x ); // expected-warning{{TRUE}}
543
650
}
544
651
545
- class PubClass {
546
- public:
547
- int foo;
548
- int bar;
549
- };
550
- void public_class_designated_initializers () {
551
- PubClass direct{
552
- .foo = 13 ,
553
- .bar = 1 ,
554
- };
555
- clang_analyzer_eval (13 == direct.foo ); // expected-warning{{TRUE}}
556
- clang_analyzer_eval (1 == direct.bar ); // expected-warning{{TRUE}}
557
-
558
- PubClass copy = {
559
- .foo = 13 ,
560
- .bar = 1 ,
561
- };
562
- clang_analyzer_eval (13 == copy.foo ); // expected-warning{{TRUE}}
563
- clang_analyzer_eval (1 == copy.bar ); // expected-warning{{TRUE}}
564
-
565
- PubClass *ptr = new PubClass{
566
- .foo = 13 ,
567
- .bar = 1 ,
568
- };
569
- clang_analyzer_eval (13 == ptr->foo ); // expected-warning{{TRUE}}
570
- clang_analyzer_eval (1 == ptr->bar ); // expected-warning{{TRUE}}
571
- delete ptr;
572
-
573
- PubClass slot;
574
- PubClass *place = new (&slot) PubClass{
575
- .foo = 13 ,
576
- .bar = 1 ,
577
- };
578
- clang_analyzer_eval (13 == place->foo ); // expected-warning{{TRUE}}
579
- clang_analyzer_eval (1 == place->bar ); // expected-warning{{TRUE}}
580
- }
581
-
582
652
class NonAggregateImplicitDefaultCtor {
583
653
int NeverUsed = 14 ;
584
654
public:
@@ -726,41 +796,6 @@ void initializer_clauses_sequenced() {
726
796
727
797
delete ptr;
728
798
}
729
- void designated_initializers_with_gaps () {
730
- Three direct{
731
- .x = 13 ,
732
- .z = 1 ,
733
- };
734
- clang_analyzer_eval (13 == direct.x ); // expected-warning{{TRUE}}
735
- clang_analyzer_eval (0 == direct.y ); // expected-warning{{TRUE}}
736
- clang_analyzer_eval (1 == direct.z ); // expected-warning{{TRUE}}
737
-
738
- Three copy = {
739
- .x = 13 ,
740
- .z = 1 ,
741
- };
742
- clang_analyzer_eval (13 == copy.x ); // expected-warning{{TRUE}}
743
- clang_analyzer_eval (0 == copy.y ); // expected-warning{{TRUE}}
744
- clang_analyzer_eval (1 == copy.z ); // expected-warning{{TRUE}}
745
-
746
- Three *ptr = new Three{
747
- .x = 13 ,
748
- .z = 1 ,
749
- };
750
- clang_analyzer_eval (13 == ptr->x ); // expected-warning{{TRUE}}
751
- clang_analyzer_eval (0 == ptr->y ); // expected-warning{{TRUE}}
752
- clang_analyzer_eval (1 == ptr->z ); // expected-warning{{TRUE}}
753
- delete ptr;
754
-
755
- Three slot;
756
- Three *place = new (&slot) Three{
757
- .x = 13 ,
758
- .z = 1 ,
759
- };
760
- clang_analyzer_eval (13 == place->x ); // expected-warning{{TRUE}}
761
- clang_analyzer_eval (0 == place->y ); // expected-warning{{TRUE}}
762
- clang_analyzer_eval (1 == place->z ); // expected-warning{{TRUE}}
763
- }
764
799
765
800
// https://eel.is/c++draft/dcl.init.aggr#note-6:
766
801
// Static data members, non-static data members of anonymous
@@ -860,7 +895,7 @@ void array_empty_list_init_values() {
860
895
void array_empty_list_init_invalid_index_undef () {
861
896
const int *ptr = glob_arr1;
862
897
int idx = -42 ;
863
- auto x = ptr[idx]; // expected-warning{{garbage or undefined }}
898
+ auto x = ptr[idx]; // expected-warning{{uninitialized }}
864
899
}
865
900
void array_empty_list_init_symbolic_index_unknown (int idx) {
866
901
clang_analyzer_dump (glob_arr1[idx]); // expected-warning{{Unknown}}
@@ -879,12 +914,12 @@ void array_nested_empty_list_init_values() {
879
914
}
880
915
void array_nested_empty_list_init_invalid_idx_undef () {
881
916
int idx = -42 ;
882
- auto x = glob_arr4[1 ][idx]; // expected-warning{{garbage or undefined }}
917
+ auto x = glob_arr4[1 ][idx]; // expected-warning{{uninitialized }}
883
918
}
884
919
void array_nested_empty_list_init_invalid_idx_undef2 () {
885
920
const int *ptr = glob_arr4[1 ];
886
921
int idx = -42 ;
887
- auto x = ptr[idx]; // expected-warning{{garbage or undefined }}
922
+ auto x = ptr[idx]; // expected-warning{{uninitialized }}
888
923
}
889
924
890
925
int const glob_arr2[4 ] = {1 , 2 };
@@ -898,7 +933,7 @@ void array_fewer_init_clauses_values() {
898
933
void array_fewer_init_clauses_values_invalid_index () {
899
934
const int *ptr = glob_arr2;
900
935
int idx = 42 ;
901
- auto x = ptr[idx]; // expected-warning{{garbage or undefined }}
936
+ auto x = ptr[idx]; // expected-warning{{uninitialized }}
902
937
}
903
938
904
939
int const glob_arr5[4 ][2 ] = {{1 }, 3 , 4 , 5 };
@@ -920,12 +955,12 @@ void array_nested_init_list_oob_read() {
920
955
}
921
956
void array_nested_init_list_invalid_index () {
922
957
int idx = -42 ;
923
- auto x = glob_arr5[1 ][idx]; // expected-warning{{garbage or undefined }}
958
+ auto x = glob_arr5[1 ][idx]; // expected-warning{{uninitialized }}
924
959
}
925
960
void array_nested_init_list_invalid_index2 () {
926
961
int const *ptr = &glob_arr5[1 ][0 ];
927
962
int idx = 42 ;
928
- auto x = ptr[idx]; // expected-warning{{garbage or undefined }}
963
+ auto x = ptr[idx]; // expected-warning{{uninitialized }}
929
964
}
930
965
931
966
char const char_string_init[5 ] = {" 123" };
@@ -938,12 +973,12 @@ void array_char_init_with_char_string() {
938
973
}
939
974
void array_char_init_with_char_string_invalid_index () {
940
975
int idx = -42 ;
941
- auto x = char_string_init[idx]; // expected-warning{{garbage or undefined }}
976
+ auto x = char_string_init[idx]; // expected-warning{{uninitialized }}
942
977
}
943
978
void array_char_init_with_char_string_invalid_index2 () {
944
979
const char *ptr = char_string_init;
945
980
int idx = 42 ;
946
- auto x = ptr[idx]; // expected-warning{{garbage or undefined }}
981
+ auto x = ptr[idx]; // expected-warning{{uninitialized }}
947
982
}
948
983
949
984
const int glob_arr9[2 ][4 ] = {{(1 ), 2 , ((3 )), 4 }, 5 , 6 , (((7 )))};
@@ -1149,10 +1184,11 @@ void union_single_initializer_clause_first_field() {
1149
1184
clang_analyzer_eval (1 == ptr->x ); // expected-warning{{UNKNOWN}}
1150
1185
clang_analyzer_eval (1 == place->x ); // expected-warning{{UNKNOWN}}
1151
1186
1152
- clang_analyzer_eval (1 + direct.y ); // expected-warning{{UNDEFINED}}
1153
- clang_analyzer_eval (1 + copy.y ); // expected-warning{{UNDEFINED}}
1154
- clang_analyzer_eval (1 + ptr->y ); // expected-warning{{UNDEFINED}}
1155
- clang_analyzer_eval (1 + place->y ); // expected-warning{{UNDEFINED}}
1187
+ // FIXME: should be undefined
1188
+ clang_analyzer_eval (1 + direct.y ); // expected-warning{{UNKNOWN}}
1189
+ clang_analyzer_eval (1 + copy.y ); // expected-warning{{UNKNOWN}}
1190
+ clang_analyzer_eval (1 + ptr->y ); // expected-warning{{UNKNOWN}}
1191
+ clang_analyzer_eval (1 + place->y ); // expected-warning{{UNKNOWN}}
1156
1192
1157
1193
delete ptr;
1158
1194
}
@@ -1169,10 +1205,11 @@ void union_single_initializer_clause_non_first_field() {
1169
1205
clang_analyzer_eval (1 == ptr->y ); // expected-warning{{UNKNOWN}}
1170
1206
clang_analyzer_eval (1 == place->y ); // expected-warning{{UNKNOWN}}
1171
1207
1172
- clang_analyzer_eval (1 + direct.x ); // expected-warning{{UNDEFINED}}
1173
- clang_analyzer_eval (1 + copy.x ); // expected-warning{{UNDEFINED}}
1174
- clang_analyzer_eval (1 + ptr->x ); // expected-warning{{UNDEFINED}}
1175
- clang_analyzer_eval (1 + place->x ); // expected-warning{{UNDEFINED}}
1208
+ // FIXME: should be undefined
1209
+ clang_analyzer_eval (1 + direct.x ); // expected-warning{{UNKNOWN}}
1210
+ clang_analyzer_eval (1 + copy.x ); // expected-warning{{UNKNOWN}}
1211
+ clang_analyzer_eval (1 + ptr->x ); // expected-warning{{UNKNOWN}}
1212
+ clang_analyzer_eval (1 + place->x ); // expected-warning{{UNKNOWN}}
1176
1213
1177
1214
delete ptr;
1178
1215
}
0 commit comments