Author: Haojian Wu Date: 2020-04-16T12:35:45+02:00 New Revision: 94d6dd01ba439ffcef7f7873622cf6ae99bcf5cb
URL: https://github.com/llvm/llvm-project/commit/94d6dd01ba439ffcef7f7873622cf6ae99bcf5cb DIFF: https://github.com/llvm/llvm-project/commit/94d6dd01ba439ffcef7f7873622cf6ae99bcf5cb.diff LOG: [AST] Fix an undefine behavior when creating an empty recovery expr. Summary: We forgot to initialize the NumExpr member in one of the constructors, which leads crashes in preamble serialization. Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78284 Added: clang/test/PCH/cxx-recovery-expr.cpp Modified: clang/include/clang/AST/Expr.h clang/lib/AST/Expr.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index fab84f6a6ecd..4d89234b0da7 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -6080,7 +6080,8 @@ class RecoveryExpr final : public Expr, private: RecoveryExpr(ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef<Expr *> SubExprs); - RecoveryExpr(EmptyShell Empty) : Expr(RecoveryExprClass, Empty) {} + RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs) + : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {} size_t numTrailingObjects(OverloadToken<Stmt *>) const { return NumExprs; } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index bc6fadc71609..f108b49ceac1 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -4652,7 +4652,7 @@ RecoveryExpr *RecoveryExpr::Create(ASTContext &Ctx, SourceLocation BeginLoc, RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) { void *Mem = Ctx.Allocate(totalSizeToAlloc<Expr *>(NumSubExprs), alignof(RecoveryExpr)); - return new (Mem) RecoveryExpr(EmptyShell()); + return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs); } void OMPArrayShapingExpr::setDimensions(ArrayRef<Expr *> Dims) { diff --git a/clang/test/PCH/cxx-recovery-expr.cpp b/clang/test/PCH/cxx-recovery-expr.cpp new file mode 100644 index 000000000000..e0d58c119c54 --- /dev/null +++ b/clang/test/PCH/cxx-recovery-expr.cpp @@ -0,0 +1,13 @@ +// Test with pch. +// RUN: %clang_cc1 -emit-pch -frecovery-ast -fallow-pch-with-compiler-errors -o %t %s +// RUN: %clang_cc1 -include-pch %t -fno-validate-pch -emit-llvm -o - %s + +#ifndef HEADER +#define HEADER + +int func(int); +int s = func(); + +#else + +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits