[PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 14:03:29 PDT 2020


xbolva00 added inline comments.


================
Comment at: clang/test/Sema/string-concat.c:55
+                       "optional",
+                       "packaged_task"};
----------------
Quuxplusone wrote:
> > What if the user did actually want to concatenate the strings
> 
> > Is there a way to suppress this diagnostic
> 
> Sounds like if someone wanted to suppress the diagnostic, it would suffice for them to add a macro invocation:
> 
>     #define SUPPRESS(x) x
>     const char *test9[] = { SUPPRESS("foo" "bar"), "baz" };
> 
> Please add this test case. Please also add one for concatenation //with the result of// a macro, as in
> 
>     #define ONE(x) x
>     #define TWO "foo"
>     const char *test10[] = { ONE("foo") "bar", TWO "bar", "foo" TWO };
> 
> I would expect and hope that the diagnostic would catch all three of these cases.
> 
> It would also be nice to check a case like
> 
>     char test11[][4] = {
>         "a",
>         "b"
>         "c"
>     };
> 
> where the string literal is being used to initialize an array not a pointer.
```
#define SUPPRESS(x) x
const char *test9[] = { SUPPRESS("foo" "bar"), "baz" };
```

Added.


```
#define ONE(x) x
#define TWO "foo"
const char *test10[] = { ONE("foo") "bar", TWO "bar", "foo" TWO };
```

Only "foo" TWO is diagnosted. Other two may lead to false positives - already tested with linux kernel.


================
Comment at: clang/test/Sema/string-concat.c:55
+                       "optional",
+                       "packaged_task"};
----------------
xbolva00 wrote:
> Quuxplusone wrote:
> > > What if the user did actually want to concatenate the strings
> > 
> > > Is there a way to suppress this diagnostic
> > 
> > Sounds like if someone wanted to suppress the diagnostic, it would suffice for them to add a macro invocation:
> > 
> >     #define SUPPRESS(x) x
> >     const char *test9[] = { SUPPRESS("foo" "bar"), "baz" };
> > 
> > Please add this test case. Please also add one for concatenation //with the result of// a macro, as in
> > 
> >     #define ONE(x) x
> >     #define TWO "foo"
> >     const char *test10[] = { ONE("foo") "bar", TWO "bar", "foo" TWO };
> > 
> > I would expect and hope that the diagnostic would catch all three of these cases.
> > 
> > It would also be nice to check a case like
> > 
> >     char test11[][4] = {
> >         "a",
> >         "b"
> >         "c"
> >     };
> > 
> > where the string literal is being used to initialize an array not a pointer.
> ```
> #define SUPPRESS(x) x
> const char *test9[] = { SUPPRESS("foo" "bar"), "baz" };
> ```
> 
> Added.
> 
> 
> ```
> #define ONE(x) x
> #define TWO "foo"
> const char *test10[] = { ONE("foo") "bar", TWO "bar", "foo" TWO };
> ```
> 
> Only "foo" TWO is diagnosted. Other two may lead to false positives - already tested with linux kernel.
```
char test11[][4] = {
    "a",
    "b"
    "c"
};
```

This case is diagnosed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85545/new/

https://reviews.llvm.org/D85545



More information about the cfe-commits mailing list