From: David Bolvansky Date: Sat, 14 Sep 2019 19:38:55 +0000 (+0000) Subject: [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens X-Git-Tag: llvmorg-11-init~9186 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8185153f35446c2a8db48ee711d2fb577674c18;p=platform%2Fupstream%2Fllvm.git [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens llvm-svn: 371924 --- diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8452005..99e4389 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9200,6 +9200,8 @@ static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS, S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here) << LHSArgDecl; } + + S.Diag(Loc, diag::note_precedence_silence) << RHS; } } diff --git a/clang/test/Sema/div-sizeof-array.cpp b/clang/test/Sema/div-sizeof-array.cpp index 15da1da..cd9b307 100644 --- a/clang/test/Sema/div-sizeof-array.cpp +++ b/clang/test/Sema/div-sizeof-array.cpp @@ -9,21 +9,38 @@ int f(Ty (&Array)[N]) { typedef int int32; void test(void) { - int arr[12]; // expected-note 2 {{array 'arr' declared here}} + int arr[12]; // expected-note 2 {{array 'arr' declared here}} unsigned long long arr2[4]; int *p = &arr[0]; int a1 = sizeof(arr) / sizeof(*arr); int a2 = sizeof arr / sizeof p; // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'int *'}} + // expected-note@-1 {{place parentheses around the 'sizeof p' expression to silence this warning}} int a4 = sizeof arr2 / sizeof p; int a5 = sizeof(arr) / sizeof(short); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int', not 'short'}} + // expected-note@-1 {{place parentheses around the 'sizeof(short)' expression to silence this warning}} int a6 = sizeof(arr) / sizeof(int32); int a7 = sizeof(arr) / sizeof(int); int a9 = sizeof(arr) / sizeof(unsigned int); const char arr3[2] = "A"; int a10 = sizeof(arr3) / sizeof(char); + int a11 = sizeof(arr2) / (sizeof(unsigned)); + int a12 = sizeof(arr) / (sizeof(short)); int arr4[10][12]; // expected-note 3 {{array 'arr4' declared here}} int b1 = sizeof(arr4) / sizeof(arr2[12]); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'unsigned long long'}} - int b2 = sizeof(arr4) / sizeof(int *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'int *'}} - int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'short *'}} + // expected-note@-1 {{place parentheses around the 'sizeof (arr2[12])' expression to silence this warning}} + int b2 = sizeof(arr4) / sizeof(int *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'int *'}} + // expected-note@-1 {{place parentheses around the 'sizeof(int *)' expression to silence this warning}} + int b3 = sizeof(arr4) / sizeof(short *); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [12]', not 'short *'}} + // expected-note@-1 {{place parentheses around the 'sizeof(short *)' expression to silence this warning}} + + int arr5[][5] = { // expected-note 2 {{array 'arr5' declared here}} + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 0}, + }; + int c1 = sizeof(arr5) / sizeof(*arr5); + int c2 = sizeof(arr5) / sizeof(**arr5); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} + // expected-note@-1 {{place parentheses around the 'sizeof (**arr5)' expression to silence this warning}} + int c3 = sizeof(arr5) / sizeof(int); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int [5]', not 'int'}} + // expected-note@-1 {{place parentheses around the 'sizeof(int)' expression to silence this warning}} }