[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112081 >From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 12 Oct 2024 08:27:51 +0300 Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw expressions --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaChecking.cpp | 3 +++ clang/test/SemaCXX/conditional-expr.cpp | 7 +++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 337e3fc10bf49d..2ab13640bfa53c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -512,6 +512,7 @@ Bug Fixes to C++ Support and undeclared templates. (#GH107047, #GH49093) - Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded parameter pack. (#GH109148) +- Fixed assertion failure in range calculations for conditional throw expressions (#GH111854) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2bcb930acdcb57..b3d88f053872c1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, return IntRange(BitField->getBitWidthValue(C), BitField->getType()->isUnsignedIntegerOrEnumerationType()); + if (GetExprType(E)->isVoidType()) +return IntRange{0, true}; + return IntRange::forValueOfType(C, GetExprType(E)); } diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 01effaa189322b..8f17555fd806ff 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -429,3 +429,10 @@ void g() { long e = a = b ? throw 0 : throw 1; } } // namespace PR46484 + +namespace GH111854 { +void f() { + (true ? throw 0 : 0) <= 0; // expected-warning {{relational comparison result unused}} + (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison result unused}} +} +} >From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 19 Oct 2024 00:00:19 +0300 Subject: [PATCH 2/2] change return type to nullable for handling invalid ranges in integer expression evaluation --- clang/lib/Sema/SemaChecking.cpp | 198 +++- 1 file changed, 118 insertions(+), 80 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b3d88f053872c1..2ca342a6065550 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) { ///particular, assume that arithmetic on narrower types doesn't leave ///those types. If \c false, return a range including all possible ///result values. -static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, - bool InConstantContext, bool Approximate) { +static std::optional TryGetExprRange(ASTContext &C, const Expr *E, + unsigned MaxWidth, + bool InConstantContext, + bool Approximate) { E = E->IgnoreParens(); // Try a full evaluation first. @@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, // being of the new, wider type. if (const auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue) - return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, - Approximate); + return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, + Approximate); IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE)); @@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, if (!isIntegerCast) return OutputTypeRange; -IntRange SubRange = GetExprRange(C, CE->getSubExpr(), - std::min(MaxWidth, OutputTypeRange.Width), - InConstantContext, Approximate); +std::optional SubRange = TryGetExprRange( +C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width), +InConstantContext, Approximate); +if (!SubRange) + return std::nullopt; // Bail out if the subexpr's range is as wide as the cast type. -if (SubRange.Width >= OutputTypeRange.Width) +if (SubRange->Width >= OutputTypeRange.Width) return OutputTypeRange; // Otherwise, we take the smaller width, and we're non-negative if // either the output type or the subexpr is. -
[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112424 >From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 15 Oct 2024 22:43:24 +0300 Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier for missing primary declarations --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAccess.cpp | 3 ++- clang/test/SemaCXX/enum.cpp | 8 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 817e3abef8d566..64ffdcde045a3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,6 +517,8 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) +- Fixed an assertion failure when the default lexical access specifier was set for missing + primary declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index df6edb21a50dee..8b4a5b70669d84 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -MemberDecl->setAccess(LexicalAS); +if (LexicalAS != AS_none) + MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da886c..44042d8bf5cfc8 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ +// expected-error {{unexpected ';' before ')'}} +}; +} >From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 18 Oct 2024 14:55:47 +0300 Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum forward declarations --- clang/docs/ReleaseNotes.rst | 3 +-- clang/lib/Sema/SemaAccess.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64ffdcde045a3a..3fd37663ca7bc6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,8 +517,7 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) -- Fixed an assertion failure when the default lexical access specifier was set for missing - primary declarations. (#GH112208) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 8b4a5b70669d84..df6edb21a50dee 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -if (LexicalAS != AS_none) - MemberDecl->setAccess(LexicalAS); +MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fece22c663d00c..9eb3d06289e88f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration && Name) +Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in fma function. (PR #113020)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/113020 >From 93c625ad60fc834e72df667addc6eec83247fc8c Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 19 Oct 2024 03:45:17 + Subject: [PATCH 1/2] constexpr fma --- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/Basic/Builtins.td | 1 + clang/lib/AST/ByteCode/InterpBuiltin.cpp | 37 +++ clang/lib/AST/ExprConstant.cpp| 16 clang/test/AST/ByteCode/builtin-functions.cpp | 9 + clang/test/Sema/constant-builtins-2.c | 7 6 files changed, 71 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7a6ace8bb895d..605d55a9e51f37 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -273,6 +273,7 @@ Non-comprehensive list of changes in this release - Plugins can now define custom attributes that apply to statements as well as declarations. - ``__builtin_abs`` function can now be used in constant expressions. +- ``__builtin_fma`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 90475a361bb8f8..55f470a9f715b9 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -3723,6 +3723,7 @@ def Fma : FPMathTemplate, LibBuiltin<"math.h"> { let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions]; let Prototype = "T(T, T, T)"; let AddBuiltinPrefixedAlias = 1; + let OnlyBuiltinPrefixedAliasIsConstexpr = 1; } def Fmax : FPMathTemplate, LibBuiltin<"math.h"> { diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index d4a8e6c2035ee5..145f4627dd73da 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -142,6 +142,19 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result, #undef RET_CASE } +/// Get rounding mode to use in evaluation of the specified expression. +/// +/// If rounding mode is unknown at compile time, still try to evaluate the +/// expression. If the result is exact, it does not depend on rounding mode. +/// So return "tonearest" mode instead of "dynamic". +static llvm::RoundingMode getActiveRoundingMode(InterpState &S, const Expr *E) { + llvm::RoundingMode RM = + E->getFPFeaturesInEffect(S.getLangOpts()).getRoundingMode(); + if (RM == llvm::RoundingMode::Dynamic) +RM = llvm::RoundingMode::NearestTiesToEven; + return RM; +} + static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC, const InterpFrame *Frame, const CallExpr *Call) { @@ -549,6 +562,22 @@ static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC, return true; } +static bool interp__builtin_fma(InterpState &S, CodePtr OpPC, +const InterpFrame *Frame, const Function *Func, +const CallExpr *Call) { + const Floating &X = getParam(Frame, 0); + const Floating &Y = getParam(Frame, 1); + const Floating &Z = getParam(Frame, 2); + Floating Result; + + llvm::RoundingMode RM = getActiveRoundingMode(S, Call); + Floating::mul(X, Y, RM, &Result); + Floating::add(Result, Z, RM, &Result); + + S.Stk.push(Result); + return true; +} + // The C standard says "fabs raises no floating-point exceptions, // even if x is a signaling NaN. The returned value is independent of // the current rounding direction mode." Therefore constant folding can @@ -1814,6 +1843,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, return false; break; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: +if (!interp__builtin_fma(S, OpPC, Frame, F, Call)) + return false; +break; + case Builtin::BI__builtin_fabs: case Builtin::BI__builtin_fabsf: case Builtin::BI__builtin_fabsl: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 8e36cad2d2c6e7..685ce8a63f6c9e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { Result.changeSign(); return true; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: { +APFloat Y(0.), Z(0.); +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluateFloat(E->getArg(1), Y, Info) || +!EvaluateFloat(E->getArg(2), Z, Info)) + return false; + +llvm::RoundingMode RM = getActiveRoundingMode(Info, E); +Result.multiply(Y, RM); +Result.add(Z, RM); +return true;
[clang] [clang] constexpr built-in fma function. (PR #113020)
@@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { Result.changeSign(); return true; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: { +APFloat Y(0.), Z(0.); +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluateFloat(E->getArg(1), Y, Info) || +!EvaluateFloat(E->getArg(2), Z, Info)) + return false; + +llvm::RoundingMode RM = getActiveRoundingMode(Info, E); +Result.multiply(Y, RM); +Result.add(Z, RM); c8ef wrote: Done. Thanks for pointing it out! https://github.com/llvm/llvm-project/pull/113020 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/112612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)
@@ -11536,6 +11536,9 @@ bool ArrayExprEvaluator::VisitCXXParenListOrInitListExpr( LValue Subobject = This; Subobject.addArray(Info, ExprToVisit, CAT); auto Eval = [&](const Expr *Init, unsigned ArrayIndex) { +if (Init->isValueDependent()) a-tarasyuk wrote: @shafik Thanks for the feedback. I've updated the PR summary. https://github.com/llvm/llvm-project/pull/112612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112081 >From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 12 Oct 2024 08:27:51 +0300 Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw expressions --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaChecking.cpp | 3 +++ clang/test/SemaCXX/conditional-expr.cpp | 7 +++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 337e3fc10bf49d..2ab13640bfa53c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -512,6 +512,7 @@ Bug Fixes to C++ Support and undeclared templates. (#GH107047, #GH49093) - Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded parameter pack. (#GH109148) +- Fixed assertion failure in range calculations for conditional throw expressions (#GH111854) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2bcb930acdcb57..b3d88f053872c1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, return IntRange(BitField->getBitWidthValue(C), BitField->getType()->isUnsignedIntegerOrEnumerationType()); + if (GetExprType(E)->isVoidType()) +return IntRange{0, true}; + return IntRange::forValueOfType(C, GetExprType(E)); } diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 01effaa189322b..8f17555fd806ff 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -429,3 +429,10 @@ void g() { long e = a = b ? throw 0 : throw 1; } } // namespace PR46484 + +namespace GH111854 { +void f() { + (true ? throw 0 : 0) <= 0; // expected-warning {{relational comparison result unused}} + (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison result unused}} +} +} >From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 19 Oct 2024 00:00:19 +0300 Subject: [PATCH 2/2] change return type to nullable for handling invalid ranges in integer expression evaluation --- clang/lib/Sema/SemaChecking.cpp | 198 +++- 1 file changed, 118 insertions(+), 80 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b3d88f053872c1..2ca342a6065550 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) { ///particular, assume that arithmetic on narrower types doesn't leave ///those types. If \c false, return a range including all possible ///result values. -static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, - bool InConstantContext, bool Approximate) { +static std::optional TryGetExprRange(ASTContext &C, const Expr *E, + unsigned MaxWidth, + bool InConstantContext, + bool Approximate) { E = E->IgnoreParens(); // Try a full evaluation first. @@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, // being of the new, wider type. if (const auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue) - return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, - Approximate); + return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, + Approximate); IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE)); @@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, if (!isIntegerCast) return OutputTypeRange; -IntRange SubRange = GetExprRange(C, CE->getSubExpr(), - std::min(MaxWidth, OutputTypeRange.Width), - InConstantContext, Approximate); +std::optional SubRange = TryGetExprRange( +C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width), +InConstantContext, Approximate); +if (!SubRange) + return std::nullopt; // Bail out if the subexpr's range is as wide as the cast type. -if (SubRange.Width >= OutputTypeRange.Width) +if (SubRange->Width >= OutputTypeRange.Width) return OutputTypeRange; // Otherwise, we take the smaller width, and we're non-negative if // either the output type or the subexpr is. -
[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112424 >From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 15 Oct 2024 22:43:24 +0300 Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier for missing primary declarations --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAccess.cpp | 3 ++- clang/test/SemaCXX/enum.cpp | 8 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 817e3abef8d566..64ffdcde045a3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,6 +517,8 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) +- Fixed an assertion failure when the default lexical access specifier was set for missing + primary declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index df6edb21a50dee..8b4a5b70669d84 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -MemberDecl->setAccess(LexicalAS); +if (LexicalAS != AS_none) + MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da886c..44042d8bf5cfc8 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ +// expected-error {{unexpected ';' before ')'}} +}; +} >From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 18 Oct 2024 14:55:47 +0300 Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum forward declarations --- clang/docs/ReleaseNotes.rst | 3 +-- clang/lib/Sema/SemaAccess.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64ffdcde045a3a..3fd37663ca7bc6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,8 +517,7 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) -- Fixed an assertion failure when the default lexical access specifier was set for missing - primary declarations. (#GH112208) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 8b4a5b70669d84..df6edb21a50dee 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -if (LexicalAS != AS_none) - MemberDecl->setAccess(LexicalAS); +MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fece22c663d00c..9eb3d06289e88f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration && Name) +Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
https://github.com/torshepherd updated https://github.com/llvm/llvm-project/pull/95712 >From ee08d8cc7760fe39637260408aec2b1e6ab30d0a Mon Sep 17 00:00:00 2001 From: Tor Shepherd Date: Mon, 23 Sep 2024 23:12:23 -0400 Subject: [PATCH 1/7] just defaults --- clang-tools-extra/clangd/Config.h | 1 + clang-tools-extra/clangd/ConfigCompile.cpp| 6 +- clang-tools-extra/clangd/ConfigFragment.h | 3 + clang-tools-extra/clangd/ConfigYAML.cpp | 5 +- clang-tools-extra/clangd/InlayHints.cpp | 61 ++- clang-tools-extra/clangd/Protocol.cpp | 3 + clang-tools-extra/clangd/Protocol.h | 9 +++ .../clangd/unittests/InlayHintTests.cpp | 29 + 8 files changed, 112 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h index 8fcbc5c33469fa..e174f7fabe344e 100644 --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -162,6 +162,7 @@ struct Config { bool DeducedTypes = true; bool Designators = true; bool BlockEnd = false; +bool DefaultArguments = false; // Limit the length of type names in inlay hints. (0 means no limit) uint32_t TypeNameLimit = 32; } InlayHints; diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index 58610a5b87922d..fb7692998d05c7 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -43,7 +43,6 @@ #include "llvm/Support/Regex.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" -#include #include #include #include @@ -669,6 +668,11 @@ struct FragmentCompiler { Out.Apply.push_back([Value(**F.BlockEnd)](const Params &, Config &C) { C.InlayHints.BlockEnd = Value; }); +if (F.DefaultArguments) + Out.Apply.push_back( + [Value(**F.DefaultArguments)](const Params &, Config &C) { +C.InlayHints.DefaultArguments = Value; + }); if (F.TypeNameLimit) Out.Apply.push_back( [Value(**F.TypeNameLimit)](const Params &, Config &C) { diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h index fc1b45f5d4c3e9..36f7d04231c414 100644 --- a/clang-tools-extra/clangd/ConfigFragment.h +++ b/clang-tools-extra/clangd/ConfigFragment.h @@ -339,6 +339,9 @@ struct Fragment { std::optional> Designators; /// Show defined symbol names at the end of a definition block. std::optional> BlockEnd; +/// Show parameter names and default values of default arguments after all +/// of the explicit arguments. +std::optional> DefaultArguments; /// Limit the length of type name hints. (0 means no limit) std::optional> TypeNameLimit; }; diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp index bcdda99eeed67a..32e028981d4244 100644 --- a/clang-tools-extra/clangd/ConfigYAML.cpp +++ b/clang-tools-extra/clangd/ConfigYAML.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/YAMLParser.h" #include #include -#include namespace clang { namespace clangd { @@ -268,6 +267,10 @@ class Parser { if (auto Value = boolValue(N, "BlockEnd")) F.BlockEnd = *Value; }); +Dict.handle("DefaultArguments", [&](Node &N) { + if (auto Value = boolValue(N, "DefaultArguments")) +F.DefaultArguments = *Value; +}); Dict.handle("TypeNameLimit", [&](Node &N) { if (auto Value = uint32Value(N, "TypeNameLimit")) F.TypeNameLimit = *Value; diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index cd4f1931b3ce1d..72fa92a81ce800 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -11,9 +11,11 @@ #include "Config.h" #include "HeuristicResolver.h" #include "ParsedAST.h" +#include "Protocol.h" #include "SourceCode.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -23,15 +25,22 @@ #include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" +#include +#include #include #include @@ -372,6 +381,25 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) { return Params; } +template
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
https://github.com/torshepherd updated https://github.com/llvm/llvm-project/pull/95712 >From 2c9e7c16524b7ce3bf818e451279722dc45d3efc Mon Sep 17 00:00:00 2001 From: Tor Shepherd Date: Mon, 23 Sep 2024 23:12:23 -0400 Subject: [PATCH 1/6] just defaults --- clang-tools-extra/clangd/Config.h | 1 + clang-tools-extra/clangd/ConfigCompile.cpp| 6 +- clang-tools-extra/clangd/ConfigFragment.h | 3 + clang-tools-extra/clangd/ConfigYAML.cpp | 5 +- clang-tools-extra/clangd/InlayHints.cpp | 61 ++- clang-tools-extra/clangd/Protocol.cpp | 3 + clang-tools-extra/clangd/Protocol.h | 9 +++ .../clangd/unittests/InlayHintTests.cpp | 29 + 8 files changed, 112 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h index 41143b9ebc8d27..6fb846aa99437f 100644 --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -148,6 +148,7 @@ struct Config { bool DeducedTypes = true; bool Designators = true; bool BlockEnd = false; +bool DefaultArguments = false; // Limit the length of type names in inlay hints. (0 means no limit) uint32_t TypeNameLimit = 32; } InlayHints; diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index f32f674443ffeb..81bc68e4e93d89 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -43,7 +43,6 @@ #include "llvm/Support/Regex.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" -#include #include #include #include @@ -654,6 +653,11 @@ struct FragmentCompiler { Out.Apply.push_back([Value(**F.BlockEnd)](const Params &, Config &C) { C.InlayHints.BlockEnd = Value; }); +if (F.DefaultArguments) + Out.Apply.push_back( + [Value(**F.DefaultArguments)](const Params &, Config &C) { +C.InlayHints.DefaultArguments = Value; + }); if (F.TypeNameLimit) Out.Apply.push_back( [Value(**F.TypeNameLimit)](const Params &, Config &C) { diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h index f3e51a9b6dbc4b..3a591e3062e355 100644 --- a/clang-tools-extra/clangd/ConfigFragment.h +++ b/clang-tools-extra/clangd/ConfigFragment.h @@ -331,6 +331,9 @@ struct Fragment { std::optional> Designators; /// Show defined symbol names at the end of a definition block. std::optional> BlockEnd; +/// Show parameter names and default values of default arguments after all +/// of the explicit arguments. +std::optional> DefaultArguments; /// Limit the length of type name hints. (0 means no limit) std::optional> TypeNameLimit; }; diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp index 3e9b6a07d3b325..ed90e6d648b1c2 100644 --- a/clang-tools-extra/clangd/ConfigYAML.cpp +++ b/clang-tools-extra/clangd/ConfigYAML.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/YAMLParser.h" #include #include -#include namespace clang { namespace clangd { @@ -264,6 +263,10 @@ class Parser { if (auto Value = boolValue(N, "BlockEnd")) F.BlockEnd = *Value; }); +Dict.handle("DefaultArguments", [&](Node &N) { + if (auto Value = boolValue(N, "DefaultArguments")) +F.DefaultArguments = *Value; +}); Dict.handle("TypeNameLimit", [&](Node &N) { if (auto Value = uint32Value(N, "TypeNameLimit")) F.TypeNameLimit = *Value; diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index cd4f1931b3ce1d..72fa92a81ce800 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -11,9 +11,11 @@ #include "Config.h" #include "HeuristicResolver.h" #include "ParsedAST.h" +#include "Protocol.h" #include "SourceCode.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -23,15 +25,22 @@ #include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" +#include +#include #include #include @@ -372,6 +381,25 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) { return Params; } +template
[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)
https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/113049 Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions. If my thinking is wrong, I apologize, and IIUC seems it's caused by 5ae5774fb0b5cac11af479b0905dfdd5255b4047. >From 57293112bb238ae6ac1d0dea9dafba72fa5e9fed Mon Sep 17 00:00:00 2001 From: yronglin Date: Sun, 20 Oct 2024 00:12:00 +0800 Subject: [PATCH] [clang] Fix a crash issue that caused by handling of of fields with initializers in nested anonymous unions Signed-off-by: yronglin --- clang/lib/Sema/SemaInit.cpp | 15 ++- .../test/SemaCXX/cxx1y-initializer-aggregates.cpp | 11 +++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index f560865681fa5a..4878dcb5d2c8e0 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -868,13 +868,19 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity, if (const RecordType *RType = ILE->getType()->getAs()) { const RecordDecl *RDecl = RType->getDecl(); -if (RDecl->isUnion() && ILE->getInitializedFieldInUnion()) { +if (RDecl->isUnion() && ILE->getInitializedFieldInUnion()) FillInEmptyInitForField(0, ILE->getInitializedFieldInUnion(), Entity, ILE, RequiresSecondPass, FillWithNoInit); +else if (RDecl->isUnion() && isa(RDecl) && + cast(RDecl)->hasInClassInitializer()) { + for (auto *Field : RDecl->fields()) { +if (Field->hasInClassInitializer()) { + FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass, + FillWithNoInit); + break; +} + } } else { - assert((!RDecl->isUnion() || !isa(RDecl) || - !cast(RDecl)->hasInClassInitializer()) && - "We should have computed initialized fields already"); // The fields beyond ILE->getNumInits() are default initialized, so in // order to leave them uninitialized, the ILE is expanded and the extra // fields are then filled with NoInitExpr. @@ -2296,7 +2302,6 @@ void InitListChecker::CheckStructUnionTypes( return; } } - llvm_unreachable("Couldn't find in-class initializer"); } // Value-initialize the first member of the union that isn't an unnamed diff --git a/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp b/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp index 03a6800898d18f..8360b8fd7d8ee2 100644 --- a/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp +++ b/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp @@ -115,3 +115,14 @@ namespace nested_union { // of Test3, or we should exclude f(Test3) as a candidate. static_assert(f({1}) == 2, ""); // expected-error {{call to 'f' is ambiguous}} } + +// Fix crash issue https://github.com/llvm/llvm-project/issues/112560. +// Make sure clang compiles the following code without crashing: +namespace GH112560 { +union U { + int f = ; // expected-error {{expected expression}} +}; +void foo() { + U g{}; +} +} // namespace GH112560 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (yronglin) Changes Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions. If my thinking is wrong, I apologize, and IIUC seems it's caused by 5ae5774fb0b5cac11af479b0905dfdd5255b4047. --- Full diff: https://github.com/llvm/llvm-project/pull/113049.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaInit.cpp (+10-5) - (modified) clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp (+11) ``diff diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index f560865681fa5a..4878dcb5d2c8e0 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -868,13 +868,19 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity, if (const RecordType *RType = ILE->getType()->getAs()) { const RecordDecl *RDecl = RType->getDecl(); -if (RDecl->isUnion() && ILE->getInitializedFieldInUnion()) { +if (RDecl->isUnion() && ILE->getInitializedFieldInUnion()) FillInEmptyInitForField(0, ILE->getInitializedFieldInUnion(), Entity, ILE, RequiresSecondPass, FillWithNoInit); +else if (RDecl->isUnion() && isa(RDecl) && + cast(RDecl)->hasInClassInitializer()) { + for (auto *Field : RDecl->fields()) { +if (Field->hasInClassInitializer()) { + FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass, + FillWithNoInit); + break; +} + } } else { - assert((!RDecl->isUnion() || !isa(RDecl) || - !cast(RDecl)->hasInClassInitializer()) && - "We should have computed initialized fields already"); // The fields beyond ILE->getNumInits() are default initialized, so in // order to leave them uninitialized, the ILE is expanded and the extra // fields are then filled with NoInitExpr. @@ -2296,7 +2302,6 @@ void InitListChecker::CheckStructUnionTypes( return; } } - llvm_unreachable("Couldn't find in-class initializer"); } // Value-initialize the first member of the union that isn't an unnamed diff --git a/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp b/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp index 03a6800898d18f..8360b8fd7d8ee2 100644 --- a/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp +++ b/clang/test/SemaCXX/cxx1y-initializer-aggregates.cpp @@ -115,3 +115,14 @@ namespace nested_union { // of Test3, or we should exclude f(Test3) as a candidate. static_assert(f({1}) == 2, ""); // expected-error {{call to 'f' is ambiguous}} } + +// Fix crash issue https://github.com/llvm/llvm-project/issues/112560. +// Make sure clang compiles the following code without crashing: +namespace GH112560 { +union U { + int f = ; // expected-error {{expected expression}} +}; +void foo() { + U g{}; +} +} // namespace GH112560 `` https://github.com/llvm/llvm-project/pull/113049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make LazyOffsetPtr more portable (PR #112927)
zygoloid wrote: > Doesn't it change ABI, though? Only on platforms where it didn't work at all before. https://github.com/llvm/llvm-project/pull/112927 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
torshepherd wrote: Accepted the comment and added relnotes. Lmk if you need anything else prior to merge https://github.com/llvm/llvm-project/pull/95712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112816 >From 6b85331c4927c031fb8a937467cf62c5d0f80e64 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 05:03:22 +0200 Subject: [PATCH 1/5] [NFC][Clang] Fix enumerated mismatch warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix warning: llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::’ vs ‘clang::diag::’ [-Werror=enum-compare] 3152 | DS.isFriendSpecified() || NextToken().is(tok::kw_friend) | 3153 | ? diag::err_friend_concept | ^~ 3154 | : diag:: | 3155 | err_concept_decls_may_only_appear_in_global_namespace_scope); --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 78510e61a639fa..cb52629f9c61c7 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,9 +983,6 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; -def err_friend_concept : Error< - "friend declaration cannot be a concept">; - // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 883db838ca0147..d102a45f8c1ed2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,6 +3020,8 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts +def err_friend_concept : Error< + "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< >From 1733184c9a6fa8a375dec2c10f5456cfb86e9a57 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 14:58:27 +0200 Subject: [PATCH 2/5] cast instead --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 +++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 -- clang/lib/Parse/ParseDeclCXX.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index cb52629f9c61c7..78510e61a639fa 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,6 +983,9 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; +def err_friend_concept : Error< + "friend declaration cannot be a concept">; + // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d102a45f8c1ed2..883db838ca0147 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,8 +3020,6 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts -def err_friend_concept : Error< - "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6f0f5a0311bc18..fb159eb997ce9d 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -3150,8 +3150,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( if (Tok.is(tok::kw_concept)) { Diag(Tok.getLocation(), DS.isFriendSpecified() || NextToken().is(tok::kw_friend) - ? diag::err_friend_concept - : diag:: + ? (unsigned)diag::err_friend_concept + : (unsigned)diag:: err_concept_decls_may_only_appear_in_global_namespace_scope); SkipUntil(tok::semi, tok::r
[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112816 >From 6b85331c4927c031fb8a937467cf62c5d0f80e64 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 05:03:22 +0200 Subject: [PATCH 1/6] [NFC][Clang] Fix enumerated mismatch warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix warning: llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::’ vs ‘clang::diag::’ [-Werror=enum-compare] 3152 | DS.isFriendSpecified() || NextToken().is(tok::kw_friend) | 3153 | ? diag::err_friend_concept | ^~ 3154 | : diag:: | 3155 | err_concept_decls_may_only_appear_in_global_namespace_scope); --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 78510e61a639fa..cb52629f9c61c7 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,9 +983,6 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; -def err_friend_concept : Error< - "friend declaration cannot be a concept">; - // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 883db838ca0147..d102a45f8c1ed2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,6 +3020,8 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts +def err_friend_concept : Error< + "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< >From 1733184c9a6fa8a375dec2c10f5456cfb86e9a57 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 14:58:27 +0200 Subject: [PATCH 2/6] cast instead --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 +++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 -- clang/lib/Parse/ParseDeclCXX.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index cb52629f9c61c7..78510e61a639fa 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,6 +983,9 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; +def err_friend_concept : Error< + "friend declaration cannot be a concept">; + // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d102a45f8c1ed2..883db838ca0147 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,8 +3020,6 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts -def err_friend_concept : Error< - "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6f0f5a0311bc18..fb159eb997ce9d 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -3150,8 +3150,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( if (Tok.is(tok::kw_concept)) { Diag(Tok.getLocation(), DS.isFriendSpecified() || NextToken().is(tok::kw_friend) - ? diag::err_friend_concept - : diag:: + ? (unsigned)diag::err_friend_concept + : (unsigned)diag:: err_concept_decls_may_only_appear_in_global_namespace_scope); SkipUntil(tok::semi, tok::r
[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)
https://github.com/kidq330 edited https://github.com/llvm/llvm-project/pull/113046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
@@ -3148,11 +3148,13 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // we did nothing here, but this allows us to issue a more // helpful diagnostic. if (Tok.is(tok::kw_concept)) { -Diag(Tok.getLocation(), - DS.isFriendSpecified() || NextToken().is(tok::kw_friend) - ? diag::err_friend_concept - : diag:: - err_concept_decls_may_only_appear_in_global_namespace_scope); +Diag( +Tok.getLocation(), +DS.isFriendSpecified() || NextToken().is(tok::kw_friend) +? unsigned(diag::err_friend_concept) cor3ntin wrote: ```suggestion ? llvm::to_underlying(diag::err_friend_concept) ``` https://github.com/llvm/llvm-project/pull/112816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)
https://github.com/kidq330 created https://github.com/llvm/llvm-project/pull/113046 None From b2753fc81792cf5c3a95eedbf349bac2e461e883 Mon Sep 17 00:00:00 2001 From: Giovanni Martins Date: Wed, 6 Dec 2023 11:26:53 -0300 Subject: [PATCH 1/3] replace memcpy with std::copy on clang-tidy removed typo on files sort imports removed some typo solve linter reports update modernize-replace-memcpy-with-stdcopy.rst --- .../clang-tidy/modernize/CMakeLists.txt | 1 + .../modernize/ModernizeTidyModule.cpp | 3 + .../modernize/ReplaceMemcpyWithStdCopy.cpp| 119 ++ .../modernize/ReplaceMemcpyWithStdCopy.h | 49 clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../docs/clang-tidy/checks/list.rst | 1 + .../modernize-replace-memcpy-with-stdcopy.rst | 47 +++ 7 files changed, 225 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp create mode 100644 clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/modernize/modernize-replace-memcpy-with-stdcopy.rst diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt index c919d49b42873a..83ebd2f12775e7 100644 --- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt @@ -23,6 +23,7 @@ add_clang_library(clangTidyModernizeModule STATIC RedundantVoidArgCheck.cpp ReplaceAutoPtrCheck.cpp ReplaceDisallowCopyAndAssignMacroCheck.cpp + ReplaceMemcpyWithStdCopy.cpp ReplaceRandomShuffleCheck.cpp ReturnBracedInitListCheck.cpp ShrinkToFitCheck.cpp diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp index 18607593320635..257c9373444761 100644 --- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp @@ -24,6 +24,7 @@ #include "RedundantVoidArgCheck.h" #include "ReplaceAutoPtrCheck.h" #include "ReplaceDisallowCopyAndAssignMacroCheck.h" +#include "ReplaceMemcpyWithStdCopy.h" #include "ReplaceRandomShuffleCheck.h" #include "ReturnBracedInitListCheck.h" #include "ShrinkToFitCheck.h" @@ -91,6 +92,8 @@ class ModernizeModule : public ClangTidyModule { "modernize-replace-auto-ptr"); CheckFactories.registerCheck( "modernize-replace-disallow-copy-and-assign-macro"); +CheckFactories.registerCheck( +"modernize-replace-memcpy-by-stdcopy"); CheckFactories.registerCheck( "modernize-replace-random-shuffle"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp new file mode 100644 index 00..af6b365c162517 --- /dev/null +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp @@ -0,0 +1,119 @@ +//===--- ReplaceMemcpyWithStdCopy.cpp - clang-tidy*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ReplaceMemcpyWithStdCopy.h" +#include "../utils/OptionsUtils.h" +#include + +using namespace clang; +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace modernize { + +ReplaceMemcpyWithStdCopy::ReplaceMemcpyWithStdCopy(StringRef Name, + ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + IncludeInserter(Options.getLocalOrGlobal("IncludeStyle", + utils::IncludeSorter::IS_LLVM)) { +} + +void ReplaceMemcpyWithStdCopy::registerMatchers(MatchFinder *Finder) { + assert(Finder != nullptr); + + if (!getLangOpts().CPlusPlus) +return; + + auto MemcpyMatcher = + callExpr(hasDeclaration(functionDecl(hasName("memcpy"), + isExpansionInSystemHeader())), + isExpansionInMainFile()) + .bind("memcpy_function"); + + Finder->addMatcher(MemcpyMatcher, this); +} + +void ReplaceMemcpyWithStdCopy::registerPPCallbacks( +const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { + if (!getLangOpts().CPlusPlus) +return; + + Inserter = + std::make_unique(SM, getLangOpts(), + IncludeStyle); + PP->addPPCallbacks(Inserter->CreatePPCallbacks()); +} + +void ReplaceMemcpyWithStdCopy::check(const MatchFinder::MatchResult &Result) { + const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function"); + assert(MemcpyNode !=
[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/113046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
@@ -3148,11 +3148,13 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // we did nothing here, but this allows us to issue a more // helpful diagnostic. if (Tok.is(tok::kw_concept)) { -Diag(Tok.getLocation(), - DS.isFriendSpecified() || NextToken().is(tok::kw_friend) - ? diag::err_friend_concept - : diag:: - err_concept_decls_may_only_appear_in_global_namespace_scope); +Diag( +Tok.getLocation(), +DS.isFriendSpecified() || NextToken().is(tok::kw_friend) +? unsigned(diag::err_friend_concept) +: unsigned( cor3ntin wrote: ```suggestion : llvm::to_underlying(( ``` https://github.com/llvm/llvm-project/pull/112816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)
https://github.com/yronglin edited https://github.com/llvm/llvm-project/pull/113049 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a crash on C# `goto case` (PR #113056)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/113056 Fixes #113011. >From dd3bba3760b74806871593c430f9c1f6b55cfe62 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 19 Oct 2024 10:25:32 -0700 Subject: [PATCH] [clang-format] Fix a crash on C# `goto case` Fixes #113011. --- clang/lib/Format/UnwrappedLineParser.cpp| 2 +- clang/unittests/Format/FormatTestCSharp.cpp | 12 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index bda9850670ab06..4a5109983dfcc5 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2148,7 +2148,7 @@ bool UnwrappedLineParser::tryToParsePropertyAccessor() { if (!Style.isCSharp()) return false; // See if it's a property accessor. - if (FormatTok->Previous->isNot(tok::identifier)) + if (!FormatTok->Previous || FormatTok->Previous->isNot(tok::identifier)) return false; // See if we are inside a property accessor. diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 3b04238b9b48b0..0c5afa1524374d 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -1688,6 +1688,18 @@ TEST_F(FormatTestCSharp, BrokenBrackets) { EXPECT_NE("", format("int where b <")); // reduced from crasher } +TEST_F(FormatTestCSharp, GotoCaseLabel) { + verifyNoCrash("switch (i) {\n" +"case 0:\n" +" goto case 1;\n" +"case 1:\n" +" j = 0;\n" +" {\n" +"break;\n" +" }\n" +"}"); +} + } // namespace } // namespace test } // namespace format ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in fma function. (PR #113020)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/113020 >From 93c625ad60fc834e72df667addc6eec83247fc8c Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 19 Oct 2024 03:45:17 + Subject: [PATCH 1/3] constexpr fma --- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/Basic/Builtins.td | 1 + clang/lib/AST/ByteCode/InterpBuiltin.cpp | 37 +++ clang/lib/AST/ExprConstant.cpp| 16 clang/test/AST/ByteCode/builtin-functions.cpp | 9 + clang/test/Sema/constant-builtins-2.c | 7 6 files changed, 71 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7a6ace8bb895d..605d55a9e51f37 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -273,6 +273,7 @@ Non-comprehensive list of changes in this release - Plugins can now define custom attributes that apply to statements as well as declarations. - ``__builtin_abs`` function can now be used in constant expressions. +- ``__builtin_fma`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 90475a361bb8f8..55f470a9f715b9 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -3723,6 +3723,7 @@ def Fma : FPMathTemplate, LibBuiltin<"math.h"> { let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions]; let Prototype = "T(T, T, T)"; let AddBuiltinPrefixedAlias = 1; + let OnlyBuiltinPrefixedAliasIsConstexpr = 1; } def Fmax : FPMathTemplate, LibBuiltin<"math.h"> { diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index d4a8e6c2035ee5..145f4627dd73da 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -142,6 +142,19 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result, #undef RET_CASE } +/// Get rounding mode to use in evaluation of the specified expression. +/// +/// If rounding mode is unknown at compile time, still try to evaluate the +/// expression. If the result is exact, it does not depend on rounding mode. +/// So return "tonearest" mode instead of "dynamic". +static llvm::RoundingMode getActiveRoundingMode(InterpState &S, const Expr *E) { + llvm::RoundingMode RM = + E->getFPFeaturesInEffect(S.getLangOpts()).getRoundingMode(); + if (RM == llvm::RoundingMode::Dynamic) +RM = llvm::RoundingMode::NearestTiesToEven; + return RM; +} + static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC, const InterpFrame *Frame, const CallExpr *Call) { @@ -549,6 +562,22 @@ static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC, return true; } +static bool interp__builtin_fma(InterpState &S, CodePtr OpPC, +const InterpFrame *Frame, const Function *Func, +const CallExpr *Call) { + const Floating &X = getParam(Frame, 0); + const Floating &Y = getParam(Frame, 1); + const Floating &Z = getParam(Frame, 2); + Floating Result; + + llvm::RoundingMode RM = getActiveRoundingMode(S, Call); + Floating::mul(X, Y, RM, &Result); + Floating::add(Result, Z, RM, &Result); + + S.Stk.push(Result); + return true; +} + // The C standard says "fabs raises no floating-point exceptions, // even if x is a signaling NaN. The returned value is independent of // the current rounding direction mode." Therefore constant folding can @@ -1814,6 +1843,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, return false; break; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: +if (!interp__builtin_fma(S, OpPC, Frame, F, Call)) + return false; +break; + case Builtin::BI__builtin_fabs: case Builtin::BI__builtin_fabsf: case Builtin::BI__builtin_fabsl: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 8e36cad2d2c6e7..685ce8a63f6c9e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { Result.changeSign(); return true; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: { +APFloat Y(0.), Z(0.); +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluateFloat(E->getArg(1), Y, Info) || +!EvaluateFloat(E->getArg(2), Z, Info)) + return false; + +llvm::RoundingMode RM = getActiveRoundingMode(Info, E); +Result.multiply(Y, RM); +Result.add(Z, RM); +return true;
[clang] [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (PR #112966)
https://github.com/whisperity closed https://github.com/llvm/llvm-project/pull/112966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (PR #112966)
https://github.com/whisperity edited https://github.com/llvm/llvm-project/pull/112966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (PR #112966)
https://github.com/whisperity approved this pull request. https://github.com/llvm/llvm-project/pull/112966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (PR #112966)
github-actions[bot] wrote: @BenBlumer Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/112966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5e81437 - [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (#112966)
Author: BrnBlrg Date: 2024-10-19T11:06:12+02:00 New Revision: 5e81437f2ba03ee0ab93b26a9654da9b95dab3b0 URL: https://github.com/llvm/llvm-project/commit/5e81437f2ba03ee0ab93b26a9654da9b95dab3b0 DIFF: https://github.com/llvm/llvm-project/commit/5e81437f2ba03ee0ab93b26a9654da9b95dab3b0.diff LOG: [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (#112966) Added: Modified: clang/docs/analyzer/user-docs/CommandLineUsage.rst Removed: diff --git a/clang/docs/analyzer/user-docs/CommandLineUsage.rst b/clang/docs/analyzer/user-docs/CommandLineUsage.rst index d7f8253469df40..59f8187f374a95 100644 --- a/clang/docs/analyzer/user-docs/CommandLineUsage.rst +++ b/clang/docs/analyzer/user-docs/CommandLineUsage.rst @@ -2,7 +2,7 @@ Command Line Usage: scan-build and CodeChecker == This document provides guidelines for running the static analyzer from the command line on whole projects. -CodeChecker and scan-build are two CLI tools for using CSA on multiple files (tranlation units). +CodeChecker and scan-build are two CLI tools for using CSA on multiple files (translation units). Both provide a way of driving the analyzer, detecting compilation flags, and generating reports. CodeChecker is more actively maintained, provides heuristics for working with multiple versions of popular compilers and it also comes with a web-based GUI for viewing, filtering, categorizing and suppressing the results. Therefore CodeChecker is recommended in case you need any of the above features or just more customizability in general. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112424 >From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 15 Oct 2024 22:43:24 +0300 Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier for missing primary declarations --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAccess.cpp | 3 ++- clang/test/SemaCXX/enum.cpp | 8 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 817e3abef8d566..64ffdcde045a3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,6 +517,8 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) +- Fixed an assertion failure when the default lexical access specifier was set for missing + primary declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index df6edb21a50dee..8b4a5b70669d84 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -MemberDecl->setAccess(LexicalAS); +if (LexicalAS != AS_none) + MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da886c..44042d8bf5cfc8 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ +// expected-error {{unexpected ';' before ')'}} +}; +} >From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 18 Oct 2024 14:55:47 +0300 Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum forward declarations --- clang/docs/ReleaseNotes.rst | 3 +-- clang/lib/Sema/SemaAccess.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64ffdcde045a3a..3fd37663ca7bc6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,8 +517,7 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) -- Fixed an assertion failure when the default lexical access specifier was set for missing - primary declarations. (#GH112208) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 8b4a5b70669d84..df6edb21a50dee 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -if (LexicalAS != AS_none) - MemberDecl->setAccess(LexicalAS); +MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fece22c663d00c..9eb3d06289e88f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration && Name) +Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112081 >From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 12 Oct 2024 08:27:51 +0300 Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw expressions --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaChecking.cpp | 3 +++ clang/test/SemaCXX/conditional-expr.cpp | 7 +++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 337e3fc10bf49d..2ab13640bfa53c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -512,6 +512,7 @@ Bug Fixes to C++ Support and undeclared templates. (#GH107047, #GH49093) - Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded parameter pack. (#GH109148) +- Fixed assertion failure in range calculations for conditional throw expressions (#GH111854) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2bcb930acdcb57..b3d88f053872c1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, return IntRange(BitField->getBitWidthValue(C), BitField->getType()->isUnsignedIntegerOrEnumerationType()); + if (GetExprType(E)->isVoidType()) +return IntRange{0, true}; + return IntRange::forValueOfType(C, GetExprType(E)); } diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 01effaa189322b..8f17555fd806ff 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -429,3 +429,10 @@ void g() { long e = a = b ? throw 0 : throw 1; } } // namespace PR46484 + +namespace GH111854 { +void f() { + (true ? throw 0 : 0) <= 0; // expected-warning {{relational comparison result unused}} + (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison result unused}} +} +} >From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 19 Oct 2024 00:00:19 +0300 Subject: [PATCH 2/2] change return type to nullable for handling invalid ranges in integer expression evaluation --- clang/lib/Sema/SemaChecking.cpp | 198 +++- 1 file changed, 118 insertions(+), 80 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b3d88f053872c1..2ca342a6065550 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) { ///particular, assume that arithmetic on narrower types doesn't leave ///those types. If \c false, return a range including all possible ///result values. -static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, - bool InConstantContext, bool Approximate) { +static std::optional TryGetExprRange(ASTContext &C, const Expr *E, + unsigned MaxWidth, + bool InConstantContext, + bool Approximate) { E = E->IgnoreParens(); // Try a full evaluation first. @@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, // being of the new, wider type. if (const auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue) - return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, - Approximate); + return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, + Approximate); IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE)); @@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, if (!isIntegerCast) return OutputTypeRange; -IntRange SubRange = GetExprRange(C, CE->getSubExpr(), - std::min(MaxWidth, OutputTypeRange.Width), - InConstantContext, Approximate); +std::optional SubRange = TryGetExprRange( +C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width), +InConstantContext, Approximate); +if (!SubRange) + return std::nullopt; // Bail out if the subexpr's range is as wide as the cast type. -if (SubRange.Width >= OutputTypeRange.Width) +if (SubRange->Width >= OutputTypeRange.Width) return OutputTypeRange; // Otherwise, we take the smaller width, and we're non-negative if // either the output type or the subexpr is. -
[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112424 >From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 15 Oct 2024 22:43:24 +0300 Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier for missing primary declarations --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAccess.cpp | 3 ++- clang/test/SemaCXX/enum.cpp | 8 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 817e3abef8d566..64ffdcde045a3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,6 +517,8 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) +- Fixed an assertion failure when the default lexical access specifier was set for missing + primary declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index df6edb21a50dee..8b4a5b70669d84 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -MemberDecl->setAccess(LexicalAS); +if (LexicalAS != AS_none) + MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da886c..44042d8bf5cfc8 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ +// expected-error {{unexpected ';' before ')'}} +}; +} >From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 18 Oct 2024 14:55:47 +0300 Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum forward declarations --- clang/docs/ReleaseNotes.rst | 3 +-- clang/lib/Sema/SemaAccess.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64ffdcde045a3a..3fd37663ca7bc6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,8 +517,7 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) -- Fixed an assertion failure when the default lexical access specifier was set for missing - primary declarations. (#GH112208) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 8b4a5b70669d84..df6edb21a50dee 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -if (LexicalAS != AS_none) - MemberDecl->setAccess(LexicalAS); +MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fece22c663d00c..9eb3d06289e88f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration && Name) +Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 2eb1699 - [clangd] Add inlay hints for default function arguments (#95712)
Author: Tor Shepherd Date: 2024-10-19T18:19:01-04:00 New Revision: 2eb1699184cf4d5de69f7825f66d7b3c04827f77 URL: https://github.com/llvm/llvm-project/commit/2eb1699184cf4d5de69f7825f66d7b3c04827f77 DIFF: https://github.com/llvm/llvm-project/commit/2eb1699184cf4d5de69f7825f66d7b3c04827f77.diff LOG: [clangd] Add inlay hints for default function arguments (#95712) The new inlay hints have the `DefaultArguments` kind and can be enabled in config similar to other inlay kint kinds. Added: Modified: clang-tools-extra/clangd/Config.h clang-tools-extra/clangd/ConfigCompile.cpp clang-tools-extra/clangd/ConfigFragment.h clang-tools-extra/clangd/ConfigYAML.cpp clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h clang-tools-extra/clangd/unittests/InlayHintTests.cpp clang-tools-extra/docs/ReleaseNotes.rst Removed: diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h index 8fcbc5c33469fa..e174f7fabe344e 100644 --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -162,6 +162,7 @@ struct Config { bool DeducedTypes = true; bool Designators = true; bool BlockEnd = false; +bool DefaultArguments = false; // Limit the length of type names in inlay hints. (0 means no limit) uint32_t TypeNameLimit = 32; } InlayHints; diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index 58610a5b87922d..fb7692998d05c7 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -43,7 +43,6 @@ #include "llvm/Support/Regex.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" -#include #include #include #include @@ -669,6 +668,11 @@ struct FragmentCompiler { Out.Apply.push_back([Value(**F.BlockEnd)](const Params &, Config &C) { C.InlayHints.BlockEnd = Value; }); +if (F.DefaultArguments) + Out.Apply.push_back( + [Value(**F.DefaultArguments)](const Params &, Config &C) { +C.InlayHints.DefaultArguments = Value; + }); if (F.TypeNameLimit) Out.Apply.push_back( [Value(**F.TypeNameLimit)](const Params &, Config &C) { diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h index fc1b45f5d4c3e9..36f7d04231c414 100644 --- a/clang-tools-extra/clangd/ConfigFragment.h +++ b/clang-tools-extra/clangd/ConfigFragment.h @@ -339,6 +339,9 @@ struct Fragment { std::optional> Designators; /// Show defined symbol names at the end of a definition block. std::optional> BlockEnd; +/// Show parameter names and default values of default arguments after all +/// of the explicit arguments. +std::optional> DefaultArguments; /// Limit the length of type name hints. (0 means no limit) std::optional> TypeNameLimit; }; diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp index bcdda99eeed67a..32e028981d4244 100644 --- a/clang-tools-extra/clangd/ConfigYAML.cpp +++ b/clang-tools-extra/clangd/ConfigYAML.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/YAMLParser.h" #include #include -#include namespace clang { namespace clangd { @@ -268,6 +267,10 @@ class Parser { if (auto Value = boolValue(N, "BlockEnd")) F.BlockEnd = *Value; }); +Dict.handle("DefaultArguments", [&](Node &N) { + if (auto Value = boolValue(N, "DefaultArguments")) +F.DefaultArguments = *Value; +}); Dict.handle("TypeNameLimit", [&](Node &N) { if (auto Value = uint32Value(N, "TypeNameLimit")) F.TypeNameLimit = *Value; diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index cd4f1931b3ce1d..c4053fced81d6f 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -11,9 +11,11 @@ #include "Config.h" #include "HeuristicResolver.h" #include "ParsedAST.h" +#include "Protocol.h" #include "SourceCode.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -23,15 +25,22 @@ #include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Sav
[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
https://github.com/carlosgalvezp edited https://github.com/llvm/llvm-project/pull/111434 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [NVPTX] Remove nvvm.ldg.global.* intrinsics (PR #112834)
https://github.com/AlexMaclean updated https://github.com/llvm/llvm-project/pull/112834 >From 0b43fa7364bf45515905d98cd0731c5509de5196 Mon Sep 17 00:00:00 2001 From: Alex Maclean Date: Thu, 17 Oct 2024 16:49:24 + Subject: [PATCH 1/2] [NVPTX] Remove nvvm.ldg.global.* intrinsics --- clang/lib/CodeGen/CGBuiltin.cpp | 45 +++-- .../builtins-nvptx-native-half-type-native.c | 4 +- .../CodeGen/builtins-nvptx-native-half-type.c | 4 +- clang/test/CodeGen/builtins-nvptx.c | 72 +++ llvm/include/llvm/IR/IntrinsicsNVVM.td| 18 +- llvm/lib/IR/AutoUpgrade.cpp | 14 ++ llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp | 189 +++--- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 55 + llvm/lib/Target/NVPTX/NVPTXISelLowering.h | 2 - .../Assembler/auto_upgrade_nvvm_intrinsics.ll | 31 +++ 10 files changed, 188 insertions(+), 246 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index f6d7db2c204c12..3b42977b578e15 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20473,7 +20473,7 @@ static NVPTXMmaInfo getNVPTXMmaInfo(unsigned BuiltinID) { #undef MMA_VARIANTS_B1_XOR } -static Value *MakeLdgLdu(unsigned IntrinsicID, CodeGenFunction &CGF, +static Value *MakeLdu(unsigned IntrinsicID, CodeGenFunction &CGF, const CallExpr *E) { Value *Ptr = CGF.EmitScalarExpr(E->getArg(0)); QualType ArgType = E->getArg(0)->getType(); @@ -20484,6 +20484,21 @@ static Value *MakeLdgLdu(unsigned IntrinsicID, CodeGenFunction &CGF, {Ptr, ConstantInt::get(CGF.Builder.getInt32Ty(), Align.getQuantity())}); } +static Value *MakeLdg(CodeGenFunction &CGF, const CallExpr *E) { + Value *Ptr = CGF.EmitScalarExpr(E->getArg(0)); + QualType ArgType = E->getArg(0)->getType(); + clang::CharUnits AlignV = CGF.CGM.getNaturalPointeeTypeAlignment(ArgType); + llvm::Type *ElemTy = CGF.ConvertTypeForMem(ArgType->getPointeeType()); + + // Use addrspace(1) for NVPTX ADDRESS_SPACE_GLOBAL + auto *ASC = CGF.Builder.CreateAddrSpaceCast(Ptr, CGF.Builder.getPtrTy(1)); + auto *LD = CGF.Builder.CreateAlignedLoad(ElemTy, ASC, AlignV.getAsAlign()); + MDNode *MD = MDNode::get(CGF.Builder.getContext(), {}); + LD->setMetadata(LLVMContext::MD_invariant_load, MD); + + return LD; +} + static Value *MakeScopedAtomic(unsigned IntrinsicID, CodeGenFunction &CGF, const CallExpr *E) { Value *Ptr = CGF.EmitScalarExpr(E->getArg(0)); @@ -20517,9 +20532,11 @@ static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID, return nullptr; } - if (IntrinsicID == Intrinsic::nvvm_ldg_global_f || - IntrinsicID == Intrinsic::nvvm_ldu_global_f) -return MakeLdgLdu(IntrinsicID, CGF, E); + if (BuiltinID == NVPTX::BI__nvvm_ldg_h || BuiltinID == NVPTX::BI__nvvm_ldg_h2) +return MakeLdg(CGF, E); + + if (IntrinsicID == Intrinsic::nvvm_ldu_global_f) +return MakeLdu(IntrinsicID, CGF, E); SmallVector Args; auto *F = CGF.CGM.getIntrinsic(IntrinsicID); @@ -20656,16 +20673,15 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_ldg_ul2: case NVPTX::BI__nvvm_ldg_ull: case NVPTX::BI__nvvm_ldg_ull2: -// PTX Interoperability section 2.2: "For a vector with an even number of -// elements, its alignment is set to number of elements times the alignment -// of its member: n*alignof(t)." -return MakeLdgLdu(Intrinsic::nvvm_ldg_global_i, *this, E); case NVPTX::BI__nvvm_ldg_f: case NVPTX::BI__nvvm_ldg_f2: case NVPTX::BI__nvvm_ldg_f4: case NVPTX::BI__nvvm_ldg_d: case NVPTX::BI__nvvm_ldg_d2: -return MakeLdgLdu(Intrinsic::nvvm_ldg_global_f, *this, E); +// PTX Interoperability section 2.2: "For a vector with an even number of +// elements, its alignment is set to number of elements times the alignment +// of its member: n*alignof(t)." +return MakeLdg(*this, E); case NVPTX::BI__nvvm_ldu_c: case NVPTX::BI__nvvm_ldu_sc: @@ -20696,13 +20712,13 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, case NVPTX::BI__nvvm_ldu_ul2: case NVPTX::BI__nvvm_ldu_ull: case NVPTX::BI__nvvm_ldu_ull2: -return MakeLdgLdu(Intrinsic::nvvm_ldu_global_i, *this, E); +return MakeLdu(Intrinsic::nvvm_ldu_global_i, *this, E); case NVPTX::BI__nvvm_ldu_f: case NVPTX::BI__nvvm_ldu_f2: case NVPTX::BI__nvvm_ldu_f4: case NVPTX::BI__nvvm_ldu_d: case NVPTX::BI__nvvm_ldu_d2: -return MakeLdgLdu(Intrinsic::nvvm_ldu_global_f, *this, E); +return MakeLdu(Intrinsic::nvvm_ldu_global_f, *this, E); case NVPTX::BI__nvvm_atom_cta_add_gen_i: case NVPTX::BI__nvvm_atom_cta_add_gen_l: @@ -21176,14 +21192,11 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16x2, BuiltinID, E, *this); case NVPTX::BI__nvvm_ldg_h
[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
@@ -102,7 +102,7 @@ struct __aliasing_iterator_wrapper { _LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT { _Alias __val; - __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type)); + __builtin_memcpy(&__val, static_cast(std::__to_address(__base_)), sizeof(value_type)); carlosgalvezp wrote: [cppreference](https://en.cppreference.com/w/cpp/string/byte/memcpy) used to say that it was UB, but now they have changed it to "may be UB": Honestly, I cannot find any reference in the C++ Standard about this, maybe it's indirectly from [basic.life] of something. The C standard only says: > The memcpy function copies n characters from the object pointed to by s2 into > the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined. https://github.com/llvm/llvm-project/pull/111434 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86][RFC] Refactor the SSE intrinsics constexpr tests to simplify future expansion (PR #112578)
@@ -6,13 +6,23 @@ #include +#if defined(__cplusplus) && (__cplusplus >= 201103L) +constexpr bool match_m128(__m128 v, float x, float y, float z, float w) { + return v[0] == x && v[1] == y && v[2] == z && v[3] == w; +} +#define TEST_CONSTEXPR(...) static_assert(__VA_ARGS__) +#else +#define TEST_CONSTEXPR(...) +#endif + boomanaiden154 wrote: Is the plan to do that in this patch or a later one? I think it would make sense to do here given the duplication between the SSE builtin tests. https://github.com/llvm/llvm-project/pull/112578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)
@@ -221,21 +221,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { PtrDepth++; Ty = Ty->getPointeeType().getTypePtr(); } while (Ty->isPointerType()); -// TODO: Implement C++'s type "similarity" and consider dis-"similar" -// pointers distinct for non-builtin types. + +SmallString<256> TyName; if (isa(Ty)) { llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty); StringRef Name = cast( ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0)) ->getString(); + TyName = Name; +} else if (!isa(Ty)) { + // For non-builtin types use the mangled name of the canonical type. + llvm::raw_svector_ostream TyOut(TyName); + Context.createMangleContext()->mangleCanonicalTypeName(QualType(Ty, 0), fhahn wrote: Updated to retrieve a pointer to the Itanium mangler once and use it here, thanks! https://github.com/llvm/llvm-project/pull/110569 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)
@@ -221,21 +221,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { PtrDepth++; Ty = Ty->getPointeeType().getTypePtr(); } while (Ty->isPointerType()); -// TODO: Implement C++'s type "similarity" and consider dis-"similar" -// pointers distinct for non-builtin types. + +SmallString<256> TyName; if (isa(Ty)) { llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty); StringRef Name = cast( ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0)) ->getString(); + TyName = Name; +} else if (!isa(Ty)) { fhahn wrote: Thanks, it should be adjusted now. https://github.com/llvm/llvm-project/pull/110569 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)
@@ -221,21 +221,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { PtrDepth++; Ty = Ty->getPointeeType().getTypePtr(); } while (Ty->isPointerType()); -// TODO: Implement C++'s type "similarity" and consider dis-"similar" -// pointers distinct for non-builtin types. + +SmallString<256> TyName; fhahn wrote: Done, thanks! https://github.com/llvm/llvm-project/pull/110569 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)
@@ -221,21 +221,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { PtrDepth++; Ty = Ty->getPointeeType().getTypePtr(); } while (Ty->isPointerType()); -// TODO: Implement C++'s type "similarity" and consider dis-"similar" -// pointers distinct for non-builtin types. + +SmallString<256> TyName; fhahn wrote: Done, thanks! https://github.com/llvm/llvm-project/pull/110569 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/104533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 093d4db - Add "clang-format-on-save-mode" minor mode to clang-format.el (#104533)
Author: Campbell Barton Date: 2024-10-19T22:09:06+02:00 New Revision: 093d4db2f3c874d4683fb01194b00dbb20e5c713 URL: https://github.com/llvm/llvm-project/commit/093d4db2f3c874d4683fb01194b00dbb20e5c713 DIFF: https://github.com/llvm/llvm-project/commit/093d4db2f3c874d4683fb01194b00dbb20e5c713.diff LOG: Add "clang-format-on-save-mode" minor mode to clang-format.el (#104533) Add an minor mode which can be optionally used to run clang-format on save. Formatting before saving works well and is convenient to avoid having to remember to manually run clang format. I've written this as it's own package but it's probably better if the functionality is supported by clang-format.el. See: https://github.com/melpa/melpa/pull/8762 Added: Modified: clang/tools/clang-format/clang-format.el Removed: diff --git a/clang/tools/clang-format/clang-format.el b/clang/tools/clang-format/clang-format.el index f3da5415f8672b..fb943b7b722f8a 100644 --- a/clang/tools/clang-format/clang-format.el +++ b/clang/tools/clang-format/clang-format.el @@ -70,6 +70,20 @@ in such buffers." :safe #'stringp) (make-variable-buffer-local 'clang-format-fallback-style) +(defcustom clang-format-on-save-p 'clang-format-on-save-check-config-exists + "Only reformat on save if this function returns non-nil. + +You may wish to choose one of the following options: +- `always': To always format on save. +- `clang-format-on-save-check-config-exists': + Only reformat when \".clang-format\" exists. + +Otherwise you can set this to a user defined function." + :group 'clang-format + :type 'function + :risky t) +(make-variable-buffer-local 'clang-format-on-save-p) + (defun clang-format--extract (xml-node) "Extract replacements and cursor information from XML-NODE." (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements)) @@ -217,5 +231,48 @@ the function `buffer-file-name'." ;;;###autoload (defalias 'clang-format 'clang-format-region) +;; Format on save minor mode. + +(defun clang-format--on-save-buffer-hook () + "The hook to run on buffer saving to format the buffer." + ;; Demote errors as this is user configurable, we can't be sure it wont error. + (when (with-demoted-errors "clang-format: Error %S" + (funcall clang-format-on-save-p)) +(clang-format-buffer)) + ;; Continue to save. + nil) + +(defun clang-format--on-save-enable () + "Disable the minor mode." + (add-hook 'before-save-hook #'clang-format--on-save-buffer-hook nil t)) + +(defun clang-format--on-save-disable () + "Enable the minor mode." + (remove-hook 'before-save-hook #'clang-format--on-save-buffer-hook t)) + +;; Default value for `clang-format-on-save-p'. +(defun clang-format-on-save-check-config-exists () + "Return non-nil when `.clang-format' is found in a parent directory." + ;; Unlikely but possible this is nil. + (let ((filepath buffer-file-name)) +(cond + (filepath + (not (null (locate-dominating-file (file-name-directory filepath) ".clang-format" + (t + nil + +;;;###autoload +(define-minor-mode clang-format-on-save-mode + "Clang-format on save minor mode." + :global nil + :lighter "" + :keymap nil + + (cond + (clang-format-on-save-mode +(clang-format--on-save-enable)) + (t +(clang-format--on-save-disable + (provide 'clang-format) ;;; clang-format.el ends here ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)
github-actions[bot] wrote: @ideasman42 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/104533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Coverage] Introduce "partial fold" on BranchRegion (PR #112694)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/112694 >From ea3e2df8c712ae5da77e55a14e97b1b6855a6b76 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 6 Oct 2024 10:11:54 +0900 Subject: [PATCH 1/2] [Coverage] Introduce "partial fold" on BranchRegion Currently both True/False counts were folded. It lost the information, "It is True or False before folding." It prevented recalling branch counts in merging template instantiations. In `llvm-cov`, a folded branch is shown as: - `[True: n, Folded]` - `[Folded, False n]` In the case If `n` is zero, a branch is reported as "uncovered". This is distinguished from "folded" branch. When folded branches are merged, `Folded` may be dissolved. In the coverage map, either `Counter` is `Zero`. Currently both were `Zero`. Since "partial fold" has been introduced, either case in `switch` is omitted as `Folded`. Each `case:` in `switch` is reported as `[True: n, Folded]`, since `False` count doesn't show meaningful value. When `switch` doesn't have `default:`, `switch (Cond)` is reported as `[Folded, False: n]`, since `True` count was just the sum of `case`(s). `switch` with `default` can be considered as "the statement that doesn't have any `False`(s)". --- clang/lib/CodeGen/CoverageMappingGen.cpp | 46 + .../CoverageMapping/branch-constfolded.cpp| 40 ++-- clang/test/CoverageMapping/if.cpp | 4 +- clang/test/CoverageMapping/macro-expansion.c | 10 +-- .../test/CoverageMapping/mcdc-scratch-space.c | 4 +- .../CoverageMapping/mcdc-system-headers.cpp | 4 +- clang/test/CoverageMapping/switch.cpp | 64 +-- clang/test/CoverageMapping/switchmacro.c | 4 +- .../ProfileData/Coverage/CoverageMapping.h| 15 +++-- .../ProfileData/Coverage/CoverageMapping.cpp | 2 +- .../test/tools/llvm-cov/branch-c-general.test | 14 ++-- llvm/tools/llvm-cov/CoverageExporterJson.cpp | 2 +- llvm/tools/llvm-cov/CoverageExporterLcov.cpp | 2 +- llvm/tools/llvm-cov/CoverageSummaryInfo.cpp | 24 +++ .../tools/llvm-cov/SourceCoverageViewHTML.cpp | 51 +-- .../tools/llvm-cov/SourceCoverageViewText.cpp | 47 -- 16 files changed, 169 insertions(+), 164 deletions(-) diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 07015834bc84f3..a9a3eb91a6af27 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1098,12 +1098,6 @@ struct CounterCoverageMappingBuilder return ExitCount; } - /// Determine whether the given condition can be constant folded. - bool ConditionFoldsToBool(const Expr *Cond) { -Expr::EvalResult Result; -return (Cond->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext())); - } - /// Create a Branch Region around an instrumentable condition for coverage /// and add it to the function's SourceRegions. A branch region tracks a /// "True" counter and a "False" counter for boolean expressions that @@ -1133,13 +1127,15 @@ struct CounterCoverageMappingBuilder // Alternatively, we can prevent any optimization done via // constant-folding by ensuring that ConstantFoldsToSimpleInteger() in // CodeGenFunction.c always returns false, but that is very heavy-handed. - if (ConditionFoldsToBool(C)) -popRegions(pushRegion(Counter::getZero(), getStart(C), getEnd(C), - Counter::getZero(), BranchParams)); - else -// Otherwise, create a region with the True counter and False counter. -popRegions(pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt, - BranchParams)); + Expr::EvalResult Result; + if (C->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext())) { +if (Result.Val.getInt().getBoolValue()) + FalseCnt = Counter::getZero(); +else + TrueCnt = Counter::getZero(); + } + popRegions( + pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt, BranchParams)); } } @@ -1153,12 +1149,12 @@ struct CounterCoverageMappingBuilder /// Create a Branch Region around a SwitchCase for code coverage /// and add it to the function's SourceRegions. - void createSwitchCaseRegion(const SwitchCase *SC, Counter TrueCnt, - Counter FalseCnt) { + void createSwitchCaseRegion(const SwitchCase *SC, Counter TrueCnt) { // Push region onto RegionStack but immediately pop it (which adds it to // the function's SourceRegions) because it doesn't apply to any other // source other than the SwitchCase. -popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), FalseCnt)); +popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), + Counter::getZero())); } /// Check whether a region with bounds \c StartLoc and \c EndLoc @@ -1870,24 +1866,16 @@ struct CounterCove
[clang] [llvm] [Coverage] Introduce "partial fold" on BranchRegion (PR #112694)
@@ -125,7 +125,7 @@ json::Array renderRegions(ArrayRef Regions) { json::Array renderBranchRegions(ArrayRef Regions) { json::Array RegionArray; for (const auto &Region : Regions) -if (!Region.Folded) +if (!Region.TrueFolded || !Region.FalseFolded) chapuni wrote: I guess we have to revisit how to show folding. Let me feed this to future tasks. https://github.com/llvm/llvm-project/pull/112694 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a crash on C# `goto case` (PR #113056)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #113011. --- Full diff: https://github.com/llvm/llvm-project/pull/113056.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-1) - (modified) clang/unittests/Format/FormatTestCSharp.cpp (+12) ``diff diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index bda9850670ab06..4a5109983dfcc5 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2148,7 +2148,7 @@ bool UnwrappedLineParser::tryToParsePropertyAccessor() { if (!Style.isCSharp()) return false; // See if it's a property accessor. - if (FormatTok->Previous->isNot(tok::identifier)) + if (!FormatTok->Previous || FormatTok->Previous->isNot(tok::identifier)) return false; // See if we are inside a property accessor. diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 3b04238b9b48b0..0c5afa1524374d 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -1688,6 +1688,18 @@ TEST_F(FormatTestCSharp, BrokenBrackets) { EXPECT_NE("", format("int where b <")); // reduced from crasher } +TEST_F(FormatTestCSharp, GotoCaseLabel) { + verifyNoCrash("switch (i) {\n" +"case 0:\n" +" goto case 1;\n" +"case 1:\n" +" j = 0;\n" +" {\n" +"break;\n" +" }\n" +"}"); +} + } // namespace } // namespace test } // namespace format `` https://github.com/llvm/llvm-project/pull/113056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in fma function. (PR #113020)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/113020 >From 93c625ad60fc834e72df667addc6eec83247fc8c Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 19 Oct 2024 03:45:17 + Subject: [PATCH 1/3] constexpr fma --- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/Basic/Builtins.td | 1 + clang/lib/AST/ByteCode/InterpBuiltin.cpp | 37 +++ clang/lib/AST/ExprConstant.cpp| 16 clang/test/AST/ByteCode/builtin-functions.cpp | 9 + clang/test/Sema/constant-builtins-2.c | 7 6 files changed, 71 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7a6ace8bb895d..605d55a9e51f37 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -273,6 +273,7 @@ Non-comprehensive list of changes in this release - Plugins can now define custom attributes that apply to statements as well as declarations. - ``__builtin_abs`` function can now be used in constant expressions. +- ``__builtin_fma`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 90475a361bb8f8..55f470a9f715b9 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -3723,6 +3723,7 @@ def Fma : FPMathTemplate, LibBuiltin<"math.h"> { let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions]; let Prototype = "T(T, T, T)"; let AddBuiltinPrefixedAlias = 1; + let OnlyBuiltinPrefixedAliasIsConstexpr = 1; } def Fmax : FPMathTemplate, LibBuiltin<"math.h"> { diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index d4a8e6c2035ee5..145f4627dd73da 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -142,6 +142,19 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, APValue &Result, #undef RET_CASE } +/// Get rounding mode to use in evaluation of the specified expression. +/// +/// If rounding mode is unknown at compile time, still try to evaluate the +/// expression. If the result is exact, it does not depend on rounding mode. +/// So return "tonearest" mode instead of "dynamic". +static llvm::RoundingMode getActiveRoundingMode(InterpState &S, const Expr *E) { + llvm::RoundingMode RM = + E->getFPFeaturesInEffect(S.getLangOpts()).getRoundingMode(); + if (RM == llvm::RoundingMode::Dynamic) +RM = llvm::RoundingMode::NearestTiesToEven; + return RM; +} + static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC, const InterpFrame *Frame, const CallExpr *Call) { @@ -549,6 +562,22 @@ static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC, return true; } +static bool interp__builtin_fma(InterpState &S, CodePtr OpPC, +const InterpFrame *Frame, const Function *Func, +const CallExpr *Call) { + const Floating &X = getParam(Frame, 0); + const Floating &Y = getParam(Frame, 1); + const Floating &Z = getParam(Frame, 2); + Floating Result; + + llvm::RoundingMode RM = getActiveRoundingMode(S, Call); + Floating::mul(X, Y, RM, &Result); + Floating::add(Result, Z, RM, &Result); + + S.Stk.push(Result); + return true; +} + // The C standard says "fabs raises no floating-point exceptions, // even if x is a signaling NaN. The returned value is independent of // the current rounding direction mode." Therefore constant folding can @@ -1814,6 +1843,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, return false; break; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: +if (!interp__builtin_fma(S, OpPC, Frame, F, Call)) + return false; +break; + case Builtin::BI__builtin_fabs: case Builtin::BI__builtin_fabsf: case Builtin::BI__builtin_fabsl: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 8e36cad2d2c6e7..685ce8a63f6c9e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { Result.changeSign(); return true; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: { +APFloat Y(0.), Z(0.); +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluateFloat(E->getArg(1), Y, Info) || +!EvaluateFloat(E->getArg(2), Z, Info)) + return false; + +llvm::RoundingMode RM = getActiveRoundingMode(Info, E); +Result.multiply(Y, RM); +Result.add(Z, RM); +return true;
[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)
https://github.com/Artem-B approved this pull request. LGTM overall, with a minor style nit. https://github.com/llvm/llvm-project/pull/113017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)
@@ -363,6 +363,14 @@ void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum, } } +void NVPTXInstPrinter::printOffseti32imm(const MCInst *MI, int OpNum, + raw_ostream &O, const char *Modifier) { + if (auto &Op = MI->getOperand(OpNum); Op.isImm() && Op.getImm() == 0) +return; // don't print '+0' + O << "+"; + printOperand(MI, OpNum, O); Artem-B wrote: Nit: No need for the early return here. Also, instead of just ignoring non-immediate operands, we should probablly assert it, as that should never happen. ``` auto &Op = MI->getOperand(OpNum); assert(Op.isImm() && "Invalid operand"); if (Op.getImm() != 0)) { O << "+"; printOperand(MI, OpNum, O); } ``` https://github.com/llvm/llvm-project/pull/113017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/96301 >From cbd6e832fbbc905d52926e268d7ba8568df80df1 Mon Sep 17 00:00:00 2001 From: Rajveer Date: Fri, 21 Jun 2024 18:26:36 +0530 Subject: [PATCH] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) Resolves #95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3 --- clang/docs/ReleaseNotes.rst| 3 ++ clang/lib/AST/DeclCXX.cpp | 8 +- clang/test/SemaCXX/GH95854.cpp | 51 ++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/GH95854.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7a6ace8bb895d..21f8d47cb36099 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -539,6 +539,9 @@ Bug Fixes to C++ Support - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) - Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559) +- Clang incorrectly considered a class with an anonymous union member to not be + const-default-constructible even if a union member has a default member initializer. + (#GH95854). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 08615d4393f5d1..34bb200e43360c 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1060,6 +1060,9 @@ void CXXRecordDecl::addedMember(Decl *D) { if (isUnion() && !Field->isAnonymousStructOrUnion()) data().HasVariantMembers = true; +if (isUnion() && IsFirstField) + data().HasUninitializedFields = true; + // C++0x [class]p9: // A POD struct is a class that is both a trivial class and a // standard-layout class, and has no non-static data members of type @@ -1128,7 +1131,10 @@ void CXXRecordDecl::addedMember(Decl *D) { data().DefaultedCopyConstructorIsDeleted = true; } -if (!Field->hasInClassInitializer() && !Field->isMutable()) { +if (isUnion() && !Field->isMutable()) { + if (Field->hasInClassInitializer()) +data().HasUninitializedFields = false; +} else if (!Field->hasInClassInitializer() && !Field->isMutable()) { if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) { if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) data().HasUninitializedFields = true; diff --git a/clang/test/SemaCXX/GH95854.cpp b/clang/test/SemaCXX/GH95854.cpp new file mode 100644 index 00..aa470c6ac8e5b4 --- /dev/null +++ b/clang/test/SemaCXX/GH95854.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s + +struct A { + union { +int n = 0; +int m; + }; +}; +const A a; + +struct B { + union { +struct { + int n = 5; + int m; +}; + }; +}; +const B b; // expected-error {{default initialization of an object of const type 'const B' without a user-provided default constructor}} + +struct S { + int i; + int j; +}; + +struct T { + T() = default; +}; + +struct C { + union { +S s; + }; +}; + +struct D { + union { +T s; + }; +}; + +const C c; // expected-error {{default initialization of an object of const type 'const C' without a user-provided default constructor}} +const D d; // expected-error {{default initialization of an object of const type 'const D' without a user-provided default constructor}} + +struct E { + union { +int n; +int m=0; + }; +}; +const E e; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/96301 >From c12be47eaa24981080b9eeb3aaa4770b03ad6a9e Mon Sep 17 00:00:00 2001 From: Rajveer Date: Fri, 21 Jun 2024 18:26:36 +0530 Subject: [PATCH] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) Resolves #95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3 --- clang/docs/ReleaseNotes.rst | 3 ++ clang/lib/AST/DeclCXX.cpp | 8 +- clang/test/Sema/debug-84072.cpp | 19 clang/test/SemaCXX/GH95854.cpp | 51 + 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/debug-84072.cpp create mode 100644 clang/test/SemaCXX/GH95854.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7a6ace8bb895d..21f8d47cb36099 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -539,6 +539,9 @@ Bug Fixes to C++ Support - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) - Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559) +- Clang incorrectly considered a class with an anonymous union member to not be + const-default-constructible even if a union member has a default member initializer. + (#GH95854). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 08615d4393f5d1..34bb200e43360c 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1060,6 +1060,9 @@ void CXXRecordDecl::addedMember(Decl *D) { if (isUnion() && !Field->isAnonymousStructOrUnion()) data().HasVariantMembers = true; +if (isUnion() && IsFirstField) + data().HasUninitializedFields = true; + // C++0x [class]p9: // A POD struct is a class that is both a trivial class and a // standard-layout class, and has no non-static data members of type @@ -1128,7 +1131,10 @@ void CXXRecordDecl::addedMember(Decl *D) { data().DefaultedCopyConstructorIsDeleted = true; } -if (!Field->hasInClassInitializer() && !Field->isMutable()) { +if (isUnion() && !Field->isMutable()) { + if (Field->hasInClassInitializer()) +data().HasUninitializedFields = false; +} else if (!Field->hasInClassInitializer() && !Field->isMutable()) { if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) { if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) data().HasUninitializedFields = true; diff --git a/clang/test/Sema/debug-84072.cpp b/clang/test/Sema/debug-84072.cpp new file mode 100644 index 00..e3a905db4c97cc --- /dev/null +++ b/clang/test/Sema/debug-84072.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s + +void Func(int x) { + switch (x) { +[[likely]] case 0: +case 1: + int i = 3; +case 2: + break; + } + +// switch (x) { +//case 0: +//case 1: +// int i = 3; +//case 2: +// break; +// } +} diff --git a/clang/test/SemaCXX/GH95854.cpp b/clang/test/SemaCXX/GH95854.cpp new file mode 100644 index 00..aa470c6ac8e5b4 --- /dev/null +++ b/clang/test/SemaCXX/GH95854.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s + +struct A { + union { +int n = 0; +int m; + }; +}; +const A a; + +struct B { + union { +struct { + int n = 5; + int m; +}; + }; +}; +const B b; // expected-error {{default initialization of an object of const type 'const B' without a user-provided default constructor}} + +struct S { + int i; + int j; +}; + +struct T { + T() = default; +}; + +struct C { + union { +S s; + }; +}; + +struct D { + union { +T s; + }; +}; + +const C c; // expected-error {{default initialization of an object of const type 'const C' without a user-provided default constructor}} +const D d; // expected-error {{default initialization of an object of const type 'const D' without a user-provided default constructor}} + +struct E { + union { +int n; +int m=0; + }; +}; +const E e; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)
Rajveer100 wrote: @Sirraide https://github.com/llvm/llvm-project/pull/96301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)
https://github.com/Artem-B edited https://github.com/llvm/llvm-project/pull/113017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make LazyOffsetPtr more portable (PR #112927)
thesamesam wrote: I appreciate it's not exactly a straightforward change given the discussion it provoked, but any chance you'd be okay with a backport to 19? Clang isn't really usable on ppc32 without this. We could pull it in just for ppc32 downstream but we generally dislike doing conditional patching. WDYT? https://github.com/llvm/llvm-project/pull/112927 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in fma function. (PR #113020)
@@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { Result.changeSign(); return true; + case Builtin::BI__builtin_fma: + case Builtin::BI__builtin_fmaf: + case Builtin::BI__builtin_fmal: + case Builtin::BI__builtin_fmaf128: { +APFloat Y(0.), Z(0.); +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluateFloat(E->getArg(1), Y, Info) || +!EvaluateFloat(E->getArg(2), Z, Info)) + return false; + +llvm::RoundingMode RM = getActiveRoundingMode(Info, E); +Result.multiply(Y, RM); +Result.add(Z, RM); tbaederr wrote: Shouldn't we check the status they return? And shouldn't this use `APFloat::fusedMultiplyAdd()`? https://github.com/llvm/llvm-project/pull/113020 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][doc] Fix typo in "translation unit" in analyzer doc CommandLineUsage.rst (PR #112966)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot2` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/3047 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 86362 of 86363 tests, 88 workers -- Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. FAIL: lld :: ELF/symbol-ordering-file-warnings.s (85808 of 86362) TEST 'lld :: ELF/symbol-ordering-file-warnings.s' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 2: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/symbol-ordering-file-warnings.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp1.o + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/symbol-ordering-file-warnings.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp1.o RUN: at line 3: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/Inputs/symbol-ordering-file-warnings1.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp2.o + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/Inputs/symbol-ordering-file-warnings1.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp2.o RUN: at line 4: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/Inputs/symbol-ordering-file-warnings2.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp3.o + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -filetype=obj -triple=x86_64-pc-linux /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/Inputs/symbol-ordering-file-warnings2.s -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/symbol-ordering-file-warnings.s.tmp3.o RUN: at line 5: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/ll
[clang] [clang] Make LazyOffsetPtr more portable (PR #112927)
glaubitz wrote: > I appreciate it's not exactly a straightforward change given the discussion > it provoked, but any chance you'd be okay with a backport to 19? Clang isn't > really usable on ppc32 without this. We could pull it in just for ppc32 > downstream but we generally dislike doing conditional patching. WDYT? > > cc @mgorny I agree. It would be great if this fix could be backported. https://github.com/llvm/llvm-project/pull/112927 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112816 >From 6b85331c4927c031fb8a937467cf62c5d0f80e64 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 05:03:22 +0200 Subject: [PATCH 1/4] [NFC][Clang] Fix enumerated mismatch warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix warning: llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3153:14: error: enumerated mismatch in conditional expression: ‘clang::diag::’ vs ‘clang::diag::’ [-Werror=enum-compare] 3152 | DS.isFriendSpecified() || NextToken().is(tok::kw_friend) | 3153 | ? diag::err_friend_concept | ^~ 3154 | : diag:: | 3155 | err_concept_decls_may_only_appear_in_global_namespace_scope); --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 78510e61a639fa..cb52629f9c61c7 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,9 +983,6 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; -def err_friend_concept : Error< - "friend declaration cannot be a concept">; - // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 883db838ca0147..d102a45f8c1ed2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,6 +3020,8 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts +def err_friend_concept : Error< + "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< >From 1733184c9a6fa8a375dec2c10f5456cfb86e9a57 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 14:58:27 +0200 Subject: [PATCH 2/4] cast instead --- clang/include/clang/Basic/DiagnosticParseKinds.td | 3 +++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 -- clang/lib/Parse/ParseDeclCXX.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index cb52629f9c61c7..78510e61a639fa 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -983,6 +983,9 @@ def warn_cxx23_variadic_friends : Warning< "variadic 'friend' declarations are incompatible with C++ standards before C++2c">, DefaultIgnore, InGroup; +def err_friend_concept : Error< + "friend declaration cannot be a concept">; + // C++11 default member initialization def ext_nonstatic_member_init : ExtWarn< "default member initializer for non-static data member is a C++11 " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d102a45f8c1ed2..883db838ca0147 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3020,8 +3020,6 @@ def err_c23_constexpr_pointer_not_null : Error< "constexpr pointer initializer is not null">; // C++ Concepts -def err_friend_concept : Error< - "friend declaration cannot be a concept">; def err_concept_decls_may_only_appear_in_global_namespace_scope : Error< "concept declarations may only appear in global or namespace scope">; def err_concept_no_parameters : Error< diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6f0f5a0311bc18..fb159eb997ce9d 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -3150,8 +3150,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( if (Tok.is(tok::kw_concept)) { Diag(Tok.getLocation(), DS.isFriendSpecified() || NextToken().is(tok::kw_friend) - ? diag::err_friend_concept - : diag:: + ? (unsigned)diag::err_friend_concept + : (unsigned)diag:: err_concept_decls_may_only_appear_in_global_namespace_scope); SkipUntil(tok::semi, tok::r
[clang] [NFC][Sema][OpenMP] Fix free-nonheap-object warning (PR #112942)
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112942 >From a01e0d660a1631c7b9a78d1a48dc6dc2080cc19a Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Fri, 18 Oct 2024 19:29:43 +0200 Subject: [PATCH] [NFC][Sema][OpenMP] Fix free-nonheap-object warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11. Fix warning In destructor ‘llvm::APInt::~APInt()’, inlined from ‘llvm::APInt::~APInt()’ at llvm-project/llvm/include/llvm/ADT/APInt.h:190:3, inlined from ‘llvm::APSInt::~APSInt()’ at llvm-project/llvm/include/llvm/ADT/APSInt.h:23:21, inlined from ‘bool checkOMPArraySectionConstantForReduction(clang::ASTContext&, const clang::ArraySectionExpr*, bool&, llvm::SmallVectorImpl&)’ at llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18357:45, inlined from ‘bool actOnOMPReductionKindClause(clang::Sema&, {anonymous}::DSAStackTy*, clang::OpenMPClauseKind, llvm::ArrayRef, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, const clang::DeclarationNameInfo&, llvm::ArrayRef, {anonymous}::ReductionData&)’ at llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18715:68: llvm-project/llvm/include/llvm/ADT/APInt.h:192:18: error: ‘void operator delete [](void*)’ called on a pointer to an unallocated object ‘1’ [-Werror=free-nonheap-object] 192 | delete[] U.pVal; | ^~~~ --- clang/lib/Sema/SemaOpenMP.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 0232745b3c19e5..fa81fc42c0ee53 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -18335,7 +18335,8 @@ static bool checkOMPArraySectionConstantForReduction( return false; // This is an array subscript which has implicit length 1! - ArraySizes.push_back(llvm::APSInt::get(1)); + llvm::APSInt ConstantOne = llvm::APSInt::get(1); + ArraySizes.push_back(ConstantOne); } else { Expr::EvalResult Result; if (!Length->EvaluateAsInt(Result, Context)) @@ -18354,7 +18355,8 @@ static bool checkOMPArraySectionConstantForReduction( if (!SingleElement) { while (const auto *TempASE = dyn_cast(Base)) { // Has implicit length 1! - ArraySizes.push_back(llvm::APSInt::get(1)); + llvm::APSInt ConstantOne = llvm::APSInt::get(1); + ArraySizes.push_back(ConstantOne); Base = TempASE->getBase()->IgnoreParenImpCasts(); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make LazyOffsetPtr more portable (PR #112927)
mgorny wrote: Doesn't it change ABI, though? https://github.com/llvm/llvm-project/pull/112927 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Allow overload of __builtin_amdgcn_mov/update_dpp (PR #112447)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/112447 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)
https://github.com/JOE1994 closed https://github.com/llvm/llvm-project/pull/113017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building `clang,llvm` at step 6 "test-openmp". Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7305 Here is the relevant piece of the build log for the reference ``` Step 6 (test-openmp) failure: test (failure) TEST 'libomp :: tasking/issue-94260-2.c' FAILED Exit Code: -11 Command Output (stdout): -- # RUN: at line 1 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp # note: command had no output on stdout or stderr # error: command failed with exit status: -11 -- Step 10 (Add check check-offload) failure: test (failure) TEST 'libomptarget :: amdgcn-amd-amdhsa :: offloading/schedule.c' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp-I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgp
[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
@@ -102,7 +102,7 @@ struct __aliasing_iterator_wrapper { _LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT { _Alias __val; - __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type)); + __builtin_memcpy(&__val, static_cast(std::__to_address(__base_)), sizeof(value_type)); philnik777 wrote: Why do you think it is UB? We're only inspecting the memory of the non-trivially copyable type. We're not round-tripping here or anything like that. https://github.com/llvm/llvm-project/pull/111434 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112424 >From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 15 Oct 2024 22:43:24 +0300 Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier for missing primary declarations --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAccess.cpp | 3 ++- clang/test/SemaCXX/enum.cpp | 8 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 817e3abef8d566..64ffdcde045a3a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,6 +517,8 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) +- Fixed an assertion failure when the default lexical access specifier was set for missing + primary declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index df6edb21a50dee..8b4a5b70669d84 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -MemberDecl->setAccess(LexicalAS); +if (LexicalAS != AS_none) + MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index 9c398cc8da886c..44042d8bf5cfc8 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -143,3 +143,11 @@ struct PR28903 { }) }; }; + +namespace GH112208 { +class C { + enum E { e = 0 }; + void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ +// expected-error {{unexpected ';' before ')'}} +}; +} >From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 18 Oct 2024 14:55:47 +0300 Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum forward declarations --- clang/docs/ReleaseNotes.rst | 3 +-- clang/lib/Sema/SemaAccess.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64ffdcde045a3a..3fd37663ca7bc6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -517,8 +517,7 @@ Bug Fixes to C++ Support certain situations. (#GH47400), (#GH90896) - Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441) - During the lookup for a base class name, non-type names are ignored. (#GH16855) -- Fixed an assertion failure when the default lexical access specifier was set for missing - primary declarations. (#GH112208) +- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 8b4a5b70669d84..df6edb21a50dee 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, AccessSpecifier LexicalAS) { if (!PrevMemberDecl) { // Use the lexical access specifier. -if (LexicalAS != AS_none) - MemberDecl->setAccess(LexicalAS); +MemberDecl->setAccess(LexicalAS); return false; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fece22c663d00c..9eb3d06289e88f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, << Name; Invalid = true; } + if (TUK == TagUseKind::Declaration && Name) +Invalid = true; } else if (!PrevDecl) { Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4a011ac - [Coverage] Introduce "partial fold" on BranchRegion (#112694)
Author: NAKAMURA Takumi Date: 2024-10-20T12:30:35+09:00 New Revision: 4a011ac84fa16f7eed34c309bdac5591d9553da7 URL: https://github.com/llvm/llvm-project/commit/4a011ac84fa16f7eed34c309bdac5591d9553da7 DIFF: https://github.com/llvm/llvm-project/commit/4a011ac84fa16f7eed34c309bdac5591d9553da7.diff LOG: [Coverage] Introduce "partial fold" on BranchRegion (#112694) Currently both True/False counts were folded. It lost the information, "It is True or False before folding." It prevented recalling branch counts in merging template instantiations. In `llvm-cov`, a folded branch is shown as: - `[True: n, Folded]` - `[Folded, False n]` In the case If `n` is zero, a branch is reported as "uncovered". This is distinguished from "folded" branch. When folded branches are merged, `Folded` may be dissolved. In the coverage map, either `Counter` is `Zero`. Currently both were `Zero`. Since "partial fold" has been introduced, either case in `switch` is omitted as `Folded`. Each `case:` in `switch` is reported as `[True: n, Folded]`, since `False` count doesn't show meaningful value. When `switch` doesn't have `default:`, `switch (Cond)` is reported as `[Folded, False: n]`, since `True` count was just the sum of `case`(s). `switch` with `default` can be considered as "the statement that doesn't have any `False`(s)". Added: Modified: clang/lib/CodeGen/CoverageMappingGen.cpp clang/test/CoverageMapping/branch-constfolded.cpp clang/test/CoverageMapping/if.cpp clang/test/CoverageMapping/macro-expansion.c clang/test/CoverageMapping/mcdc-scratch-space.c clang/test/CoverageMapping/mcdc-system-headers.cpp clang/test/CoverageMapping/switch.cpp clang/test/CoverageMapping/switchmacro.c llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h llvm/lib/ProfileData/Coverage/CoverageMapping.cpp llvm/test/tools/llvm-cov/branch-c-general.test llvm/tools/llvm-cov/CoverageExporterJson.cpp llvm/tools/llvm-cov/CoverageExporterLcov.cpp llvm/tools/llvm-cov/CoverageSummaryInfo.cpp llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp llvm/tools/llvm-cov/SourceCoverageViewText.cpp Removed: diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 577a0f571e16ea..0a63c50d44f4b7 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1098,12 +1098,6 @@ struct CounterCoverageMappingBuilder return ExitCount; } - /// Determine whether the given condition can be constant folded. - bool ConditionFoldsToBool(const Expr *Cond) { -Expr::EvalResult Result; -return (Cond->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext())); - } - /// Create a Branch Region around an instrumentable condition for coverage /// and add it to the function's SourceRegions. A branch region tracks a /// "True" counter and a "False" counter for boolean expressions that @@ -1133,13 +1127,15 @@ struct CounterCoverageMappingBuilder // Alternatively, we can prevent any optimization done via // constant-folding by ensuring that ConstantFoldsToSimpleInteger() in // CodeGenFunction.c always returns false, but that is very heavy-handed. - if (ConditionFoldsToBool(C)) -popRegions(pushRegion(Counter::getZero(), getStart(C), getEnd(C), - Counter::getZero(), BranchParams)); - else -// Otherwise, create a region with the True counter and False counter. -popRegions(pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt, - BranchParams)); + Expr::EvalResult Result; + if (C->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext())) { +if (Result.Val.getInt().getBoolValue()) + FalseCnt = Counter::getZero(); +else + TrueCnt = Counter::getZero(); + } + popRegions( + pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt, BranchParams)); } } @@ -1153,12 +1149,12 @@ struct CounterCoverageMappingBuilder /// Create a Branch Region around a SwitchCase for code coverage /// and add it to the function's SourceRegions. - void createSwitchCaseRegion(const SwitchCase *SC, Counter TrueCnt, - Counter FalseCnt) { + void createSwitchCaseRegion(const SwitchCase *SC, Counter TrueCnt) { // Push region onto RegionStack but immediately pop it (which adds it to // the function's SourceRegions) because it doesn't apply to any other // source other than the SwitchCase. -popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), FalseCnt)); +popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), + Counter::getZero())); } /// Check whether a region with bounds \c StartLoc and \c EndLoc @@ -1870,24 +1866,16 @@ struct CounterCoverageMappingBuilde
[clang] [llvm] [Coverage] Introduce "partial fold" on BranchRegion (PR #112694)
https://github.com/chapuni closed https://github.com/llvm/llvm-project/pull/112694 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling] Simplify code with StringMap::operator[] (NFC) (PR #113071)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/113071 None >From 8d9861a290a9bca4504c1c21345e04d92e2c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 19 Oct 2024 15:15:25 -0700 Subject: [PATCH] [Tooling] Simplify code with StringMap::operator[] (NFC) --- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp index 0cb96097415ea8..01b3be700b9fad 100644 --- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp +++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp @@ -335,10 +335,9 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code, // \p Offset: the start of the line following this include directive. void HeaderIncludes::addExistingInclude(Include IncludeToAdd, unsigned NextLineOffset) { - auto Iter = - ExistingIncludes.try_emplace(trimInclude(IncludeToAdd.Name)).first; - Iter->second.push_back(std::move(IncludeToAdd)); - auto &CurInclude = Iter->second.back(); + auto &Incs = ExistingIncludes[trimInclude(IncludeToAdd.Name)]; + Incs.push_back(std::move(IncludeToAdd)); + auto &CurInclude = Incs.back(); // The header name with quotes or angle brackets. // Only record the offset of current #include if we can insert after it. if (CurInclude.R.getOffset() <= MaxInsertOffset) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling] Simplify code with StringMap::operator[] (NFC) (PR #113071)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/113071.diff 1 Files Affected: - (modified) clang/lib/Tooling/Inclusions/HeaderIncludes.cpp (+3-4) ``diff diff --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp index 0cb96097415ea8..01b3be700b9fad 100644 --- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp +++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp @@ -335,10 +335,9 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code, // \p Offset: the start of the line following this include directive. void HeaderIncludes::addExistingInclude(Include IncludeToAdd, unsigned NextLineOffset) { - auto Iter = - ExistingIncludes.try_emplace(trimInclude(IncludeToAdd.Name)).first; - Iter->second.push_back(std::move(IncludeToAdd)); - auto &CurInclude = Iter->second.back(); + auto &Incs = ExistingIncludes[trimInclude(IncludeToAdd.Name)]; + Incs.push_back(std::move(IncludeToAdd)); + auto &CurInclude = Incs.back(); // The header name with quotes or angle brackets. // Only record the offset of current #include if we can insert after it. if (CurInclude.R.getOffset() <= MaxInsertOffset) { `` https://github.com/llvm/llvm-project/pull/113071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Coverage] Introduce "partial fold" on BranchRegion (PR #112694)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building `clang,llvm` at step 7 "Add check check-offload". Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/8580 Here is the relevant piece of the build log for the reference ``` Step 7 (Add check check-offload) failure: test (failure) TEST 'libomptarget :: amdgcn-amd-amdhsa :: sanitizer/kernel_crash_async.c' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp-I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa -O3 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa -O3 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # note: command had no output on stdout or stderr # RUN: at line 3 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=TRACE # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp # note: command had no output on stdout or stderr # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=TRACE # note: command had no output on stdout or stderr # RUN: at line 4 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=CHECK # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash /home/ompworker/bb
[clang] [clang-format] convert path to Windows path if user is using a MSYS2 shell (PR #111526)
BLumia wrote: Ping https://github.com/llvm/llvm-project/pull/111526 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/110569 >From fcadf4db481091314548eb9d79ea4d816a120d00 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 30 Sep 2024 10:12:01 +0100 Subject: [PATCH 1/2] [TBAA] Extend pointer TBAA to pointers of non-builtin types. Extend the logic added in 123c036bd361d (https://github.com/llvm/llvm-project/pull/76612) to support pointers to non-builtin types by using the mangled name of the canonical type. --- clang/lib/CodeGen/CodeGenTBAA.cpp | 16 +++ clang/test/CodeGen/tbaa-pointers.c| 38 +++ clang/test/CodeGen/tbaa-reference.cpp | 30 - 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 5b3393ec150e44..990a0ea8dafd72 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -221,21 +221,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { PtrDepth++; Ty = Ty->getPointeeType().getTypePtr(); } while (Ty->isPointerType()); -// TODO: Implement C++'s type "similarity" and consider dis-"similar" -// pointers distinct for non-builtin types. + +SmallString<256> TyName; if (isa(Ty)) { llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty); StringRef Name = cast( ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0)) ->getString(); + TyName = Name; +} else if (!isa(Ty)) { + // For non-builtin types use the mangled name of the canonical type. + llvm::raw_svector_ostream TyOut(TyName); + Context.createMangleContext()->mangleCanonicalTypeName(QualType(Ty, 0), + TyOut); +} + SmallString<256> OutName("p"); OutName += std::to_string(PtrDepth); OutName += " "; - OutName += Name; + OutName += TyName; return createScalarTypeNode(OutName, AnyPtr, Size); -} -return AnyPtr; } // Accesses to arrays are accesses to objects of their element types. diff --git a/clang/test/CodeGen/tbaa-pointers.c b/clang/test/CodeGen/tbaa-pointers.c index 8860b7042d0a25..2b6c2f1418b50f 100644 --- a/clang/test/CodeGen/tbaa-pointers.c +++ b/clang/test/CodeGen/tbaa-pointers.c @@ -116,10 +116,12 @@ void p2struct(struct S1 **ptr) { // COMMON-LABEL: define void @p2struct( // COMMON-SAME:ptr noundef [[PTR:%.+]]) // COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8 - // ENABLED-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR:!.+]] + // ENABLED-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[P2S1_TAG:!.+]] // DEFAULT-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] - // COMMON-NEXT:[[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] - // COMMON-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]] + // ENABLED-NEXT:[[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[P2S1_TAG]] + // DEFAULT-NEXT:[[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] + // ENABLED-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[P1S1_TAG:!.+]] + // DEFAULT-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]] // COMMON-NEXT:ret void // *ptr = 0; @@ -129,9 +131,10 @@ void p2struct_const(struct S1 const **ptr) { // COMMON-LABEL: define void @p2struct_const( // COMMON-SAME:ptr noundef [[PTR:%.+]]) // COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8 - // COMMON-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] + // COMMON-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR:!.+]] // COMMON-NEXT:[[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] - // COMMON-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]] + // ENABLED-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[P1S1_TAG]] + // DEFAULT-NEXT:store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]] // COMMON-NEXT:ret void // *ptr = 0; @@ -145,10 +148,14 @@ void p2struct2(struct S2 *ptr) { // COMMON-LABEL: define void @p2struct2( // COMMON-SAME:ptr noundef [[PTR:%.+]]) // COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8 - // COMMON-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] - // COMMON-NEXT:[[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]] - // COMMON-NEXT:[[S:%.+]] = getelementptr inbounds nuw %struct.S2, ptr [[BASE]], i32 0, i32 0 - // COMMON-NEXT:store ptr null, ptr [[S]], align 8, !tbaa [[S2_S_TAG:!.+]] + // ENABLED-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[P1S2_TAG:!.+]] + // ENABLED-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[P1S2_TAG]] + // ENABLED-NEXT: [[S:%.+]] = getelementptr
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
HighCommander4 wrote: Thanks. The buildkite failure looks unrelated (it's a `clang-move` test, and this patch only touches `clangd` code), so I will go ahead and merge this. https://github.com/llvm/llvm-project/pull/95712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] dde26e3 - [libunwind][AIX] Call dlclose only when dlsym() fails (#112768)
Author: Xing Xue Date: 2024-10-19T18:41:06-04:00 New Revision: dde26e361f50df4b999ac117222c74f2c100f817 URL: https://github.com/llvm/llvm-project/commit/dde26e361f50df4b999ac117222c74f2c100f817 DIFF: https://github.com/llvm/llvm-project/commit/dde26e361f50df4b999ac117222c74f2c100f817.diff LOG: [libunwind][AIX] Call dlclose only when dlsym() fails (#112768) The personality routine `__xlcxx_personality_v0` in `libc++abi` is hard-coded in the unwinder as the handler for EH in applications generated by the legacy IBM C++ compiler. The symbol is resolved dynamically using `dlopen` to avoid a hard dependency of `libunwind` on `libc++abi` for cases such as non-C++ applications. However, `dlclose` was incorrectly called after `dlsym` succeeded, potentially invalidating the function pointer obtained from `dlsym` when the memory allocated for the `dlopen` is reclaimed. This PR changes to call `dlclose` only when `dlsym` fails. Added: Modified: libunwind/src/UnwindCursor.hpp Removed: diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 2a3aba28fb6ca5..32e6fb43d988ff 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -2150,9 +2150,9 @@ bool UnwindCursor::getInfoFromTBTable(pint_t pc, R ®isters) { dlsym(libHandle, "__xlcxx_personality_v0")); if (xlcPersonalityV0 == NULL) { _LIBUNWIND_TRACE_UNWINDING("dlsym() failed with errno=%d\n", errno); + dlclose(libHandle); assert(0 && "dlsym() failed"); } -dlclose(libHandle); errno = saveErrno; } xlcPersonalityV0InitLock.unlock(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86][RFC] Refactor the SSE intrinsics constexpr tests to simplify future expansion (PR #112578)
https://github.com/boomanaiden154 approved this pull request. This seems reasonable enough modulo refactoring test macros to a common spot if reasonable. This is certainly a lot cleaner than throwing all the constant expression tests at the end of the file. https://github.com/llvm/llvm-project/pull/112578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)
boomanaiden154 wrote: > Because only part of the doc is generated by dump_format_style.py. It should still be possible to only include the non-generated parts in the repo and then modify the script to add all the generated components on afterwards as a build step? Not sure if I'm missing something here. https://github.com/llvm/llvm-project/pull/111513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
https://github.com/HighCommander4 closed https://github.com/llvm/llvm-project/pull/95712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)
github-actions[bot] wrote: @torshepherd Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/95712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind][AIX] Call dlclose only when dlsym() fails (PR #112768)
https://github.com/xingxue-ibm closed https://github.com/llvm/llvm-project/pull/112768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86][RFC] Refactor the SSE intrinsics constexpr tests to simplify future expansion (PR #112578)
https://github.com/boomanaiden154 edited https://github.com/llvm/llvm-project/pull/112578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/112081 >From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 12 Oct 2024 08:27:51 +0300 Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw expressions --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaChecking.cpp | 3 +++ clang/test/SemaCXX/conditional-expr.cpp | 7 +++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 337e3fc10bf49d..2ab13640bfa53c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -512,6 +512,7 @@ Bug Fixes to C++ Support and undeclared templates. (#GH107047, #GH49093) - Clang no longer crashes when a lambda contains an invalid block declaration that contains an unexpanded parameter pack. (#GH109148) +- Fixed assertion failure in range calculations for conditional throw expressions (#GH111854) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2bcb930acdcb57..b3d88f053872c1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, return IntRange(BitField->getBitWidthValue(C), BitField->getType()->isUnsignedIntegerOrEnumerationType()); + if (GetExprType(E)->isVoidType()) +return IntRange{0, true}; + return IntRange::forValueOfType(C, GetExprType(E)); } diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 01effaa189322b..8f17555fd806ff 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -429,3 +429,10 @@ void g() { long e = a = b ? throw 0 : throw 1; } } // namespace PR46484 + +namespace GH111854 { +void f() { + (true ? throw 0 : 0) <= 0; // expected-warning {{relational comparison result unused}} + (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison result unused}} +} +} >From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 19 Oct 2024 00:00:19 +0300 Subject: [PATCH 2/2] change return type to nullable for handling invalid ranges in integer expression evaluation --- clang/lib/Sema/SemaChecking.cpp | 198 +++- 1 file changed, 118 insertions(+), 80 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b3d88f053872c1..2ca342a6065550 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) { ///particular, assume that arithmetic on narrower types doesn't leave ///those types. If \c false, return a range including all possible ///result values. -static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, - bool InConstantContext, bool Approximate) { +static std::optional TryGetExprRange(ASTContext &C, const Expr *E, + unsigned MaxWidth, + bool InConstantContext, + bool Approximate) { E = E->IgnoreParens(); // Try a full evaluation first. @@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, // being of the new, wider type. if (const auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue) - return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, - Approximate); + return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext, + Approximate); IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE)); @@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth, if (!isIntegerCast) return OutputTypeRange; -IntRange SubRange = GetExprRange(C, CE->getSubExpr(), - std::min(MaxWidth, OutputTypeRange.Width), - InConstantContext, Approximate); +std::optional SubRange = TryGetExprRange( +C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width), +InConstantContext, Approximate); +if (!SubRange) + return std::nullopt; // Bail out if the subexpr's range is as wide as the cast type. -if (SubRange.Width >= OutputTypeRange.Width) +if (SubRange->Width >= OutputTypeRange.Width) return OutputTypeRange; // Otherwise, we take the smaller width, and we're non-negative if // either the output type or the subexpr is. -
[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)
https://github.com/benshi001 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/111290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][llvm][SPIR-V] Explicitly encode native integer widths for SPIR-V (PR #110695)
@@ -1,12 +1,14 @@ ; This test aims to check ability to support "Arithmetic with Overflow" intrinsics ; in the special case when those intrinsics are being generated by the CodeGenPrepare; -; pass during translations with optimization (note -O3 in llc arguments). +; pass during translations with optimization (note -disable-lsr, to inhibit +; strength reduction pre-empting with a more preferable match for this pattern +; in llc arguments). -; RUN: llc -O3 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s -; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %} +; RUN: llc -O3 -disable-lsr -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s arsenm wrote: I think this should be updated to reflect the reality https://github.com/llvm/llvm-project/pull/110695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits