[PATCH] D115976: [clang] Fix a crash case when reporting an uninitialized field.
Michael Liao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 17 18:11:29 PST 2021
hliao updated this revision to Diff 395248.
hliao added a comment.
Revise the formatting.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115976/new/
https://reviews.llvm.org/D115976
Files:
clang/include/clang/AST/Expr.h
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/uninitialized.cpp
Index: clang/test/SemaCXX/uninitialized.cpp
===================================================================
--- clang/test/SemaCXX/uninitialized.cpp
+++ clang/test/SemaCXX/uninitialized.cpp
@@ -1472,3 +1472,20 @@
};
};
Outer<int>::Inner outerinner;
+
+namespace crash_on_report_uninitialized_field {
+struct S {
+ union {
+ struct {
+ const int &f0;
+ const float &f1; // expected-note{{uninitialized reference member is here}}
+ };
+ double d;
+ };
+};
+void bar(struct S &s);
+void foo(int i, float f) {
+ S s = {.f0 = i}; // expected-error{{reference member of type 'const float &' uninitialized}}
+ bar(s);
+}
+} // namespace crash_on_report_uninitialized_field
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -695,8 +695,7 @@
// member of reference type uninitialized, the program is
// ill-formed.
SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
- << Field->getType()
- << ILE->getSyntacticForm()->getSourceRange();
+ << Field->getType() << ILE->getSourceRange();
SemaRef.Diag(Field->getLocation(),
diag::note_uninit_reference_member);
}
Index: clang/include/clang/AST/Expr.h
===================================================================
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -4964,6 +4964,9 @@
SourceLocation getBeginLoc() const LLVM_READONLY;
SourceLocation getEndLoc() const LLVM_READONLY;
+ SourceRange getSourceRange() const LLVM_READONLY {
+ return SourceRange(getBeginLoc(), getEndLoc());
+ }
static bool classof(const Stmt *T) {
return T->getStmtClass() == InitListExprClass;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115976.395248.patch
Type: text/x-patch
Size: 1823 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211218/a510a2f3/attachment.bin>
More information about the cfe-commits
mailing list