r183803 - Tweak r183791 so we don't print a note without a source location.

Eli Friedman eli.friedman at gmail.com
Tue Jun 11 15:26:34 PDT 2013


Author: efriedma
Date: Tue Jun 11 17:26:34 2013
New Revision: 183803

URL: http://llvm.org/viewvc/llvm-project?rev=183803&view=rev
Log:
Tweak r183791 so we don't print a note without a source location.


Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/designated-initializers.c

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=183803&r1=183802&r2=183803&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jun 11 17:26:34 2013
@@ -2102,7 +2102,7 @@ InitListChecker::CheckDesignatedInitiali
       for (unsigned i = 0, e = StrLen; i != e; ++i) {
         llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
         Expr *Init = new (Context) IntegerLiteral(
-            Context, CodeUnit, PromotedCharTy, SourceLocation());
+            Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc());
         if (CharTy != PromotedCharTy)
           Init = ImplicitCastExpr::Create(Context, CharTy, CK_IntegralCast,
                                           Init, 0, VK_RValue);
@@ -2124,7 +2124,7 @@ InitListChecker::CheckDesignatedInitiali
       for (unsigned i = 0, e = StrLen; i != e; ++i) {
         llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
         Expr *Init = new (Context) IntegerLiteral(
-            Context, CodeUnit, PromotedCharTy, SourceLocation());
+            Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc());
         if (CharTy != PromotedCharTy)
           Init = ImplicitCastExpr::Create(Context, CharTy, CK_IntegralCast,
                                           Init, 0, VK_RValue);

Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=183803&r1=183802&r2=183803&view=diff
==============================================================================
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Tue Jun 11 17:26:34 2013
@@ -277,3 +277,19 @@ struct ds ds2 = { { {
     .a = 0,
     .b = 1 // expected-error{{field designator 'b' does not refer to any field}}
 } } };
+
+// Check initializer override warnings overriding a character in a string
+struct overwrite_string_struct {
+  char L[6];
+  int M;
+} overwrite_string[] = {
+  { { "foo" }, 1 }, // expected-note {{previous initialization is here}}
+  [0].L[2] = 'x' // expected-warning{{initializer overrides prior initialization of this subobject}}
+};
+struct overwrite_string_struct2 {
+  char L[6];
+  int M;
+} overwrite_string2[] = {
+    { { "foo" }, 1 },
+    [0].L[4] = 'x' // no-warning
+  };





More information about the cfe-commits mailing list