Timm =?utf-8?q?Bäder?= <tbae...@redhat.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/80...@github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/80023 >From 58ceefe09cd992c3692bb3af7c2807ac8949ba67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 1 Feb 2024 09:11:27 +0100 Subject: [PATCH 1/2] [clang][Interp] Support ChooseExprs --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 5 +++++ clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/c.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index ca7e529041188..01555b0fc7dac 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1948,6 +1948,11 @@ bool ByteCodeExprGen<Emitter>::VisitGenericSelectionExpr( return this->delegate(E->getResultExpr()); } +template <class Emitter> +bool ByteCodeExprGen<Emitter>::VisitChooseExpr(const ChooseExpr *E) { + return this->delegate(E->getChosenSubExpr()); +} + template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 1710b4446432b..4ed5d31e343a6 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -109,6 +109,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>, bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); bool VisitSizeOfPackExpr(const SizeOfPackExpr *E); bool VisitGenericSelectionExpr(const GenericSelectionExpr *E); + bool VisitChooseExpr(const ChooseExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c index 385944d643a30..df3807b371dea 100644 --- a/clang/test/AST/Interp/c.c +++ b/clang/test/AST/Interp/c.c @@ -95,3 +95,6 @@ void f (int z) { // pedantic-ref-error {{'default' statement not in switch}} } } + +int expr; +int chooseexpr[__builtin_choose_expr(1, 1, expr)]; >From 0780dcad4cc4449bc7a58fb26669282337cdaf2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 30 Jan 2024 17:04:23 +0100 Subject: [PATCH 2/2] [clang] Fix a possible out-of-bounds read Fixes #79964 --- clang/lib/Frontend/TextDiagnostic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 291d71f6db61f..a32ed443ab2e9 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned StartLineNumber, unsigned LineLength = 0; for (unsigned I = 0; I <= Spelling.size(); ++I) { // This line is done. - if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) { + if (I == Spelling.size() || isVerticalWhitespace(Spelling.at(I))) { SmallVector<TextDiagnostic::StyleRange> &LineRanges = SnippetRanges[L - StartLineNumber]; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits