diff options
author | Younan Zhang <zyn7109@gmail.com> | 2023-12-05 09:59:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-05 09:59:42 +0800 |
commit | b3392c447ad7b18a652d2ed63e8ebb7741077a98 (patch) | |
tree | 83c4fbd25c5d3e6ca2b85f3ef9778d05fe56b072 /clang/lib/Sema/SemaChecking.cpp | |
parent | a8874cf50bb676facb4429234dff7774e579faef (diff) | |
download | llvm-b3392c447ad7b18a652d2ed63e8ebb7741077a98.zip llvm-b3392c447ad7b18a652d2ed63e8ebb7741077a98.tar.gz llvm-b3392c447ad7b18a652d2ed63e8ebb7741077a98.tar.bz2 |
[clang] Reject incomplete type arguments for __builtin_dump_struct (#72749)
We used to assume that the CXXRecordDecl passed to the 1st argument
always had a definition. This is not true since a pointer to an
incomplete type was not excluded.
Fixes https://github.com/llvm/llvm-project/issues/63506
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 77c8334..07ced5f 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -712,8 +712,13 @@ static ExprResult SemaBuiltinDumpStruct(Sema &S, CallExpr *TheCall) { << 1 << TheCall->getDirectCallee() << PtrArgType; return ExprError(); } - const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl(); - + QualType Pointee = PtrArgType->getPointeeType(); + const RecordDecl *RD = Pointee->getAsRecordDecl(); + // Try to instantiate the class template as appropriate; otherwise, access to + // its data() may lead to a crash. + if (S.RequireCompleteType(PtrArgResult.get()->getBeginLoc(), Pointee, + diag::err_incomplete_type)) + return ExprError(); // Second argument is a callable, but we can't fully validate it until we try // calling it. QualType FnArgType = TheCall->getArg(1)->getType(); |