@@ -10925,6 +10925,17 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit,
10925
10925
VDecl->setInvalidDecl();
10926
10926
}
10927
10927
10928
+ if (InitListExpr *E = dyn_cast<InitListExpr>(Init)) {
10929
+ /// $TODO$ Remove dump calls.
10930
+ /// $TODO$ Handle constant string types (char array)
10931
+ //Init->dump();
10932
+ //RealDecl->is
10933
+ if (!E->handleNullTerminationCheck(RealDecl->getASTContext(), E, VDecl->getType())) {
10934
+ RealDecl->setInvalidDecl();
10935
+ return;
10936
+ }
10937
+ }
10938
+
10928
10939
// If adding the initializer will turn this declaration into a definition,
10929
10940
// and we already have a definition for this variable, diagnose or otherwise
10930
10941
// handle the situation.
@@ -11394,47 +11405,47 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
11394
11405
else if (B && !B->isInvalid() && !B->isUnknown() && !Ty->isArrayType())
11395
11406
Diag(Var->getLocation(), diag::err_initializer_expected_with_bounds)
11396
11407
<< Var;
11397
-
11398
- // An unchecked pointer in a checked scope with a bounds expression must be initialized
11399
- if (Ty->isUncheckedPointerType() && InCheckedScope && Var->hasBoundsExpr())
11400
- Diag(Var->getLocation(), diag::err_initializer_expected_for_unchecked_pointer_in_checked_scope_with_bounds_expr)
11401
- << Var;
11402
-
11403
- // An integer with a bounds expression must be initialized
11404
- if (Ty->isIntegerType() && Var->hasBoundsExpr())
11405
- Diag(Var->getLocation(), diag::err_initializer_expected_for_integer_with_bounds_expr)
11406
- << Var;
11407
-
11408
- // struct/union and array with checked pointer members must have initializers
11409
- // array with checked ptr element
11410
- if (Ty->isArrayType()) {
11411
- // if this is an array type, check the element type of the array, potentially with type qualifiers missing
11412
- if (Type::HasCheckedValue == Ty->getPointeeOrArrayElementType()->containsCheckedValue(InCheckedScope))
11413
- Diag(Var->getLocation(), diag::err_initializer_expected_for_array)
11414
- << Var;
11415
- }
11416
- // RecordType(struct/union) with checked pointer member
11417
- if (Ty->isRecordType()) {
11418
- const RecordType *RT = Ty->getAs<RecordType>();
11419
- switch (RT->containsCheckedValue(InCheckedScope)) {
11420
- default:
11421
- break;
11422
- case Type::HasCheckedValue: {
11423
- Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_checked_value)
11424
- << RT->getDecl()->getTagKind() << Var;
11425
- break;
11426
- }
11427
- case Type::HasIntWithBounds: {
11428
- Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_integer_member_with_bounds_expr)
11429
- << RT->getDecl()->getTagKind() << Var;
11430
- break;
11431
- }
11432
- case Type::HasUncheckedPointer: {
11433
- Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_unchecked_pointer_in_checked_scope)
11434
- << RT->getDecl()->getTagKind() << Var;
11435
- break;
11436
- }
11437
- }
11408
+
11409
+ // An unchecked pointer in a checked scope with a bounds expression must be initialized
11410
+ if (Ty->isUncheckedPointerType() && InCheckedScope && Var->hasBoundsExpr())
11411
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_unchecked_pointer_in_checked_scope_with_bounds_expr)
11412
+ << Var;
11413
+
11414
+ // An integer with a bounds expression must be initialized
11415
+ if (Ty->isIntegerType() && Var->hasBoundsExpr())
11416
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_integer_with_bounds_expr)
11417
+ << Var;
11418
+
11419
+ // struct/union and array with checked pointer members must have initializers
11420
+ // array with checked ptr element
11421
+ if (Ty->isArrayType()) {
11422
+ // if this is an array type, check the element type of the array, potentially with type qualifiers missing
11423
+ if (Type::HasCheckedValue == Ty->getPointeeOrArrayElementType()->containsCheckedValue(InCheckedScope))
11424
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_array)
11425
+ << Var;
11426
+ }
11427
+ // RecordType(struct/union) with checked pointer member
11428
+ if (Ty->isRecordType()) {
11429
+ const RecordType *RT = Ty->getAs<RecordType>();
11430
+ switch (RT->containsCheckedValue(InCheckedScope)) {
11431
+ default:
11432
+ break;
11433
+ case Type::HasCheckedValue: {
11434
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_checked_value)
11435
+ << RT->getDecl()->getTagKind() << Var;
11436
+ break;
11437
+ }
11438
+ case Type::HasIntWithBounds: {
11439
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_integer_member_with_bounds_expr)
11440
+ << RT->getDecl()->getTagKind() << Var;
11441
+ break;
11442
+ }
11443
+ case Type::HasUncheckedPointer: {
11444
+ Diag(Var->getLocation(), diag::err_initializer_expected_for_record_with_unchecked_pointer_in_checked_scope)
11445
+ << RT->getDecl()->getTagKind() << Var;
11446
+ break;
11447
+ }
11448
+ }
11438
11449
}
11439
11450
}
11440
11451
0 commit comments