Do not automatically report self references of structs in statement expression
as warnings. Instead wait for uninitialized cfg analysis.
https://bugs.llvm.org/show_bug.cgi?id=42604
Details
- Reviewers
- aaron.ballman - rsmith - nickdesaulniers 
- Commits
- rGd1b122cbdf22: Merging r367134: --------------------------------------------------------------…
 rL367150: Merging r367134:
 rG2e040398f8d6: [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression
 rL367134: [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression
 rC367134: [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression
Diff Detail
- Repository
- rG LLVM Github Monorepo
- Build Status
- Buildable 34925 - Build 34924: arc lint + arc unit 
Event Timeline
Thanks for the patch. Minor nits looking for test cases that should have no warning (like the two examples provided in the bug).
| clang/test/Sema/warn-uninitialized-statement-expression.c | ||
|---|---|---|
| 8 | Can you please add a case like foo without z in it (so that no warnings are expected, as in pr42604)? (You can keep both test cases, just looking for 1 more, as the first case). | |
| 21 | Ditto about adding a clear case that should not warn. | |
| 22 | This needs a trailing comment like: int x = my_widget.x; // fixme: we should probably warn about this case and file a bug about it. Doesn't need to be solved here. | |
| clang/lib/Sema/SemaDecl.cpp | ||
|---|---|---|
| 10890 | Should just be dyn_cast<StmtExpr>(E)? | |
| clang/test/Sema/warn-uninitialized-statement-expression.c | ||
| 36 | Can you please file a bug pointing to this test case? | |
| clang/test/Sema/warn-uninitialized-statement-expression.c | ||
|---|---|---|
| 22 | ||
I don't think this problem really has anything to do with statement expressions; consider:
struct Widget a = (init2(&a), a);
... which has the same behaviour and presumably produces the same warning.
It's just a C / C++ difference. In C++, these examples are undefined because the lifetime of the object hasn't started yet, but I think in C they're valid. We should just disable the whole warning in C mode and leave it to the CFG analysis.
LGTM aside from a comment request.
| clang/lib/Sema/SemaDecl.cpp | ||
|---|---|---|
| 11264 | This should probably have a comment explaining why we only do it in C++ mode. | |
Should just be dyn_cast<StmtExpr>(E)?
http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates