[clang] [llvm] [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF (PR #91423)
eddyz87 wrote: > Looks like some changes are duplicate from #91422, e.g., > llvm/lib/Bitcode/Reader/MetadataLoader.cpp. There are some other files are > duplicated as well. Could you do a cleanup here? This will make it easy to > compare to https://reviews.llvm.org/D143967. As far as I understand, this is how one makes "revision stacks" after migration from Phabriactor to Github: I have three branches, one for each patch I want to land, each branch is forked from a previous one. Until first branch is landed Github will show two pending commits (one from the previous branch, one from this branch). To check changes specific to this branch please refer to the top-most commit of the branch: https://github.com/llvm/llvm-project/pull/91423/commits/4f3fbf2e4d831ea92d3bd5170e5e3c14b36fff5c Please let me know if I understand the new process in a wrong way. https://github.com/llvm/llvm-project/pull/91423 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -0,0 +1,162 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \ +// RUN: -DWIN -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN + +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \ +// RUN: -emit-llvm -o - %s | FileCheck %s --check-prefixes=LNX + +#ifdef WIN +#define INFINITY ((float)(1e+300 * 1e+300)) +#define NAN (-(float)(INFINITY * 0.0F)) +#else +#define NAN (__builtin_nanf("")) +#define INFINITY (__builtin_inff()) +#endif + +// WIN-LABEL: define dso_local noundef i32 @_Z4funcv( +// WIN-SAME: ) #[[ATTR0:[0-9]+]] { +// WIN-NEXT: entry: +// WIN-NEXT:[[I:%.*]] = alloca i32, align 4 +// WIN-NEXT:[[MIN1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:[[MAX1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:[[FREXP1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:store i32 0, ptr [[I]], align 4 +// WIN-NEXT:store double 1.30e+00, ptr [[MIN1]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[MIN2]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[MIN3]], align 8 +// WIN-NEXT:store float 0xFFF8, ptr [[MIN4]], align 4 +// WIN-NEXT:store float -1.00e+00, ptr [[MIN5]], align 4 +// WIN-NEXT:store float 0xFFF0, ptr [[MIN6]], align 4 +// WIN-NEXT:store float 0.00e+00, ptr [[MIN7]], align 4 +// WIN-NEXT:store x86_fp80 0xK4005F6E978D4FDF3B646, ptr [[MIN8]], align 16 +// WIN-NEXT:store double 1.524000e+01, ptr [[MAX1]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[MAX2]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[MAX3]], align 8 +// WIN-NEXT:store float -1.00e+00, ptr [[MAX4]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[MAX5]], align 4 +// WIN-NEXT:store float 0.00e+00, ptr [[MAX6]], align 4 +// WIN-NEXT:store float 0xFFF8, ptr [[MAX7]], align 4 +// WIN-NEXT:store x86_fp80 0xK4008C540C49BA5E353F8, ptr [[MAX8]], align 16 +// WIN-NEXT:store double 0x3FEEDCCD, ptr [[FREXP1]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[FREXP2]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[FREXP3]], align 8 +// WIN-NEXT:store float 0xFFF8, ptr [[FREXP4]], align 4 +// WIN-NEXT:store float 0x7FF8, ptr [[FREXP5]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[FREXP6]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[FREXP7]], align 4 +// WIN-NEXT:store x86_fp80 0xK3FFE81A9FBE76C8B4396, ptr [[FREXP8]], align 16 +// WIN-NEXT:ret i32 0 +// +// LNX-LABEL: define dso_local noundef i32 @_Z4funcv( +// LNX-SAME: ) #[[ATTR0:[0-9]+]] { +// LNX-NEXT: entry: +// LNX-NEXT:[[I:%.*]] = alloca i32, align 4 +// LNX-NEXT:[[MIN1:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN2:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN3:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN4:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN5:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN6:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN7:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN8:%.*]] = alloca x86_fp80, align 16 +// LNX-NEXT:[[MAX1:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX2:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX3:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX4:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX5:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX6:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX7:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX8:%.*]] = alloca x86_fp80, align 16 +// LNX-NEXT:[[FREXP1:%.*]] = alloca double, align 8 +// LNX-NEXT:
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -DWIN -verify -std=c++23 -fsyntax-only %s +// RUN: %clang_cc1 -verify -std=c++23 -fsyntax-only %s hubert-reinterpretcast wrote: Duplicate this run line for `-std=c++20`. Modify the test to use the `__builtin_*` functions only for the `-std=c++20` case. Use the non-`__builtin_*` functions for the `-std=c++23` case. https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -14683,6 +14710,23 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { default: return false; + case Builtin::BI__builtin_frexp: hubert-reinterpretcast wrote: The non-`__builtin_`-prefixed cases need to be added in as per @philnik777's comment (https://github.com/llvm/llvm-project/pull/88978#discussion_r1582059951). Same for the other two function families. Some more thought is needed on how to handle the non-`__builtin_`-prefixed cases under non-C++23-or-higher language modes. The specific implications of those functions being non-`constexpr` under said modes (as required, for C++, by https://wg21.link/constexpr.functions) may determine the solution to apply in this PR. https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -0,0 +1,162 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \ +// RUN: -DWIN -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN + +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \ +// RUN: -emit-llvm -o - %s | FileCheck %s --check-prefixes=LNX + +#ifdef WIN +#define INFINITY ((float)(1e+300 * 1e+300)) +#define NAN (-(float)(INFINITY * 0.0F)) +#else +#define NAN (__builtin_nanf("")) +#define INFINITY (__builtin_inff()) +#endif + +// WIN-LABEL: define dso_local noundef i32 @_Z4funcv( +// WIN-SAME: ) #[[ATTR0:[0-9]+]] { +// WIN-NEXT: entry: +// WIN-NEXT:[[I:%.*]] = alloca i32, align 4 +// WIN-NEXT:[[MIN1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MIN4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MIN8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:[[MAX1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[MAX4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[MAX8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:[[FREXP1:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP2:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP3:%.*]] = alloca double, align 8 +// WIN-NEXT:[[FREXP4:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP5:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP6:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP7:%.*]] = alloca float, align 4 +// WIN-NEXT:[[FREXP8:%.*]] = alloca x86_fp80, align 16 +// WIN-NEXT:store i32 0, ptr [[I]], align 4 +// WIN-NEXT:store double 1.30e+00, ptr [[MIN1]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[MIN2]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[MIN3]], align 8 +// WIN-NEXT:store float 0xFFF8, ptr [[MIN4]], align 4 +// WIN-NEXT:store float -1.00e+00, ptr [[MIN5]], align 4 +// WIN-NEXT:store float 0xFFF0, ptr [[MIN6]], align 4 +// WIN-NEXT:store float 0.00e+00, ptr [[MIN7]], align 4 +// WIN-NEXT:store x86_fp80 0xK4005F6E978D4FDF3B646, ptr [[MIN8]], align 16 +// WIN-NEXT:store double 1.524000e+01, ptr [[MAX1]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[MAX2]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[MAX3]], align 8 +// WIN-NEXT:store float -1.00e+00, ptr [[MAX4]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[MAX5]], align 4 +// WIN-NEXT:store float 0.00e+00, ptr [[MAX6]], align 4 +// WIN-NEXT:store float 0xFFF8, ptr [[MAX7]], align 4 +// WIN-NEXT:store x86_fp80 0xK4008C540C49BA5E353F8, ptr [[MAX8]], align 16 +// WIN-NEXT:store double 0x3FEEDCCD, ptr [[FREXP1]], align 8 +// WIN-NEXT:store double 0.00e+00, ptr [[FREXP2]], align 8 +// WIN-NEXT:store double -0.00e+00, ptr [[FREXP3]], align 8 +// WIN-NEXT:store float 0xFFF8, ptr [[FREXP4]], align 4 +// WIN-NEXT:store float 0x7FF8, ptr [[FREXP5]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[FREXP6]], align 4 +// WIN-NEXT:store float 0x7FF0, ptr [[FREXP7]], align 4 +// WIN-NEXT:store x86_fp80 0xK3FFE81A9FBE76C8B4396, ptr [[FREXP8]], align 16 +// WIN-NEXT:ret i32 0 +// +// LNX-LABEL: define dso_local noundef i32 @_Z4funcv( +// LNX-SAME: ) #[[ATTR0:[0-9]+]] { +// LNX-NEXT: entry: +// LNX-NEXT:[[I:%.*]] = alloca i32, align 4 +// LNX-NEXT:[[MIN1:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN2:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN3:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MIN4:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN5:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN6:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN7:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MIN8:%.*]] = alloca x86_fp80, align 16 +// LNX-NEXT:[[MAX1:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX2:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX3:%.*]] = alloca double, align 8 +// LNX-NEXT:[[MAX4:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX5:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX6:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX7:%.*]] = alloca float, align 4 +// LNX-NEXT:[[MAX8:%.*]] = alloca x86_fp80, align 16 +// LNX-NEXT:[[FREXP1:%.*]] = alloca double, align 8 +// LNX-NEXT:
[clang] [llvm] [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF (PR #91423)
yonghong-song wrote: Looks like some changes are duplicate from https://github.com/llvm/llvm-project/pull/91422, e.g., llvm/lib/Bitcode/Reader/MetadataLoader.cpp. There are some other files are duplicated as well. Could you do a cleanup here? This will make it easy to compare to https://reviews.llvm.org/D143967. https://github.com/llvm/llvm-project/pull/91423 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/92501 >From 87cfc8234e1294dedc103b9bcd2b7d9d31874c4a Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Thu, 16 May 2024 23:24:13 -0700 Subject: [PATCH 1/7] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. When a base class B has a deref function which calls delete operator on a derived class D, don't emit a warning for B even if it did not have a virtual destructor. --- .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 140 - .../ref-cntbl-base-virtual-dtor-templates.cpp | 196 +- 2 files changed, 330 insertions(+), 6 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp index 7f4c3a7b787e8..36ab581f1edbd 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp @@ -11,16 +11,128 @@ #include "PtrTypesSemantics.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/StmtVisitor.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" +#include "llvm/ADT/DenseSet.h" #include using namespace clang; using namespace ento; namespace { + +class DerefAnalysisVisitor +: public ConstStmtVisitor { + // Returns true if any of child statements return true. + bool VisitChildren(const Stmt *S) { +for (const Stmt *Child : S->children()) { + if (Child && Visit(Child)) +return true; +} +return false; + } + + bool VisitBody(const Stmt *Body) { +if (!Body) + return false; + +auto [It, IsNew] = VisitedBody.insert(Body); +if (!IsNew) // This body is recursive + return false; + +return Visit(Body); + } + +public: + DerefAnalysisVisitor(const TemplateArgumentList , + const CXXRecordDecl *ClassDecl) +: ArgList() +, ClassDecl(ClassDecl) + { } + + DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) +: ClassDecl(ClassDecl) + { } + + bool HasSpecializedDelete(CXXMethodDecl *Decl) { +if (auto *Tmpl = Decl->getTemplateInstantiationPattern()) + return VisitBody(Tmpl->getBody()); +return VisitBody(Decl->getBody()); + } + + bool VisitCallExpr(const CallExpr *CE) { +auto *Callee = CE->getCallee(); +while (auto *Expr = dyn_cast(Callee)) + Callee = Expr->getSubExpr(); +if (auto *DeclRef = dyn_cast(Callee)) { + auto *Decl = DeclRef->getDecl(); + if (auto *VD = dyn_cast(Decl)) { +if (auto *Init = VD->getInit()) { + if (auto *Lambda = dyn_cast(Init)) +return VisitBody(Lambda->getBody()); +} + } else if (auto *FD = dyn_cast(Decl)) +return VisitBody(FD->getBody()); +} +return false; + } + + bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) { +auto *Callee = MCE->getMethodDecl(); +if (!Callee) + return false; +return VisitBody(Callee->getBody()); + } + + bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) { +auto *Arg = E->getArgument(); +while (Arg) { + if (auto *Paren = dyn_cast(Arg)) +Arg = Paren->getSubExpr(); + else if (auto *Cast = dyn_cast(Arg)) { +Arg = Cast->getSubExpr(); +auto CastType = Cast->getType(); +if (auto *PtrType = dyn_cast(CastType)) { + auto PointeeType = PtrType->getPointeeType(); + while (auto *ET = dyn_cast(PointeeType)) { +if (ET->isSugared()) + PointeeType = ET->desugar(); + } + if (auto *ParmType = dyn_cast(PointeeType)) { +if (ArgList) { + auto ParmIndex = ParmType->getIndex(); + auto Type = ArgList->get(ParmIndex).getAsType(); + if (auto *RD = dyn_cast(Type)) { +if (RD->getDecl() == ClassDecl) + return true; + } +} + } else if (auto *RD = dyn_cast(PointeeType)) { +if (RD->getDecl() == ClassDecl) + return true; + } +} + } else +break; +} +return false; + } + + bool VisitStmt(const Stmt *S) { return VisitChildren(S); } + + // Return false since the contents of lambda isn't necessarily executed. + // If it is executed, VisitCallExpr above will visit its body. + bool VisitLambdaExpr(const LambdaExpr *) { return false; } + +private: + const TemplateArgumentList* ArgList { nullptr }; + const CXXRecordDecl* ClassDecl; + llvm::DenseSet VisitedBody; +}; + class RefCntblBaseVirtualDtorChecker : public Checker> { private: @@ -91,8 +203,6 @@ class
[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/92501 >From 87cfc8234e1294dedc103b9bcd2b7d9d31874c4a Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Thu, 16 May 2024 23:24:13 -0700 Subject: [PATCH 1/6] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. When a base class B has a deref function which calls delete operator on a derived class D, don't emit a warning for B even if it did not have a virtual destructor. --- .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 140 - .../ref-cntbl-base-virtual-dtor-templates.cpp | 196 +- 2 files changed, 330 insertions(+), 6 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp index 7f4c3a7b787e8..36ab581f1edbd 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp @@ -11,16 +11,128 @@ #include "PtrTypesSemantics.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/StmtVisitor.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" +#include "llvm/ADT/DenseSet.h" #include using namespace clang; using namespace ento; namespace { + +class DerefAnalysisVisitor +: public ConstStmtVisitor { + // Returns true if any of child statements return true. + bool VisitChildren(const Stmt *S) { +for (const Stmt *Child : S->children()) { + if (Child && Visit(Child)) +return true; +} +return false; + } + + bool VisitBody(const Stmt *Body) { +if (!Body) + return false; + +auto [It, IsNew] = VisitedBody.insert(Body); +if (!IsNew) // This body is recursive + return false; + +return Visit(Body); + } + +public: + DerefAnalysisVisitor(const TemplateArgumentList , + const CXXRecordDecl *ClassDecl) +: ArgList() +, ClassDecl(ClassDecl) + { } + + DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) +: ClassDecl(ClassDecl) + { } + + bool HasSpecializedDelete(CXXMethodDecl *Decl) { +if (auto *Tmpl = Decl->getTemplateInstantiationPattern()) + return VisitBody(Tmpl->getBody()); +return VisitBody(Decl->getBody()); + } + + bool VisitCallExpr(const CallExpr *CE) { +auto *Callee = CE->getCallee(); +while (auto *Expr = dyn_cast(Callee)) + Callee = Expr->getSubExpr(); +if (auto *DeclRef = dyn_cast(Callee)) { + auto *Decl = DeclRef->getDecl(); + if (auto *VD = dyn_cast(Decl)) { +if (auto *Init = VD->getInit()) { + if (auto *Lambda = dyn_cast(Init)) +return VisitBody(Lambda->getBody()); +} + } else if (auto *FD = dyn_cast(Decl)) +return VisitBody(FD->getBody()); +} +return false; + } + + bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) { +auto *Callee = MCE->getMethodDecl(); +if (!Callee) + return false; +return VisitBody(Callee->getBody()); + } + + bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) { +auto *Arg = E->getArgument(); +while (Arg) { + if (auto *Paren = dyn_cast(Arg)) +Arg = Paren->getSubExpr(); + else if (auto *Cast = dyn_cast(Arg)) { +Arg = Cast->getSubExpr(); +auto CastType = Cast->getType(); +if (auto *PtrType = dyn_cast(CastType)) { + auto PointeeType = PtrType->getPointeeType(); + while (auto *ET = dyn_cast(PointeeType)) { +if (ET->isSugared()) + PointeeType = ET->desugar(); + } + if (auto *ParmType = dyn_cast(PointeeType)) { +if (ArgList) { + auto ParmIndex = ParmType->getIndex(); + auto Type = ArgList->get(ParmIndex).getAsType(); + if (auto *RD = dyn_cast(Type)) { +if (RD->getDecl() == ClassDecl) + return true; + } +} + } else if (auto *RD = dyn_cast(PointeeType)) { +if (RD->getDecl() == ClassDecl) + return true; + } +} + } else +break; +} +return false; + } + + bool VisitStmt(const Stmt *S) { return VisitChildren(S); } + + // Return false since the contents of lambda isn't necessarily executed. + // If it is executed, VisitCallExpr above will visit its body. + bool VisitLambdaExpr(const LambdaExpr *) { return false; } + +private: + const TemplateArgumentList* ArgList { nullptr }; + const CXXRecordDecl* ClassDecl; + llvm::DenseSet VisitedBody; +}; + class RefCntblBaseVirtualDtorChecker : public Checker> { private: @@ -91,8 +203,6 @@ class
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -DWIN -verify -std=c++23 -fsyntax-only %s +// RUN: %clang_cc1 -verify -std=c++23 -fsyntax-only %s + +// expected-no-diagnostics + + +#ifdef WIN +#define INFINITY ((float)(1e+300 * 1e+300)) +#define NAN (-(float)(INFINITY * 0.0F)) +#else +#define NAN (__builtin_nanf("")) +#define INFINITY (__builtin_inff()) +#endif + +extern "C" void abort() noexcept; +extern "C" int write(int, const void*, unsigned long); + +#define assert(condition) \ + do { \ +if (!(condition)) {\ + write(2, "Assertion failed: ", 18); \ + write(2, #condition, sizeof(#condition) - 1);\ + write(2, "\n", 1); \ + abort(); \ +} \ + } while (false) + +int main() { +int i; + +// fmin +static_assert(__builtin_fmin(15.24, 1.3) == 1.3, ""); +static_assert(__builtin_fmin(-0.0, +0.0) == -0.0, ""); +static_assert(__builtin_fmin(+0.0, -0.0) == -0.0, ""); +assert(__builtin_isnan(__builtin_fminf(NAN,NAN))); +assert(__builtin_isnan(__builtin_fminf(NAN, -1))); +assert(__builtin_isnan(__builtin_fminf(-INFINITY, 0))); +assert(__builtin_iszero(__builtin_fminf(+INFINITY, 0))); + +// frexp +static_assert(__builtin_frexp(123.45, ) == 0.9644531250002); hubert-reinterpretcast wrote: Here is an example of checking both the fraction and exponent values by "identity" instead of by comparisons. ```cpp template constexpr bool is_same_val = false; template constexpr bool is_same_val = true; template struct FrexpResult { T fraction; int exponent; }; template constexpr auto simulateFrexp(T value) { FrexpResult result; result.fraction = __builtin_frexp(value, ); return result; } static_assert(is_same_val); ``` https://godbolt.org/z/Whx6o5Y7E https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
hubert-reinterpretcast wrote: Re: https://github.com/llvm/llvm-project/pull/88978#discussion_r1578762448 > It means that INT_MAX and INT_MIN is fine (based on the wording). The committee reflector discussion reached a conclusion that this behaviour is okay. Implementations need not agree on the values. Indeed, an implementation is not required to consistently produce the same value. https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { return true; } + case Builtin::BIfmin: + case Builtin::BIfminf: hubert-reinterpretcast wrote: At the Clang C/C++ Language Workgroup call on 2024-05-15, it was agreed that `-fno-builtin[-*]` should remain capable of disabling built-in treatment even when that treatment would be required for conformance w.r.t. `constexpr` behaviour of functions shared with C. For me, the first expectation for this PR (on that subject) is an update to the documentation of `-fno-builtin[-*]`. @AaronBallman @ldionne, I am no sure how we want to handle this w.r.t. documenting the C++23 implementation status. Does it go in both the Clang documentation (for the functions shared with C) and the libc++ documentation (for the overloads added by C++)? https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)
@@ -36,7 +36,7 @@ namespace InExpr { // These are valid expressions. foo(0); +foo(0); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}} foo(false); shafik wrote: It is a shame we don't catch this one but neither does gcc https://github.com/llvm/llvm-project/pull/92200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: The leak via `clang::Parser::ParseLexedCAttribute` is ```c++ LA.Toks.push_back(AttrEnd); ``` and the leak via `clang::Parser::ParseGNUAttributes` is ``` LateParsedAttribute *LA = new LateParsedAttribute(this, *AttrName, AttrNameLoc); ``` which is really old code so I doubt this is directly responsible for the leak. I'm a little confused because LSan is telling us that these are indirect leaks which means "reachable from other leaked blocks" but LSan isn't showing any direct leaks (not reachable from anywhere). This might suggest the leak is some sort of cycle (multiple objects leaked that point to each other). https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: Hmm. Apparently there's a memory leak. https://lab.llvm.org/buildbot/#/builders/239/builds/7043 ``` -- Testing: 79948 of 79949 tests, 48 workers -- Testing: FAIL: Clang :: AST/attr-counted-by-late-parsed-struct-ptrs.c (480 of 79948) TEST 'Clang :: AST/attr-counted-by-late-parsed-struct-ptrs.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang -cc1 -internal-isystem /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/19/include -nostdsysteminc -fexperimental-late-parse-attributes /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c -ast-dump | /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c + /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang -cc1 -internal-isystem /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/19/include -nostdsysteminc -fexperimental-late-parse-attributes /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c -ast-dump + /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c = ==1477834==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 432 byte(s) in 2 object(s) allocated from: #0 0xbdec8684 in malloc /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3 #1 0xc36532a8 in safe_malloc /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18 #2 0xc36532a8 in llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/SmallVector.cpp:143:15 #3 0xc82d9960 in grow_pod /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:151:11 #4 0xc82d9960 in grow /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:538:41 #5 0xc82d9960 in reserveForParamAndGetAddressImpl > /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:256:11 #6 0xc82d9960 in reserveForParamAndGetAddress /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:543:12 #7 0xc82d9960 in push_back /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:575:23 #8 0xc82d9960 in clang::Parser::ParseLexedCAttribute(clang::Parser::LateParsedAttribute&, clang::ParsedAttributes*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:4943:11 #9 0xc82db118 in clang::Parser::ParseStructUnionBody(clang::SourceLocation, clang::TypeSpecifierType, clang::RecordDecl*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:5128:5 #10 0xc827170c in clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:2275:7 #11 0xc82c4734 in clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:4598:7 #12 0xc81b99dc in ParseDeclarationSpecifiers /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/include/clang/Parse/Parser.h:2495:12 #13 0xc81b99dc in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/Parser.cpp:1153:3 #14 0xc81b8ffc in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/Parser.cpp:1271:12 #15 0xc81b63e4 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*)
[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)
delcypher wrote: Hmm. Apparently there's a memory leak. https://lab.llvm.org/buildbot/#/builders/239/builds/7043 ``` -- Testing: 79948 of 79949 tests, 48 workers -- Testing: FAIL: Clang :: AST/attr-counted-by-late-parsed-struct-ptrs.c (480 of 79948) TEST 'Clang :: AST/attr-counted-by-late-parsed-struct-ptrs.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang -cc1 -internal-isystem /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/19/include -nostdsysteminc -fexperimental-late-parse-attributes /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c -ast-dump | /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c + /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang -cc1 -internal-isystem /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/19/include -nostdsysteminc -fexperimental-late-parse-attributes /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c -ast-dump + /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c = ==1477834==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 432 byte(s) in 2 object(s) allocated from: #0 0xbdec8684 in malloc /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3 #1 0xc36532a8 in safe_malloc /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18 #2 0xc36532a8 in llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/SmallVector.cpp:143:15 #3 0xc82d9960 in grow_pod /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:151:11 #4 0xc82d9960 in grow /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:538:41 #5 0xc82d9960 in reserveForParamAndGetAddressImpl > /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:256:11 #6 0xc82d9960 in reserveForParamAndGetAddress /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:543:12 #7 0xc82d9960 in push_back /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:575:23 #8 0xc82d9960 in clang::Parser::ParseLexedCAttribute(clang::Parser::LateParsedAttribute&, clang::ParsedAttributes*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:4943:11 #9 0xc82db118 in clang::Parser::ParseStructUnionBody(clang::SourceLocation, clang::TypeSpecifierType, clang::RecordDecl*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:5128:5 #10 0xc827170c in clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:2275:7 #11 0xc82c4734 in clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/ParseDecl.cpp:4598:7 #12 0xc81b99dc in ParseDeclarationSpecifiers /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/include/clang/Parse/Parser.h:2495:12 #13 0xc81b99dc in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/Parser.cpp:1153:3 #14 0xc81b8ffc in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Parse/Parser.cpp:1271:12 #15 0xc81b63e4 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*)
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), changpeng wrote: > Something like that, yes. Thanks. Updated. Should be closer! https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng updated https://github.com/llvm/llvm-project/pull/92612 >From 2468a85a47499d90a99610846c632332eb7307b8 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 15:13:07 -0700 Subject: [PATCH 1/2] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/90048), there is a bug in removeAddrSpaceQualType() for arrays. Arrays are weird because qualifiers on the element type also count as qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar on arrays. This results in an infinite loop in removeAddrSpaceQualType. To fix the issue, we use ASTContext::getUnqualifiedArrayType, which strips the qualifier off the element type, then reconstruct the array type. --- clang/lib/CodeGen/CGExprAgg.cpp | 3 ++- .../array-type-infinite-loop.clcpp| 25 +++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// CHECK-SAME: ptr nocapture noundef readonly align 8 [[IN:%.*]], ptr nocapture noundef writeonly align 8 [[OUT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual [[META4:![0-9]+]] !kernel_arg_type [[META5:![0-9]+]] !kernel_arg_base_type [[META5]] !kernel_arg_type_qual [[META6:![0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. >From 17ac766cdcbf22af685b89b9a054a22afb42f46e Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 18:20:06 -0700 Subject: [PATCH 2/2] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType Fix ASTContext::removeAddrSpaceQualType() --- clang/include/clang/AST/ASTContext.h | 2 +- clang/lib/AST/ASTContext.cpp | 9 - clang/lib/CodeGen/CGExprAgg.cpp | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index e03b112194786..2ce2b810d3636 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2611,7 +2611,7 @@ class ASTContext : public RefCountedBase { /// /// \returns if this is an array type, the completely unqualified array type /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). - QualType getUnqualifiedArrayType(QualType T, Qualifiers ); + QualType getUnqualifiedArrayType(QualType T, Qualifiers ) const; /// Determine whether the given types are equivalent after /// cvr-qualifiers have been removed. diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8fc2bb8c401c2..388233c554d46 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3054,6 +3054,13 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const { if (!T.hasAddressSpace())
[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/92623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/92623 >From ef46dd51c5c54cf5a76d83b9c15f8f3aee052e42 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Fri, 17 May 2024 17:15:48 -0700 Subject: [PATCH] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics This adds the `-fexperimental-bounds-safety` cc1 and corresponding language option. This language option enables "-fbounds-safety" which is a bounds-safety extension for C that is being incrementally upstreamed. This cc1 flag is not exposed as a driver flag yet because most of the implementation isn't upstream yet. The language option is used to make a small semantic change to how the `counted_by` attribute is treated. Without `-fexperimental-bounds-safety` the attribute is allowed (but emits a warning) on a flexible array member where the element type is a struct with a flexible array member. With the flag this situation is an error. E.g. ``` struct has_unannotated_FAM { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_FAM { int count; // Forbidden with `-fexperimental-bounds-safety` struct has_unannotated_FAM Arr[] __counted_by(count); }; ``` rdar://125400392 --- clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Driver/Options.td | 8 clang/lib/Sema/SemaDeclAttr.cpp | 2 +- .../Sema/attr-counted-by-bounds-safety-vlas.c | 37 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/attr-counted-by-bounds-safety-vlas.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 09eb92d6f10d2..77ac7cfbddfca 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -504,6 +504,8 @@ COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process sta BENIGN_LANGOPT(CheckNew, 1, 0, "Do not assume C++ operator new may not return NULL") +LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C") + #undef LANGOPT #undef COMPATIBLE_LANGOPT #undef BENIGN_LANGOPT diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7bb781667e926..798ccbe3b94d5 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1871,6 +1871,14 @@ def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">, MetaVarName<"">, HelpText<"Specify the Swift version to use when filtering API notes">; +defm bounds_safety : BoolFOption< + "experimental-bounds-safety", + LangOpts<"BoundsSafety">, DefaultFalse, + PosFlag, + NegFlag, + BothFlags<[], [CC1Option], + " experimental bounds safety extension for C">>; + defm addrsig : BoolFOption<"addrsig", CodeGenOpts<"Addrsig">, DefaultFalse, PosFlag, diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e816ea3647a7c..7eb29499dec7d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8695,7 +8695,7 @@ static bool CheckCountedByAttrOnField( } else if (PointeeTy->isFunctionType()) { InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION; } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) { -if (FieldTy->isArrayType()) { +if (FieldTy->isArrayType() && !S.getLangOpts().BoundsSafety) { // This is a workaround for the Linux kernel that has already adopted // `counted_by` on a FAM where the pointee is a struct with a FAM. This // should be an error because computing the bounds of the array cannot be diff --git a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c new file mode 100644 index 0..7d9c9a90880ff --- /dev/null +++ b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s +// +// This is a portion of the `attr-counted-by-vla.c` test but is checked +// under the semantics of `-fexperimental-bounds-safety` which has different +// behavior. + +#define __counted_by(f) __attribute__((counted_by(f))) + +struct has_unannotated_VLA { + int count; + char buffer[]; +}; + +struct has_annotated_VLA { + int count; + char buffer[] __counted_by(count); +}; + +struct buffer_of_structs_with_unnannotated_vla { + int count; + // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}} + struct has_unannotated_VLA Arr[] __counted_by(count); +}; + + +struct buffer_of_structs_with_annotated_vla { + int count; + // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}} + struct
[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Dan Liew (delcypher) Changes This adds the `-fexperimental-bounds-safety` cc1 and corresponding language option. This language option enables "-fbounds-safety" which is a bounds-safety extension for C that is being incrementally upstreamed. This cc1 flag is not exposed as a driver flag yet because most of the implementation isn't upstream yet. The language option is used to make a small semantic change to how the `counted_by` attribute is treated. Without `-fexperimental-bounds-safety` the attribute is allowed (but emits a warning) on a flexible array member where the element type is a struct with a flexible array member. With the flag this situation is an error. E.g. ``` struct has_unannotated_FAM { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_FAM { int count; // Forbidden with `-fexperimental-bounds-safety` struct has_unannotated_FAM Arr[] __counted_by(count); }; ``` --- Full diff: https://github.com/llvm/llvm-project/pull/92623.diff 4 Files Affected: - (modified) clang/include/clang/Basic/LangOptions.def (+2) - (modified) clang/include/clang/Driver/Options.td (+8) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1) - (added) clang/test/Sema/attr-counted-by-bounds-safety-vlas.c (+37) ``diff diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 09eb92d6f10d2..77ac7cfbddfca 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -504,6 +504,8 @@ COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process sta BENIGN_LANGOPT(CheckNew, 1, 0, "Do not assume C++ operator new may not return NULL") +LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C") + #undef LANGOPT #undef COMPATIBLE_LANGOPT #undef BENIGN_LANGOPT diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7bb781667e926..798ccbe3b94d5 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1871,6 +1871,14 @@ def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">, MetaVarName<"">, HelpText<"Specify the Swift version to use when filtering API notes">; +defm bounds_safety : BoolFOption< + "experimental-bounds-safety", + LangOpts<"BoundsSafety">, DefaultFalse, + PosFlag, + NegFlag, + BothFlags<[], [CC1Option], + " experimental bounds safety extension for C">>; + defm addrsig : BoolFOption<"addrsig", CodeGenOpts<"Addrsig">, DefaultFalse, PosFlag, diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e816ea3647a7c..7eb29499dec7d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8695,7 +8695,7 @@ static bool CheckCountedByAttrOnField( } else if (PointeeTy->isFunctionType()) { InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION; } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) { -if (FieldTy->isArrayType()) { +if (FieldTy->isArrayType() && !S.getLangOpts().BoundsSafety) { // This is a workaround for the Linux kernel that has already adopted // `counted_by` on a FAM where the pointee is a struct with a FAM. This // should be an error because computing the bounds of the array cannot be diff --git a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c new file mode 100644 index 0..7d9c9a90880ff --- /dev/null +++ b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s +// +// This is a portion of the `attr-counted-by-vla.c` test but is checked +// under the semantics of `-fexperimental-bounds-safety` which has different +// behavior. + +#define __counted_by(f) __attribute__((counted_by(f))) + +struct has_unannotated_VLA { + int count; + char buffer[]; +}; + +struct has_annotated_VLA { + int count; + char buffer[] __counted_by(count); +}; + +struct buffer_of_structs_with_unnannotated_vla { + int count; + // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}} + struct has_unannotated_VLA Arr[] __counted_by(count); +}; + + +struct buffer_of_structs_with_annotated_vla { + int count; + // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}} + struct has_annotated_VLA Arr[] __counted_by(count); +}; + +struct buffer_of_const_structs_with_annotated_vla { + int count; + // Make sure the `const` qualifier is printed when printing the element type. + // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size
[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)
delcypher wrote: This is based on #70480 but removes the driver part of the change and makes the flag a CC1 flag only. https://github.com/llvm/llvm-project/pull/92623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics (PR #92623)
https://github.com/delcypher created https://github.com/llvm/llvm-project/pull/92623 This adds the `-fexperimental-bounds-safety` cc1 and corresponding language option. This language option enables "-fbounds-safety" which is a bounds-safety extension for C that is being incrementally upstreamed. This cc1 flag is not exposed as a driver flag yet because most of the implementation isn't upstream yet. The language option is used to make a small semantic change to how the `counted_by` attribute is treated. Without `-fexperimental-bounds-safety` the attribute is allowed (but emits a warning) on a flexible array member where the element type is a struct with a flexible array member. With the flag this situation is an error. E.g. ``` struct has_unannotated_FAM { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_FAM { int count; // Forbidden with `-fexperimental-bounds-safety` struct has_unannotated_FAM Arr[] __counted_by(count); }; ``` >From cc6adf2e6473ab1dc008ddad5d925cad5e6646cf Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Fri, 17 May 2024 17:15:48 -0700 Subject: [PATCH] [BoundsSafety] Add `-fexperimental-bounds-safety` CC1 and language option and use it to tweak `counted_by`'s semantics This adds the `-fexperimental-bounds-safety` cc1 and corresponding language option. This language option enables "-fbounds-safety" which is a bounds-safety extension for C that is being incrementally upstreamed. This cc1 flag is not exposed as a driver flag yet because most of the implementation isn't upstream yet. The language option is used to make a small semantic change to how the `counted_by` attribute is treated. Without `-fexperimental-bounds-safety` the attribute is allowed (but emits a warning) on a flexible array member where the element type is a struct with a flexible array member. With the flag this situation is an error. E.g. ``` struct has_unannotated_FAM { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_FAM { int count; // Forbidden with `-fexperimental-bounds-safety` struct has_unannotated_FAM Arr[] __counted_by(count); }; ``` --- clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Driver/Options.td | 8 clang/lib/Sema/SemaDeclAttr.cpp | 2 +- .../Sema/attr-counted-by-bounds-safety-vlas.c | 37 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/attr-counted-by-bounds-safety-vlas.c diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 09eb92d6f10d2..77ac7cfbddfca 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -504,6 +504,8 @@ COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process sta BENIGN_LANGOPT(CheckNew, 1, 0, "Do not assume C++ operator new may not return NULL") +LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C") + #undef LANGOPT #undef COMPATIBLE_LANGOPT #undef BENIGN_LANGOPT diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7bb781667e926..798ccbe3b94d5 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1871,6 +1871,14 @@ def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">, MetaVarName<"">, HelpText<"Specify the Swift version to use when filtering API notes">; +defm bounds_safety : BoolFOption< + "experimental-bounds-safety", + LangOpts<"BoundsSafety">, DefaultFalse, + PosFlag, + NegFlag, + BothFlags<[], [CC1Option], + " experimental bounds safety extension for C">>; + defm addrsig : BoolFOption<"addrsig", CodeGenOpts<"Addrsig">, DefaultFalse, PosFlag, diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e816ea3647a7c..7eb29499dec7d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8695,7 +8695,7 @@ static bool CheckCountedByAttrOnField( } else if (PointeeTy->isFunctionType()) { InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION; } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) { -if (FieldTy->isArrayType()) { +if (FieldTy->isArrayType() && !S.getLangOpts().BoundsSafety) { // This is a workaround for the Linux kernel that has already adopted // `counted_by` on a FAM where the pointee is a struct with a FAM. This // should be an error because computing the bounds of the array cannot be diff --git a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c new file mode 100644 index 0..7d9c9a90880ff --- /dev/null +++ b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s +// +// This is a portion of the `attr-counted-by-vla.c` test but is
[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)
yronglin wrote: Thanks for the new test case, it's fixed with https://github.com/llvm/llvm-project/pull/92527 https://github.com/llvm/llvm-project/pull/87933 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
bwendling wrote: Thank you. I wrote to the author. I hope he'll be able to come up with a change on his end. Or at least an explanation that makes sense :-) https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), efriedma-quic wrote: Something like that, yes. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CMake][Release] Use the TXZ cpack generator for binaries (PR #90138)
https://github.com/tstellar edited https://github.com/llvm/llvm-project/pull/90138 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)
gedare wrote: With the patch: ``` $ echo " asm ( a : );" | clang-format -debug ... M=0 C=1 T=InlineASMColon S=1 F=0 B=0 BK=0 P=43 Name=colon L=7 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text=':' ... $ echo " asm { a : };" | clang-format -debug ... M=0 C=1 T=InlineASMColon S=0 F=1 B=0 BK=0 P=43 Name=colon L=7 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text=':' ``` https://github.com/llvm/llvm-project/pull/92617 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), changpeng wrote: Do you mean we should actually fix removeAddrSpaceQualType? Somewhere inside removeAddrSpaceQualType, we should use getUnqualifiedArrayType if it is an arrayType, and getSingleStepDesugaredType othereise? I have to admit that I have no experience in this field, so I am relying on you and @svenvh to move on for a reasonable fix. Thanks. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: @kees @bwendling @rapidsna The workaround to downgrade this error to a warning has landed https://github.com/llvm/llvm-project/commit/cef6387e52578366c2332275dad88b9953b55336 https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/sbc100 approved this pull request. lgtm. @dschuff WDYT? https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cef6387 - [Bounds-Safety] Temporarily relax a `counted_by` attribute restriction on flexible array members
Author: Dan Liew Date: 2024-05-17T16:23:24-07:00 New Revision: cef6387e52578366c2332275dad88b9953b55336 URL: https://github.com/llvm/llvm-project/commit/cef6387e52578366c2332275dad88b9953b55336 DIFF: https://github.com/llvm/llvm-project/commit/cef6387e52578366c2332275dad88b9953b55336.diff LOG: [Bounds-Safety] Temporarily relax a `counted_by` attribute restriction on flexible array members In 0ec3b972e58bcbcdc1bebe1696ea37f2931287c3 an additional restriction was added when applying the `counted_by` attribute to flexible array members in structs. The restriction prevented the element type being a struct that itself had a flexible array member. E.g.: ``` struct has_unannotated_VLA { int count; char buffer[]; }; struct buffer_of_structs_with_unnannotated_vla { int count; struct has_unannotated_VLA Arr[] __counted_by(count); }; ``` In this example assuming the size of `Arr` is `sizeof(struct has_unannotated_VLA)*count` (which is what the attribute says) is wrong because it doesn't account for the size of `has_unannotated_VLA::buffer`. This is why this kind of code construct was treated as an error. However, it turns out existing Linux kernel code used the attribute on a flexible array member in this way (https://github.com/llvm/llvm-project/pull/90786#issuecomment-2118416515). To unbreak the build this restriction is downgraded to a warning with the plan to make it an error again once the errornous use of the attribute in the Linux kernel is resolved. Added: Modified: clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaDeclAttr.cpp clang/test/Sema/attr-counted-by-vla.c Removed: diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 4cb4f3d999f7a..4fad4d1a0eca7 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1447,6 +1447,10 @@ def FunctionMultiVersioning def NoDeref : DiagGroup<"noderef">; +// -fbounds-safety and bounds annotation related warnings +def BoundsSafetyCountedByEltTyUnknownSize : + DiagGroup<"bounds-safety-counted-by-elt-type-unknown-size">; + // A group for cross translation unit static analysis related warnings. def CrossTU : DiagGroup<"ctu">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8e6596410c5d0..1efa3af121c10 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6552,7 +6552,7 @@ def err_counted_by_attr_refer_to_union : Error< def note_flexible_array_counted_by_attr_field : Note< "field %0 declared here">; def err_counted_by_attr_pointee_unknown_size : Error< - "'counted_by' cannot be applied to %select{" + "'counted_by' %select{cannot|should not}3 be applied to %select{" "a pointer with pointee|" // pointer "an array with element}0" // array " of unknown size because %1 is %select{" @@ -6561,8 +6561,14 @@ def err_counted_by_attr_pointee_unknown_size : Error< "a function type|" // CountedByInvalidPointeeTypeKind::FUNCTION // CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER "a struct type with a flexible array member" +"%select{|. This will be an error in a future compiler version}3" +"" "}2">; +def warn_counted_by_attr_elt_type_unknown_size : + Warning, + InGroup; + let CategoryName = "ARC Semantic Issue" in { // ARC-mode diagnostics. diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c8b71631076ba..e816ea3647a7c 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8687,6 +8687,7 @@ static bool CheckCountedByAttrOnField( // Note: The `Decl::isFlexibleArrayMemberLike` check earlier on means // only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable // when `FieldTy->isArrayType()`. + bool ShouldWarn = false; if (PointeeTy->isIncompleteType()) { InvalidTypeKind = CountedByInvalidPointeeTypeKind::INCOMPLETE; } else if (PointeeTy->isSizelessType()) { @@ -8694,13 +8695,25 @@ static bool CheckCountedByAttrOnField( } else if (PointeeTy->isFunctionType()) { InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION; } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) { +if (FieldTy->isArrayType()) { + // This is a workaround for the Linux kernel that has already adopted + // `counted_by` on a FAM where the pointee is a struct with a FAM. This + // should be an error because computing the bounds of the array cannot be + // done correctly without manually traversing every struct object in the + // array at runtime. To allow the code to be built this error is + // downgraded to a warning. + ShouldWarn =
[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Gedare Bloom (gedare) Changes Short-circuit the parsing of tok::colon to label colons found within lines starting with asm as InlineASMColon. Fixes #92616. --- Full diff: https://github.com/llvm/llvm-project/pull/92617.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+2) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+17-3) ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7c4c76a91f2c5..a83f937336565 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1358,6 +1358,8 @@ class AnnotatingParser { Line.First->startsSequence(tok::kw_export, Keywords.kw_module) || Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) { Tok->setType(TT_ModulePartitionColon); + } else if (Line.First->is(tok::kw_asm)) { +Tok->setType(TT_InlineASMColon); } else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) { Tok->setType(TT_DictLiteral); if (Style.Language == FormatStyle::LK_TextProto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index aadfa6dc0165c..0f5f3936e0181 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1489,11 +1489,25 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { TEST_F(TokenAnnotatorTest, UnderstandsAsm) { auto Tokens = annotate("__asm{\n" "a:\n" - "};"); - ASSERT_EQ(Tokens.size(), 7u) << Tokens; + ": x\n" + ":};"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); - EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); + + Tokens = annotate("__asm__ volatile (\n" +"a:\n" +": x\n" +":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); } TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) { `` https://github.com/llvm/llvm-project/pull/92617 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)
https://github.com/gedare created https://github.com/llvm/llvm-project/pull/92617 Short-circuit the parsing of tok::colon to label colons found within lines starting with asm as InlineASMColon. Fixes #92616. >From b4a8c06b79ec10ed2f53a7410bd847ecfa9e8450 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Fri, 17 May 2024 17:18:59 -0600 Subject: [PATCH] [clang-format]: Annotate colons found in inline assembly Short-circuit the parsing of tok::colon to label colons found within lines starting with asm as InlineASMColon. Fixes #92616. --- clang/lib/Format/TokenAnnotator.cpp | 2 ++ clang/unittests/Format/TokenAnnotatorTest.cpp | 20 --- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7c4c76a91f2c5..a83f937336565 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1358,6 +1358,8 @@ class AnnotatingParser { Line.First->startsSequence(tok::kw_export, Keywords.kw_module) || Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) { Tok->setType(TT_ModulePartitionColon); + } else if (Line.First->is(tok::kw_asm)) { +Tok->setType(TT_InlineASMColon); } else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) { Tok->setType(TT_DictLiteral); if (Style.Language == FormatStyle::LK_TextProto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index aadfa6dc0165c..0f5f3936e0181 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1489,11 +1489,25 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { TEST_F(TokenAnnotatorTest, UnderstandsAsm) { auto Tokens = annotate("__asm{\n" "a:\n" - "};"); - ASSERT_EQ(Tokens.size(), 7u) << Tokens; + ": x\n" + ":};"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); - EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); + + Tokens = annotate("__asm__ volatile (\n" +"a:\n" +": x\n" +":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); } TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/92604 >From bedab4dc6edc3fd44d79c42d4fd62dc1a6937fb0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 20:41:21 + Subject: [PATCH 1/3] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. --- clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ clang/test/CodeGenCXX/wasm-eh.cpp | 4 2 files changed, 6 insertions(+) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index af023f52191b9..09588985d4e74 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,4 +1,8 @@ // REQUIRES: webassembly-registered-target + +// RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR +// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 + // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s >From 38b517419cb60e9fb88828847fd8d57542e9a651 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 21:25:07 + Subject: [PATCH 2/3] Add Wasm condition --- clang/lib/Frontend/InitPreprocessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 3cc85ff502776..f76f16e2228e7 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,7 +1006,7 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); - else if (LangOpts.hasWasmExceptions()) + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) >From 8d57019721697c1367e5aca99e032e7c094aedb2 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 23:07:19 + Subject: [PATCH 3/3] __USING_WASM_EXCEPTIONS__ -> __WASM_EXCEPTIONS__ --- clang/lib/Frontend/InitPreprocessor.cpp | 2 +- clang/test/CodeGenCXX/wasm-eh.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index f76f16e2228e7..68760e3e0 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1007,7 +1007,7 @@ static void InitializePredefinedMacros(const TargetInfo , (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) -Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); +Builder.defineMacro("__WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index 09588985d4e74..b70c07386fd14 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,7 +1,7 @@ // REQUIRES: webassembly-registered-target // RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR -// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 +// PREPROCESSOR: #define __WASM_EXCEPTIONS__ 1
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); aheejin wrote: I see. And come to think of it, as you said, I may not need to worry about the predefined macros in other users because they might be redundant but this will not break them because we define the macro in Clang. Will update this to `__WASM_EXCEPTIONS__`, and update the macro in other parts of LLVM and Emscripten as follow-ups. https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); sbc100 wrote: I don't think we should remove the define here, I just want us to consider carefully the name of the define if we are going to have the compiler generate it. The removal I was referring to was the `-D...` flags used in emscripten and wasi-sdk, which will be redundant once this change land (and they convert to using the new macro). https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
bwendling wrote: Ah! I see what you mean. I'll bring this up with the developer. (Actually, that construct makes me nervous about their code in general...) https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: @bwendling This is unfortunate ``` drivers/gpu/drm/radeon/pptable.h:442:5: error: 'counted_by' cannot be applied to an array with element of unknown size because 'ATOM_PPLIB_STATE_V2' (aka 'struct _ATOM_PPLIB_STATE_V2') is a struct type with a flexible array member 442 | ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); | ^~~~ 1 error generated. ``` Based on our previous discussion (https://github.com/llvm/llvm-project/pull/90786#issuecomment-2108855275) I hope we can agree using the attribute this way is problematic. I don't see how `states` could be have its bounds correctly computed when the compiler doesn't know how big `struct _ATOM_PPLIB_STATE_V2` actually is. To unbreak this particular use quickly I'll downgrade the struct with FAM case to a warning and from there we'll need to decide how to proceed. https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
rapidsna wrote: @bwendling @kees Likely, we should not put `__counted_by` in that case. Could we fix the source? https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
rapidsna wrote: @bwendling @kees Wait. `ATOM_PPLIB_STATE_V2` is also a struct with flexible array member? This is concerning because `ucNumEntries * sizeof(ATOM_PPLIB_STATE_V2)` is not the correct size anyway. Do you know the semantics of this structure? https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); aheejin wrote: Changing it in LLVM and Emscripten is not a big problem, but I'm still somewhat worried about non-Emscripten toolchain users who have `-D__USING_WASM_EXCEPTIONS__` somewhere in their build configuration. I can add some comment on the previous issues for Wasm EH library porting and change the parts of WASI toolchain that uses the macro. And why do you think we should remove this define here in Clang (assuming we change this to whatever we like)? This is consistent with what other exception modes are doing, and people need this `define` somewhere. https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), efriedma-quic wrote: I see two issues with this fix: 1. It leaves removeAddrSpaceQualType broken for anyone else who tries to use it. Ideally, removeAddrSpaceQualType should do what it says. 2. This drops other qualifiers on the floor; they might be relevant in some cases. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/86858 >From 31af119d614ef2108b5404f9c9387ec45aa1bfef Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 21 Mar 2024 15:07:31 -0700 Subject: [PATCH 1/6] [Clang][objectsize] Generate object size calculation for sub-objects The second argument of __builtin_dynamic_object_size controls whether it returns the size of the whole object or the closest surrounding object. For this struct: struct s { int foo; char bar[2][40]; int baz; int qux; }; int main(int argc, char **argv) { struct s f; #define report(x) printf(#x ": %zu\n", x) argc = 1; report(__builtin_dynamic_object_size(f.bar[argc], 0)); report(__builtin_dynamic_object_size(f.bar[argc], 1)); return 0; } should return: __builtin_dynamic_object_size(f.bar[argc], 0): 48 __builtin_dynamic_object_size(f.bar[argc], 1): 40 determined by the least significant bit of the TYPE. The LLVM IR isn't sufficient to determine what could be considered a "sub-object". However, the front-end does have enough information to determine the size of a sub-object and the offset into that sub-object. We try therefore to convert the intrinsic into a calculation in the front-end so that we can avoid the information issue.. --- clang/lib/CodeGen/CGBuiltin.cpp | 138 +- clang/lib/CodeGen/CodeGenFunction.h | 6 + clang/test/CodeGen/object-size-sub-object.c | 280 3 files changed, 418 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/object-size-sub-object.c diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 2eaceeba61770..be055f34c4492 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -26,6 +26,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/OSLog.h" #include "clang/AST/OperationKinds.h" +#include "clang/AST/StmtVisitor.h" #include "clang/Basic/TargetBuiltins.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" @@ -1052,6 +1053,128 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +struct ObjectSizeVisitor +: public ConstStmtVisitor { + const Expr *Visit(const Expr *E) { +return ConstStmtVisitor::Visit(E); + } + + const Expr *VisitStmt(const Stmt *S) { return nullptr; } + + const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; } + const Expr *VisitMemberExpr(const MemberExpr *E) { return E; } + const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { return E; } + + const Expr *VisitCastExpr(const CastExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitParenExpr(const ParenExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } +}; + +} // end anonymous namespace + +/// tryToCalculateSubObjectSize - It may be possible to calculate the +/// sub-object size of an array and skip the generation of the llvm.objectsize +/// intrinsic. This avoids the complication in conveying the sub-object's +/// information to the backend. This calculation works for an N-dimentional +/// array. +/// +/// Note that this function supports only Row-Major arrays. The generalized +/// calculation of the offset of an element in Row-Major form: +/// +/// .- -. +/// d |d | +/// ---| - | +/// offset = \ | | | | +/// / | | | N_j | m_i +/// ---| | | | +/// i = 1 | j = i + 1 | +/// `- -' +/// +/// where d is the number of dimensions; m_i is the index of an element in +/// dimension i; and N_i is the size of dimention i. +/// +/// Examples: +/// 2D: offset = m_2 + (N_2 * m_1) +/// 3D: offset = m_3 + (N_3 * m_2) + (N_3 * N_2 * m_1) +llvm::Value * +CodeGenFunction::tryToCalculateSubObjectSize(const Expr *E, unsigned Type, + llvm::IntegerType *ResType) { + if ((Type & 0x01) != 1) +// Only support sub-object calculation. +return nullptr; + + const Expr *ObjectBase = ObjectSizeVisitor().Visit(E); + if (!ObjectBase) +return nullptr; + + // Collect the sizes and indices from the array. + ASTContext = getContext(); + SmallVector, 4> Dims; + while (const auto *ASE = dyn_cast(ObjectBase)) { +const Expr *Base = ASE; +const Expr *Idx = ASE->getIdx(); + +if (Idx->HasSideEffects(Ctx)) + return nullptr; + +uint64_t BaseSize = Ctx.getTypeSizeInChars(Base->getType()).getQuantity(); +Value *IdxSize = EmitScalarExpr(Idx); + +
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/sbc100 edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); sbc100 wrote: I see the `__USING_` prefix does predate out work on Wasm exceptions so there is some precedent. I see __USING_SJLJ_EXCEPTIONS__ dating all the way back to 2009: 2f5c75e17dc0b2df841db396de22c35b95cb7f41. However, I don't see any other predefined macros using the `__USING_` prefix, so it might be worth removing it now before it gets even harder to remove. Presumably it would be quite easy for downstream toolchains to switch to using `__WASM_EXCEPTIONS__` either before or after this change lands.. and then remove the manual define at some point in the future. https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; + +public: + ObjectSizeVisitor(bool SkipASE = false) : SkipASE(SkipASE) {} + + const Expr *Visit(const Expr *E) { +return ConstStmtVisitor::Visit(E); + } + + const Expr *VisitStmt(const Stmt *S) { return nullptr; } + + const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; } + const Expr *VisitMemberExpr(const MemberExpr *E) { return E; } + const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { +return SkipASE ? Visit(E->getBase()) : E; + } + + const Expr *VisitCastExpr(const CastExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitParenExpr(const ParenExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); bwendling wrote: It's a bit aggressive, but I think it's okay. We're interested in only two situations: a __bdos on an array index, and finding the base expression to test if it's a flexible array member. However, it does return `0` for this: ```c struct foo { int ***f; }; extern struct foo *x; __builtin_dynamic_object_size(*(x->f[37]), 1) ``` I'm not sure if that's correct. I'll make it a bit less aggressive. https://github.com/llvm/llvm-project/pull/86858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)
@@ -535,20 +535,23 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); -LangAS AS = ArrayQTy.getAddressSpace(); +QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( +CGM.getContext().removeAddrSpaceQualType(ArrayQTy), changpeng wrote: > I think it's a bug in removeAddrSpaceQualType(): it needs to special-case > arrays. Arrays are weird because qualifiers on the element type also count as > qualifiers on the type, so getSingleStepDesugaredType() can't remove the > sugar on arrays. So it needs to strip the qualifier off the element type, > then reconstruct the array type. Maybe it can use > ASTContext::getUnqualifiedArrayType. Thanks for the suggestion. I drafted a fix: https://github.com/llvm/llvm-project/pull/92612 https://github.com/llvm/llvm-project/pull/90048 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Changpeng Fang (changpeng) Changes In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/90048), there is a bug in removeAddrSpaceQualType() for arrays. Arrays are weird because qualifiers on the element type also count as qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar on arrays. This results in an infinite loop in removeAddrSpaceQualType. To fix the issue, we use ASTContext::getUnqualifiedArrayType instead, which strips the qualifier off the element type, then reconstruct the array type. --- Full diff: https://github.com/llvm/llvm-project/pull/92612.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2-1) - (added) clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp (+25) ``diff diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// CHECK-SAME: ptr nocapture noundef readonly align 8 [[IN:%.*]], ptr nocapture noundef writeonly align 8 [[OUT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual [[META4:![0-9]+]] !kernel_arg_type [[META5:![0-9]+]] !kernel_arg_base_type [[META5]] !kernel_arg_type_qual [[META6:![0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. `` https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng created https://github.com/llvm/llvm-project/pull/92612 In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/90048), there is a bug in removeAddrSpaceQualType() for arrays. Arrays are weird because qualifiers on the element type also count as qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar on arrays. This results in an infinite loop in removeAddrSpaceQualType. To fix the issue, we use ASTContext::getUnqualifiedArrayType instead, which strips the qualifier off the element type, then reconstruct the array type. >From 2468a85a47499d90a99610846c632332eb7307b8 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 15:13:07 -0700 Subject: [PATCH] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/90048), there is a bug in removeAddrSpaceQualType() for arrays. Arrays are weird because qualifiers on the element type also count as qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar on arrays. This results in an infinite loop in removeAddrSpaceQualType. To fix the issue, we use ASTContext::getUnqualifiedArrayType, which strips the qualifier off the element type, then reconstruct the array type. --- clang/lib/CodeGen/CGExprAgg.cpp | 3 ++- .../array-type-infinite-loop.clcpp| 25 +++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// CHECK-SAME: ptr nocapture noundef readonly align 8 [[IN:%.*]], ptr nocapture noundef writeonly align 8 [[OUT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual [[META4:![0-9]+]] !kernel_arg_type [[META5:![0-9]+]] !kernel_arg_base_type [[META5]] !kernel_arg_type_qual [[META6:![0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
rapidsna wrote: @bwendling Thanks for reporting. We will relax the restrictions for arrays to not break the existing users. https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; + +public: + ObjectSizeVisitor(bool SkipASE = false) : SkipASE(SkipASE) {} + + const Expr *Visit(const Expr *E) { +return ConstStmtVisitor::Visit(E); + } + + const Expr *VisitStmt(const Stmt *S) { return nullptr; } + + const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; } + const Expr *VisitMemberExpr(const MemberExpr *E) { return E; } + const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { +return SkipASE ? Visit(E->getBase()) : E; + } + + const Expr *VisitCastExpr(const CastExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitParenExpr(const ParenExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } +}; + +} // end anonymous namespace + +/// getLastDecl - Return the last FieldDecl in the struct. +static const FieldDecl *getLastDecl(const RecordDecl *RD) { + const Decl *LastDecl = nullptr; + for (const Decl *D : RD->decls()) +if (isa(D) || isa(D)) + LastDecl = D; + + if (const auto *LastRD = dyn_cast(LastDecl)) { +LastDecl = getLastDecl(LastRD); + } else if (const auto *LastFD = dyn_cast(LastDecl)) { +QualType Ty = LastFD->getType(); +if (Ty->isPointerType()) + Ty = Ty->getPointeeType(); + +if (const RecordDecl *Rec = Ty->getAsRecordDecl()) + // The last FieldDecl is a structure. Look into that struct to find its + // last FieldDecl. + LastDecl = getLastDecl(Rec); + } + + return dyn_cast_if_present(LastDecl); +} + +/// tryToCalculateSubObjectSize - It may be possible to calculate the +/// sub-object size of an array and skip the generation of the llvm.objectsize +/// intrinsic. This avoids the complication in conveying the sub-object's +/// information to the backend. This calculation works for an N-dimentional +/// array. +llvm::Value * +CodeGenFunction::tryToCalculateSubObjectSize(const Expr *E, unsigned Type, + llvm::IntegerType *ResType) { + if ((Type & 0x01) != 1) +// Only support sub-object calculation. +return nullptr; + + const Expr *ObjectRef = ObjectSizeVisitor().Visit(E); + if (!ObjectRef) +return nullptr; + + QualType ObjectRefType = ObjectRef->getType(); + if (ObjectRefType->isPointerType()) +ObjectRefType = ObjectRefType->getPointeeType(); + + // Collect the base and index from the array. + QualType ObjectBaseRefTy; + const Expr *ArrayIdx = nullptr; + + if (const auto *ASE = dyn_cast(ObjectRef)) { +ArrayIdx = ASE->getIdx()->IgnoreParenImpCasts(); + +const Expr *ArrayRefBase = ASE->getBase()->IgnoreParenImpCasts(); +if (isa(ArrayRefBase)) { + ObjectBaseRefTy = ArrayRefBase->getType(); + if (ObjectBaseRefTy->isPointerType()) +ObjectBaseRefTy = ObjectBaseRefTy->getPointeeType(); +} + } + + ASTContext = getContext(); + if (!ArrayIdx || ArrayIdx->HasSideEffects(Ctx)) +return nullptr; + + // Check to see if the Decl is a flexible array member. Processing of the + // 'counted_by' attribute is done by now. So we don't have any information on + // its size, so return MAX_INT. + // + // Rerun the visitor to find the base expr: MemberExpr or DeclRefExpr. + ObjectRef = ObjectSizeVisitor(true).Visit(ObjectRef); + if (!ObjectRef) +return nullptr; + + if (const auto *ME = dyn_cast(ObjectRef)) { +if (const auto *FD = dyn_cast(ME->getMemberDecl())) { + const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel = + getLangOpts().getStrictFlexArraysLevel(); + const RecordDecl *OuterRD = + FD->getParent()->getOuterLexicalRecordContext(); + const FieldDecl *LastFD = getLastDecl(OuterRD); + + if (LastFD == FD && Decl::isFlexibleArrayMemberLike( + Ctx, FD, FD->getType(), StrictFlexArraysLevel, + /*IgnoreTemplateOrMacroSubstitution=*/true)) +return ConstantInt::get(ResType, -1, /*isSigned=*/true); +} + } + + if (ObjectBaseRefTy.isNull()) { +ObjectBaseRefTy = ObjectRef->getType(); +if (ObjectBaseRefTy->isPointerType()) + ObjectBaseRefTy = ObjectBaseRefTy->getPointeeType(); + } + + // Generate the calculation: + // + // S Object[n_1][n_2]...[n_m]; /* M-dimentional array */ + // + // ObjectRef = Object[n_1]...[n_x]; /* 0 < x < m */ + // ObjectBaseRef = Object[n_1]...[n_{x-1}]; + // + // ArrayRefSize = sizeof( typeof( ObjectRef ) ); + // ArrayRefBaseSize = sizeof( typeof( ObjectBaseRef ) ); + // + // Size = ArrayRefSize -
[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; + +public: + ObjectSizeVisitor(bool SkipASE = false) : SkipASE(SkipASE) {} + + const Expr *Visit(const Expr *E) { +return ConstStmtVisitor::Visit(E); + } + + const Expr *VisitStmt(const Stmt *S) { return nullptr; } + + const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; } + const Expr *VisitMemberExpr(const MemberExpr *E) { return E; } + const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { +return SkipASE ? Visit(E->getBase()) : E; + } + + const Expr *VisitCastExpr(const CastExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitParenExpr(const ParenExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } +}; + +} // end anonymous namespace + +/// getLastDecl - Return the last FieldDecl in the struct. +static const FieldDecl *getLastDecl(const RecordDecl *RD) { + const Decl *LastDecl = nullptr; + for (const Decl *D : RD->decls()) +if (isa(D) || isa(D)) bwendling wrote: This was due to a misunderstanding by me, that you cleared up in a previous PR. I'll remove it. https://github.com/llvm/llvm-project/pull/86858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/86858 >From 31af119d614ef2108b5404f9c9387ec45aa1bfef Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 21 Mar 2024 15:07:31 -0700 Subject: [PATCH 1/5] [Clang][objectsize] Generate object size calculation for sub-objects The second argument of __builtin_dynamic_object_size controls whether it returns the size of the whole object or the closest surrounding object. For this struct: struct s { int foo; char bar[2][40]; int baz; int qux; }; int main(int argc, char **argv) { struct s f; #define report(x) printf(#x ": %zu\n", x) argc = 1; report(__builtin_dynamic_object_size(f.bar[argc], 0)); report(__builtin_dynamic_object_size(f.bar[argc], 1)); return 0; } should return: __builtin_dynamic_object_size(f.bar[argc], 0): 48 __builtin_dynamic_object_size(f.bar[argc], 1): 40 determined by the least significant bit of the TYPE. The LLVM IR isn't sufficient to determine what could be considered a "sub-object". However, the front-end does have enough information to determine the size of a sub-object and the offset into that sub-object. We try therefore to convert the intrinsic into a calculation in the front-end so that we can avoid the information issue.. --- clang/lib/CodeGen/CGBuiltin.cpp | 138 +- clang/lib/CodeGen/CodeGenFunction.h | 6 + clang/test/CodeGen/object-size-sub-object.c | 280 3 files changed, 418 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/object-size-sub-object.c diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 2eaceeba61770..be055f34c4492 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -26,6 +26,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/OSLog.h" #include "clang/AST/OperationKinds.h" +#include "clang/AST/StmtVisitor.h" #include "clang/Basic/TargetBuiltins.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" @@ -1052,6 +1053,128 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +struct ObjectSizeVisitor +: public ConstStmtVisitor { + const Expr *Visit(const Expr *E) { +return ConstStmtVisitor::Visit(E); + } + + const Expr *VisitStmt(const Stmt *S) { return nullptr; } + + const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; } + const Expr *VisitMemberExpr(const MemberExpr *E) { return E; } + const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { return E; } + + const Expr *VisitCastExpr(const CastExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitParenExpr(const ParenExpr *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } + const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) { +return Visit(E->getSubExpr()); + } +}; + +} // end anonymous namespace + +/// tryToCalculateSubObjectSize - It may be possible to calculate the +/// sub-object size of an array and skip the generation of the llvm.objectsize +/// intrinsic. This avoids the complication in conveying the sub-object's +/// information to the backend. This calculation works for an N-dimentional +/// array. +/// +/// Note that this function supports only Row-Major arrays. The generalized +/// calculation of the offset of an element in Row-Major form: +/// +/// .- -. +/// d |d | +/// ---| - | +/// offset = \ | | | | +/// / | | | N_j | m_i +/// ---| | | | +/// i = 1 | j = i + 1 | +/// `- -' +/// +/// where d is the number of dimensions; m_i is the index of an element in +/// dimension i; and N_i is the size of dimention i. +/// +/// Examples: +/// 2D: offset = m_2 + (N_2 * m_1) +/// 3D: offset = m_3 + (N_3 * m_2) + (N_3 * N_2 * m_1) +llvm::Value * +CodeGenFunction::tryToCalculateSubObjectSize(const Expr *E, unsigned Type, + llvm::IntegerType *ResType) { + if ((Type & 0x01) != 1) +// Only support sub-object calculation. +return nullptr; + + const Expr *ObjectBase = ObjectSizeVisitor().Visit(E); + if (!ObjectBase) +return nullptr; + + // Collect the sizes and indices from the array. + ASTContext = getContext(); + SmallVector, 4> Dims; + while (const auto *ASE = dyn_cast(ObjectBase)) { +const Expr *Base = ASE; +const Expr *Idx = ASE->getIdx(); + +if (Idx->HasSideEffects(Ctx)) + return nullptr; + +uint64_t BaseSize = Ctx.getTypeSizeInChars(Base->getType()).getQuantity(); +Value *IdxSize = EmitScalarExpr(Idx); + +
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo , const BinaryOperator *E, // If during the evaluation of an expression, the result is not // mathematically defined [...], the behavior is undefined. // FIXME: C++ rules require us to not conform to IEEE 754 here. - if (LHS.isNaN()) { + if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) { hubert-reinterpretcast wrote: I do not think there is any particular reason why this change is C++23 specific. The question remains whether the change should be made at all. If the primary rationale here is to facilitate testing using the Windows header definitions, I suspect the answer is that the Windows definition of NaN is not a C++ constant expression. @jcranmer-intel's comment (https://github.com/llvm/llvm-project/pull/88978/files#discussion_r1576817678), supports the interpretation that operations that result in NaN from non-qNaN inputs are not valid in a constant expression. Other than wanting to use the Windows header definitions for the tests here, is there a reason why this change belongs in this PR? https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); aheejin wrote: I like it more too. I started using `__USING_WASM_EXCEPTIONS__` mostly because to be consistent with `__USING_SJLJ_EXCEPTIONS__`, which Wasm EH share many traits. There are many lines in libc++abi and libunwind where both SjLj and Wasm include or exclude by `ifdef`s like this https://github.com/llvm/llvm-project/blob/bdfb04a63d73c31ee75395064762d0d6ccb45819/libcxxabi/src/cxa_personality.cpp#L645 Not sure if it was really necessary to be consistent with it though. But anyway to do that we need to fix it everywhere, both in LLVM and Emscripten and libraries (libc++abi and libunwind). And it is likely other toolchains (like WASI) users have been defining `__USING_WASM_EXCEPTIONS__` somewhere in their build system already given that we have not been defining this in Clang so far. Do you think it's worth changing or feasible? https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
bwendling wrote: This seems to have broken the Linux build: https://github.com/llvm/llvm-project/commit/0ec3b972e58bcbcdc1bebe1696ea37f2931287c3 breaks the build for Linux, added by https://git.kernel.org/linus/781d41fed19caf900c8405064676813dc9921d32: https://paste.debian.net/plainh/b192bcd1 https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e2db08f - [test] Use conventional -emit-llvm-only
Author: Fangrui Song Date: 2024-05-17T14:42:48-07:00 New Revision: e2db08f8f1a7dd37cd18705164f0c1188707e5b6 URL: https://github.com/llvm/llvm-project/commit/e2db08f8f1a7dd37cd18705164f0c1188707e5b6 DIFF: https://github.com/llvm/llvm-project/commit/e2db08f8f1a7dd37cd18705164f0c1188707e5b6.diff LOG: [test] Use conventional -emit-llvm-only Similar to a6d7828f4c50c1ec7b0b5f61fe59d7a768175dcc Added: Modified: clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c Removed: diff --git a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c index fb43bc6337086..4a3a5a86a668b 100644 --- a/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c +++ b/clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify -emit-llvm %s +// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -verify -emit-llvm-only %s // REQUIRES: aarch64-registered-target ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #91606)
@@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -verify -emit-llvm %s MaskRay wrote: `-emit-llvm-only` is more conventional when the output is unneeded. In our internal build system, PWD is read-only and `-emit-llvm` would cause a failure. I changed this to `-emit-llvm-only` and changed `aarch64-none-linux-gnu` (none is sometimes used as an OS) to `aarch64` (generic ELF) to indicate that the behavior does not require Linux. https://github.com/llvm/llvm-project/pull/91606 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [Clang][Sema] Diagnose current instantiation used as an incomplete base class (PR #92597)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/92597 >From 9d95d211797843f3dc612fe4340354b5fbf6a2fe Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 17 May 2024 13:30:04 -0400 Subject: [PATCH 1/5] [Clang][Sema] Diagnose current instantiation used a incomplete base class --- clang/lib/AST/Type.cpp| 4 + clang/lib/Sema/SemaDeclCXX.cpp| 116 +- .../basic.lookup.qual/class.qual/p2.cpp | 10 +- clang/test/SemaTemplate/dependent-names.cpp | 9 +- .../test/SemaTemplate/destructor-template.cpp | 14 ++- .../test/SemaTemplate/typo-dependent-name.cpp | 7 +- 6 files changed, 84 insertions(+), 76 deletions(-) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index e31741cd44240..4ad764b67f81f 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2372,6 +2372,10 @@ bool Type::isIncompleteType(NamedDecl **Def) const { *Def = Rec; return !Rec->isCompleteDefinition(); } + case InjectedClassName: { +CXXRecordDecl *Rec = cast(CanonicalType)->getDecl(); +return Rec->isBeingDefined(); + } case ConstantArray: case VariableArray: // An array is incomplete if its element type is incomplete diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8225381985052..84033a602f131 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2704,28 +2704,53 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, Access = AS_public; QualType BaseType = TInfo->getType(); + SourceLocation BaseLoc = TInfo->getTypeLoc().getBeginLoc(); if (BaseType->containsErrors()) { // Already emitted a diagnostic when parsing the error type. return nullptr; } - // C++ [class.union]p1: - // A union shall not have base classes. - if (Class->isUnion()) { -Diag(Class->getLocation(), diag::err_base_clause_on_union) - << SpecifierRange; -return nullptr; - } - if (EllipsisLoc.isValid() && - !TInfo->getType()->containsUnexpandedParameterPack()) { + if (EllipsisLoc.isValid() && !BaseType->containsUnexpandedParameterPack()) { Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs) << TInfo->getTypeLoc().getSourceRange(); EllipsisLoc = SourceLocation(); } - SourceLocation BaseLoc = TInfo->getTypeLoc().getBeginLoc(); + auto *BaseDecl = + dyn_cast_if_present(computeDeclContext(BaseType)); + // C++ [class.derived.general]p2: + // A class-or-decltype shall denote a (possibly cv-qualified) class type + // that is not an incompletely defined class; any cv-qualifiers are + // ignored. + if (BaseDecl) { +// C++ [class.union.general]p4: +// [...] A union shall not be used as a base class. +if (BaseDecl->isUnion()) { + Diag(BaseLoc, diag::err_union_as_base_class) << SpecifierRange; + return nullptr; +} + +// For the MS ABI, propagate DLL attributes to base class templates. +if (Context.getTargetInfo().getCXXABI().isMicrosoft() || +Context.getTargetInfo().getTriple().isPS()) { + if (Attr *ClassAttr = getDLLAttr(Class)) { +if (auto *BaseSpec = +dyn_cast(BaseDecl)) { + propagateDLLAttrToBaseClassTemplate(Class, ClassAttr, BaseSpec, + BaseLoc); +} + } +} - if (BaseType->isDependentType()) { +if (RequireCompleteType(BaseLoc, BaseType, diag::err_incomplete_base_class, +SpecifierRange)) { + Class->setInvalidDecl(); + return nullptr; +} + } else if (!BaseType->isDependentType()) { +Diag(BaseLoc, diag::err_base_must_be_class) << SpecifierRange; +return nullptr; + } else { // Make sure that we don't have circular inheritance among our dependent // bases. For non-dependent bases, the check for completeness below handles // this. @@ -2750,65 +2775,28 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, // constexpr evaluator). If this case happens (in errory-recovery mode), we // explicitly mark the Class decl invalid. The diagnostic was already // emitted. -if (!Class->getTypeForDecl()->isDependentType()) +if (!Class->isDependentContext()) Class->setInvalidDecl(); return new (Context) CXXBaseSpecifier( SpecifierRange, Virtual, Class->getTagKind() == TagTypeKind::Class, Access, TInfo, EllipsisLoc); } - // Base specifiers must be record types. - if (!BaseType->isRecordType()) { -Diag(BaseLoc, diag::err_base_must_be_class) << SpecifierRange; -return nullptr; - } - - // C++ [class.union]p1: - // A union shall not be used as a base class. - if (BaseType->isUnionType()) { -Diag(BaseLoc, diag::err_union_as_base_class) << SpecifierRange; -return nullptr; - } - - // For the MS ABI, propagate DLL attributes to base class templates. - if
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
@@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); sbc100 wrote: How about just calling this `__WASM_EXCEPTIONS__`? https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/92604 >From bedab4dc6edc3fd44d79c42d4fd62dc1a6937fb0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 20:41:21 + Subject: [PATCH 1/2] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. --- clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ clang/test/CodeGenCXX/wasm-eh.cpp | 4 2 files changed, 6 insertions(+) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index af023f52191b9..09588985d4e74 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,4 +1,8 @@ // REQUIRES: webassembly-registered-target + +// RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR +// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 + // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s >From 38b517419cb60e9fb88828847fd8d57542e9a651 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 21:25:07 + Subject: [PATCH 2/2] Add Wasm condition --- clang/lib/Frontend/InitPreprocessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 3cc85ff502776..f76f16e2228e7 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,7 +1006,7 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); - else if (LangOpts.hasWasmExceptions()) + else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm()) Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 238e3242d12473a072d0d2adc51f18fbeaa927a8 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH] implement wraps attribute Signed-off-by: Justin Stitt --- clang/docs/ReleaseNotes.rst | 9 +++ clang/include/clang/AST/Expr.h| 3 + clang/include/clang/AST/Type.h| 2 + clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 69 +++ clang/include/clang/Basic/DiagnosticGroups.td | 6 ++ .../clang/Basic/DiagnosticSemaKinds.td| 7 ++ clang/lib/AST/Expr.cpp| 9 +++ clang/lib/AST/ExprConstant.cpp| 4 +- clang/lib/AST/Type.cpp| 4 ++ clang/lib/AST/TypePrinter.cpp | 3 + clang/lib/CodeGen/CGExprScalar.cpp| 47 + clang/lib/Sema/Sema.cpp | 3 + clang/lib/Sema/SemaChecking.cpp | 33 - clang/lib/Sema/SemaDeclAttr.cpp | 8 ++- clang/lib/Sema/SemaType.cpp | 15 clang/test/CodeGen/integer-overflow.c | 66 ++ clang/test/CodeGen/unsigned-overflow.c| 63 ++--- ...a-attribute-supported-attributes-list.test | 1 + clang/test/Sema/attr-wraps.c | 43 20 files changed, 376 insertions(+), 26 deletions(-) create mode 100644 clang/test/Sema/attr-wraps.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2f83f5c6d54e9..6cf358477b4db 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -425,6 +425,15 @@ Attribute Changes in Clang size_t count; }; +- Introduced ``__attribute((wraps))__`` which can be added to type or variable + declarations. Using an attributed type or variable in an arithmetic + expression will define the overflow behavior for that expression as having + two's complement wrap-around. These expressions cannot trigger integer + overflow warnings or sanitizer warnings. They also cannot be optimized away + by some eager UB optimizations. + + This attribute is only valid for C, as there are built-in language + alternatives for other languages. Improvements to Clang's diagnostics --- diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index f2bf667636dc9..48968cbbbaf7e 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4061,6 +4061,9 @@ class BinaryOperator : public Expr { return getFPFeaturesInEffect(LO).getAllowFEnvAccess(); } + /// Does one of the subexpressions have the wraps attribute? + bool hasWrappingOperand(const ASTContext ) const; + protected: BinaryOperator(const ASTContext , Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index c7a8e785913b3..d85cbfef02145 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1441,6 +1441,8 @@ class QualType { return getQualifiers().hasStrongOrWeakObjCLifetime(); } + bool hasWrapsAttr() const; + // true when Type is objc's weak and weak is enabled but ARC isn't. bool isNonWeakInMRRWithObjCWeak(const ASTContext ) const; diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 7a7721239a28f..52572ec96b203 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4569,3 +4569,10 @@ def ClspvLibclcBuiltin: InheritableAttr { let Documentation = [ClspvLibclcBuiltinDoc]; let SimpleHandler = 1; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [Clang<"wraps">]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; + let LangOpts = [COnly]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b48aaf65558ac..6340703354a45 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8101,3 +8101,72 @@ Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify func .. _`libclc`: https://libclc.llvm.org }]; } + +def WrapsDocs : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute can be used with type or variable declarations to denote that +arithmetic containing these marked components have defined overflow behavior. +Specifically, the behavior is defined as being consistent with two's complement +wrap-around. For the purposes of sanitizers or warnings that concern themselves +with the definedness of integer arithmetic, they will cease to instrument or +warn about arithmetic that directly involves a "wrapping" component. + +For example,
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Heejin Ahn (aheejin) Changes When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. --- Full diff: https://github.com/llvm/llvm-project/pull/92604.diff 2 Files Affected: - (modified) clang/lib/Frontend/InitPreprocessor.cpp (+2) - (modified) clang/test/CodeGenCXX/wasm-eh.cpp (+4) ``diff diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index af023f52191b9..09588985d4e74 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,4 +1,8 @@ // REQUIRES: webassembly-registered-target + +// RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR +// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 + // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s `` https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin ready_for_review https://github.com/llvm/llvm-project/pull/92604 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions (PR #92604)
https://github.com/aheejin created https://github.com/llvm/llvm-project/pull/92604 When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. >From bedab4dc6edc3fd44d79c42d4fd62dc1a6937fb0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 17 May 2024 20:41:21 + Subject: [PATCH] [WebAssembly] Define __USING_WASM_EXCEPTIONS__ for -fwasm-exceptions When using other specific exception options in Clang, such as `-fseh-exceptions` or `-fsjlj-exceptions`, Clang defines a corresponding preprocessor such as `-D__USING_SJLJ_EXCEPTIONS__`. Emscripten does that in our own build system: https://github.com/emscripten-core/emscripten/blob/7dcd7f40749918e141dc33397d2f4311dd80637a/tools/system_libs.py#L1577-L1578 But to make Wasm EH usable in non-Emscripten toolchain, this has to be defined somewhere else. This PR makes Wasm EH consistent with other exception scheme by letting it defined by Clang depending on the exception option. --- clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ clang/test/CodeGenCXX/wasm-eh.cpp | 4 2 files changed, 6 insertions(+) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp b/clang/test/CodeGenCXX/wasm-eh.cpp index af023f52191b9..09588985d4e74 100644 --- a/clang/test/CodeGenCXX/wasm-eh.cpp +++ b/clang/test/CodeGenCXX/wasm-eh.cpp @@ -1,4 +1,8 @@ // REQUIRES: webassembly-registered-target + +// RUN: %clang -E -dM %s -target wasm32-unknown-unknown -fwasm-exceptions | FileCheck %s -check-prefix PREPROCESSOR +// PREPROCESSOR: #define __USING_WASM_EXCEPTIONS__ 1 + // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)
https://github.com/SimplyDanny approved this pull request. https://github.com/llvm/llvm-project/pull/92241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on C23 (PR #92241)
@@ -368,7 +368,8 @@ Changes in existing checks - Improved :doc:`readability-implicit-bool-conversion ` check to provide valid fix suggestions for ``static_cast`` without a preceding space and - fixed problem with duplicate parentheses in double implicit casts. + fixed problem with duplicate parentheses in double implicit casts. Corrected + the fix suggestions for C23 by using C-style casts instead of ``static_cast``. SimplyDanny wrote: That makes sense, even though it's not super obvious at first. https://github.com/llvm/llvm-project/pull/92241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)
@@ -6086,6 +6086,62 @@ static SDValue lowerBALLOTIntrinsic(const SITargetLowering , SDNode *N, DAG.getConstant(0, SL, MVT::i32), DAG.getCondCode(ISD::SETNE)); } +static SDValue lowerLaneOp(const SITargetLowering , SDNode *N, + SelectionDAG ) { + EVT VT = N->getValueType(0); + unsigned ValSize = VT.getSizeInBits(); + unsigned IntrinsicID = N->getConstantOperandVal(0); + SDValue Src0 = N->getOperand(1); + SDLoc SL(N); + MVT IntVT = MVT::getIntegerVT(ValSize); + + auto createLaneOp = [&](SDValue Src0, SDValue Src1, SDValue Src2, + MVT VT) -> SDValue { arsenm wrote: ? VT shadow https://github.com/llvm/llvm-project/pull/89217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)
jyknight wrote: We _don't_ diagnose it at the end of the definition of M -- it looks like we explicitly intentionally stopped doing so in the commit I referenced. That's why I'm a little confused here. With this patch, we start to diagnose only in the final line of code, `void test(M m = {}) {}` (that line doesn't appear in the error message, but it's the trigger). https://github.com/llvm/llvm-project/pull/87933 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)
@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, untyped]> { // FIXME: Specify SchedRW for READFIRSTLANE_B32 // TODO: There is VOP3 encoding also def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", VOP_READFIRSTLANE, - getVOP1Pat.ret, 1> { + [], 1> { let isConvergent = 1; } +foreach vt = Reg32Types.types in { + def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))), +(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0)) arsenm wrote: I'd rather just leave the pointer cases failing in the global isel case, and remove all the cast insertion bits. You could split out the pointer cases to a separate file and just not run it with globalisel. https://github.com/llvm/llvm-project/pull/89217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)
https://github.com/farzonl approved this pull request. https://github.com/llvm/llvm-project/pull/89809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/92318 >From db264c719dfae25a536fb2452328d9aaeeea7b6f Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Wed, 15 May 2024 16:13:03 -0400 Subject: [PATCH 1/4] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions --- clang/include/clang/Sema/Sema.h | 11 +-- clang/lib/Sema/SemaCXXScopeSpec.cpp | 8 ++ clang/lib/Sema/SemaExpr.cpp | 31 ++ clang/lib/Sema/SemaTemplate.cpp | 98 ++- clang/lib/Sema/TreeTransform.h| 6 +- .../class.mfct/class.mfct.non-static/p3.cpp | 91 - ...ms-function-specialization-class-scope.cpp | 52 ++ .../ms-lookup-template-base-classes.cpp | 12 +-- .../ASTMatchers/ASTMatchersNodeTest.cpp | 6 +- 9 files changed, 206 insertions(+), 109 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index d4d4a82525a02..fcc60a2ee4bca 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -5374,11 +5374,9 @@ class Sema final : public SemaBase { bool UseArgumentDependentLookup(const CXXScopeSpec , const LookupResult , bool HasTrailingLParen); - ExprResult - BuildQualifiedDeclarationNameExpr(CXXScopeSpec , -const DeclarationNameInfo , -bool IsAddressOfOperand, const Scope *S, -TypeSourceInfo **RecoveryTSI = nullptr); + ExprResult BuildQualifiedDeclarationNameExpr( + CXXScopeSpec , const DeclarationNameInfo , + bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr); ExprResult BuildDeclarationNameExpr(const CXXScopeSpec , LookupResult , bool NeedsADL, @@ -8990,7 +8988,8 @@ class Sema final : public SemaBase { ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec , SourceLocation TemplateKWLoc, const DeclarationNameInfo , - const TemplateArgumentListInfo *TemplateArgs); + const TemplateArgumentListInfo *TemplateArgs, + bool IsAddressOfOperand); TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec , SourceLocation TemplateKWLoc, diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index fca5bd131bbc0..c405fbc0aa421 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -796,6 +796,14 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo , Diag(IdInfo.IdentifierLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << IdInfo.Identifier << ContainingClass; +// Fake up a nested-name-specifier that starts with the +// injected-class-name of the enclosing class. +QualType T = Context.getTypeDeclType(ContainingClass); +TypeLocBuilder TLB; +TLB.pushTrivial(Context, T, IdInfo.IdentifierLoc); +SS.Extend(Context, /*TemplateKWLoc=*/SourceLocation(), + TLB.getTypeLocInContext(Context, T), IdInfo.IdentifierLoc); +// Add the identifier to form a dependent name. SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc); return false; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5ecfdee21f09d..ebf02ae566044 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2946,26 +2946,14 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec , /// this path. ExprResult Sema::BuildQualifiedDeclarationNameExpr( CXXScopeSpec , const DeclarationNameInfo , -bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI) { - if (NameInfo.getName().isDependentName()) -return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(), - NameInfo, /*TemplateArgs=*/nullptr); - - DeclContext *DC = computeDeclContext(SS, false); - if (!DC) -return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(), - NameInfo, /*TemplateArgs=*/nullptr); - - if (RequireCompleteDeclContext(SS, DC)) -return ExprError(); - +bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI) { LookupResult R(*this, NameInfo, LookupOrdinaryName); - LookupQualifiedName(R, DC); + LookupParsedName(R, /*S=*/nullptr, , /*ObjectType=*/QualType()); if (R.isAmbiguous()) return ExprError(); - if (R.getResultKind() == LookupResult::NotFoundInCurrentInstantiation) + if (R.wasNotFoundInCurrentInstantiation() || SS.isInvalid()) return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)
sdkrystian wrote: Closing this for now; I'll return to this once we correctly handle dependent `operator=`. https://github.com/llvm/llvm-project/pull/91503 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)
https://github.com/sdkrystian closed https://github.com/llvm/llvm-project/pull/91503 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' redeclaration in C++11 (PR #92452)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/92452 >From 187eb245484e21970ac55f05a78d3221f2f07f9a Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Thu, 16 May 2024 16:42:27 -0400 Subject: [PATCH 1/3] [Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' redeclaration in C++11 --- clang/docs/ReleaseNotes.rst| 2 ++ clang/include/clang/Sema/DeclSpec.h| 12 ++-- clang/lib/Sema/SemaDecl.cpp| 18 +- .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp | 11 +++ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2f83f5c6d54e9..3c7e0572e837f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -758,6 +758,8 @@ Bug Fixes to C++ Support - Fix a bug with checking constrained non-type template parameters for equivalence. Fixes (#GH77377). - Fix a bug where the last argument was not considered when considering the most viable function for explicit object argument member functions. Fixes (#GH92188). +- Fix a C++11 crash when a non-const non-static member function is defined out-of-line with + the ``constexpr`` specifier. Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 23bc780e04979..44d96db54b5f0 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -1527,20 +1527,20 @@ struct DeclaratorChunk { /// Retrieve the location of the 'const' qualifier. SourceLocation getConstQualifierLoc() const { - assert(MethodQualifiers); - return MethodQualifiers->getConstSpecLoc(); + return MethodQualifiers ? MethodQualifiers->getConstSpecLoc() + : SourceLocation(); } /// Retrieve the location of the 'volatile' qualifier. SourceLocation getVolatileQualifierLoc() const { - assert(MethodQualifiers); - return MethodQualifiers->getVolatileSpecLoc(); + return MethodQualifiers ? MethodQualifiers->getVolatileSpecLoc() + : SourceLocation(); } /// Retrieve the location of the 'restrict' qualifier. SourceLocation getRestrictQualifierLoc() const { - assert(MethodQualifiers); - return MethodQualifiers->getRestrictSpecLoc(); + return MethodQualifiers ? MethodQualifiers->getRestrictSpecLoc() + : SourceLocation(); } /// Retrieve the location of the 'mutable' qualifier, if any. diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f2b9202255cd4..4a1d55ea44703 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9217,15 +9217,15 @@ static NamedDecl *DiagnoseInvalidRedeclaration( << Idx << FDParam->getType() << NewFD->getParamDecl(Idx - 1)->getType(); } else if (FDisConst != NewFDisConst) { - SemaRef.Diag(FD->getLocation(), diag::note_member_def_close_const_match) - << NewFDisConst << FD->getSourceRange().getEnd() - << (NewFDisConst - ? FixItHint::CreateRemoval(ExtraArgs.D.getFunctionTypeInfo() - .getConstQualifierLoc()) - : FixItHint::CreateInsertion(ExtraArgs.D.getFunctionTypeInfo() - .getRParenLoc() - .getLocWithOffset(1), - " const")); + auto DB = SemaRef.Diag(FD->getLocation(), + diag::note_member_def_close_const_match) +<< NewFDisConst << FD->getSourceRange().getEnd(); + if (const auto = ExtraArgs.D.getFunctionTypeInfo(); !NewFDisConst) +DB << FixItHint::CreateInsertion(FTI.getRParenLoc().getLocWithOffset(1), + " const"); + else if (SourceLocation ConstLoc = FTI.getConstQualifierLoc(); + ConstLoc.isValid()) +DB << FixItHint::CreateRemoval(ConstLoc); } else SemaRef.Diag(FD->getLocation(), IsMember ? diag::note_member_def_close_match diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp index a28a5f91c4775..788e93b56bb38 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp @@ -154,3 +154,14 @@ namespace { // FIXME: We should diagnose this prior to C++17. const int = A::n; } + +#if __cplusplus < 201402L +namespace ImplicitConstexprDef { + struct A { +void f(); // expected-note {{member declaration does not match because it is not const qualified}} + }; + + constexpr void A::f() { } // expected-warning {{'constexpr' non-static member function
[clang] [Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' redeclaration in C++11 (PR #92452)
@@ -9203,15 +9203,15 @@ static NamedDecl *DiagnoseInvalidRedeclaration( << Idx << FDParam->getType() << NewFD->getParamDecl(Idx - 1)->getType(); } else if (FDisConst != NewFDisConst) { - SemaRef.Diag(FD->getLocation(), diag::note_member_def_close_const_match) - << NewFDisConst << FD->getSourceRange().getEnd() - << (NewFDisConst - ? FixItHint::CreateRemoval(ExtraArgs.D.getFunctionTypeInfo() - .getConstQualifierLoc()) - : FixItHint::CreateInsertion(ExtraArgs.D.getFunctionTypeInfo() - .getRParenLoc() - .getLocWithOffset(1), - " const")); + auto DB = SemaRef.Diag(FD->getLocation(), + diag::note_member_def_close_const_match) +<< NewFDisConst << FD->getSourceRange().getEnd(); + if (const auto = ExtraArgs.D.getFunctionTypeInfo(); !NewFDisConst) sdkrystian wrote: I think it would work either way... since this is guarded by `if (FDisConst != NewFDisConst)`, `!NewFDisConst` implies `FDisConst`. https://github.com/llvm/llvm-project/pull/92452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Merge duplicate extension information. (PR #92319)
@@ -56,43 +52,64 @@ class Extension< // The FMV priority int FMVPriority = _FMVPriority; + +// Indicates if the extension is available on the command line. +string IsFMVOnly = _IsFMVOnly; tmatheson-arm wrote: ```suggestion bit IsFMVOnly = 0; ``` https://github.com/llvm/llvm-project/pull/92319 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Merge duplicate extension information. (PR #92319)
@@ -94,19 +94,21 @@ static void EmitARMTargetDef(RecordKeeper , raw_ostream ) { else OS << ", \"" << Alias << "\""; OS << ", AArch64::" << AEK; -if (AEK == "AEK_NONE") { +auto Name = Rec->getValueAsString("Name"); +if (Name.empty()) { tmatheson-arm wrote: Shouldn't we be checking `IsFMVOnly` here? https://github.com/llvm/llvm-project/pull/92319 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Merge duplicate extension information. (PR #92319)
@@ -56,43 +52,64 @@ class Extension< // The FMV priority int FMVPriority = _FMVPriority; + +// Indicates if the extension is available on the command line. +string IsFMVOnly = _IsFMVOnly; } // Some extensions are available for FMV but can not be controlled via the -// command line. These entries: -// - are SubtargetFeatures, so they have (unused) FieldNames on the subtarget -//e.g. HasFMVOnlyFEAT_XYZ -// - have incorrect (empty) Implies fields, because the code that handles FMV -//ignores these dependencies and looks only at FMVDependencies. -// - have no description. -// -// In the generated data structures for extensions (ExtensionInfo), AEK_NONE is -// used to indicate that a feature is FMV only. Therefore ArchExtKindSpelling is -// manually overridden here. -class FMVOnlyExtension - : Extension { -let ArchExtKindSpelling = "AEK_NONE"; // AEK_NONE indicates FMV-only feature -} +// command line, neither have a TargetFeatureName. Since they have no effect +// on their own, their description is left empty. However they can have side +// effects by implying other Subtarget Features. These extensions are used +// in FMV for detection purposes. + +let MArchName = "dgh" in +def : Extension<"", "DGH", "", [], "FEAT_DGH", "", 260, "true">; tmatheson-arm wrote: I think this is a regression over using the `FMVOnlyExtension` class: - These extensions are _not_ available via `-march`, but they require writing `let MArchName = "..."` while leaving their actual `Name` empty. That seems the wrong way around? - The `FMVOnlyExtension` type makes it obvious what it is, whereas the boolean parameter makes it obscure. - There are now subtarget fields like `HasDGH` which are not obviously FMV-only. Previously they were called `HasFMVOnlyDGH` etc. - Removing the type and relying on convention leaves it open to abusing the abstraction, which as we have seen will happen very quickly. This could be done while keeping the type: ```cpp class FMVOnlyExtension : Extension<"", "FMVOnly"#FMVBit, "", [], FMVBit, Deps, Priority> { let IsFMVOnly = 1; // comment explaining why MArchName is overridden despite not working for -march let MArchName = Name; } ``` https://github.com/llvm/llvm-project/pull/92319 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)
@@ -20,7 +20,7 @@ .text #endif -#if !defined(__USING_SJLJ_EXCEPTIONS__) +#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) aheejin wrote: Removed the clang change and `LIBUNWIND_USES_WASM_EXCEPTIONS`. https://github.com/llvm/llvm-project/pull/92192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)
https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/92192 >From 95b9e56ac8bdd3b0bde08f63f64e35d47a61b784 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 14 May 2024 22:08:20 + Subject: [PATCH 1/4] [libunwind][WebAssembly] Make libunwind compilable This tries to make Wasm compilable in LLVM tree with CMake for non-Emscripten platform. This - Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with `-fwasm-exceptions` (like other EH options) in Clang - Exclude `UnwindLevel1.c` when compiling with Wasm - Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be applied when compiling with Wasm w/o exceptions. - Define some unused macros to make it compile --- clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ libunwind/cmake/config-ix.cmake | 1 + libunwind/include/__libunwind_config.h | 4 libunwind/src/UnwindLevel1.c| 3 ++- libunwind/src/libunwind.cpp | 4 ++-- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index c1d209466ffe5..3cc85ff502776 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1006,6 +1006,8 @@ static void InitializePredefinedMacros(const TargetInfo , else if (LangOpts.hasDWARFExceptions() && (TI.getTriple().isThumb() || TI.getTriple().isARM())) Builder.defineMacro("__ARM_DWARF_EH__"); + else if (LangOpts.hasWasmExceptions()) +Builder.defineMacro("__USING_WASM_EXCEPTIONS__"); if (LangOpts.Deprecated) Builder.defineMacro("__DEPRECATED"); diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake index 126c872f0d489..d505ee1d346fa 100644 --- a/libunwind/cmake/config-ix.cmake +++ b/libunwind/cmake/config-ix.cmake @@ -109,6 +109,7 @@ check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG) check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM) check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS) check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH) +check_symbol_exists(__USING_WASM_EXCEPTIONS__ "" LIBUNWIND_USES_WASM_EXCEPTIONS) if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH) # This condition is copied from __libunwind_config.h diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 8db336b2d727c..7d87831a80446 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -180,6 +180,10 @@ #endif #define _LIBUNWIND_HIGHEST_DWARF_REGISTER \ _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH +#elif defined(__wasm__) +// Unused +# define _LIBUNWIND_CONTEXT_SIZE 0 +# define _LIBUNWIND_CURSOR_SIZE 0 # else # error "Unsupported architecture." # endif diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c index 05d0f2cb0a0a7..48e7bc3b9e00e 100644 --- a/libunwind/src/UnwindLevel1.c +++ b/libunwind/src/UnwindLevel1.c @@ -31,7 +31,8 @@ #include "libunwind_ext.h" #include "unwind.h" -#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ +!defined(__wasm__) #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index 217dde9098637..7e5c6bd263e14 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -26,7 +26,7 @@ #include #endif -#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__) +#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) #include "AddressSpace.hpp" #include "UnwindCursor.hpp" @@ -348,7 +348,7 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) { #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) #endif // !defined(__USING_SJLJ_EXCEPTIONS__) && - // !defined(__USING_WASM_EXCEPTIONS__) + // !defined(__wasm__) #ifdef __APPLE__ >From 496e9b1652a2799c77626082a337803f9c907a3a Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 14 May 2024 23:48:37 + Subject: [PATCH 2/4] clang-format --- libunwind/include/__libunwind_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 7d87831a80446..028b9e3baa806 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -182,8 +182,8 @@ _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH #elif defined(__wasm__) // Unused -# define _LIBUNWIND_CONTEXT_SIZE 0 -# define _LIBUNWIND_CURSOR_SIZE 0 +#define _LIBUNWIND_CONTEXT_SIZE 0 +#define _LIBUNWIND_CURSOR_SIZE 0 # else # error "Unsupported architecture." # endif >From 86179cc37229612c4ee0011a4db8e738587b95db Mon Sep 17 00:00:00 2001 From:
[clang] [Clang][Sema] Diagnose current instantiation used as an incomplete base class (PR #92597)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) Changes Consider the following: ```cpp templatetypename T struct A { struct B : A { }; }; ``` According to [[class.derived.general] p2](http://eel.is/c++draft/class.derived.general#2): [...] A _class-or-decltype_ shall denote a (possibly cv-qualified) class type that is not an incompletely defined class; any cv-qualifiers are ignored. [...] Although GCC and EDG rejects this, Clang accepts it. This is incorrect, as `A` is incomplete within its own definition (outside of a complete-class context). This patch correctly diagnoses instances where the current instantiation is used as a base class before it is complete. Conversely, Clang erroneously rejects the following: ```cpp templatetypename T struct A { struct B; struct C : B { }; struct B : C { }; // error: circular inheritance between 'C' and 'A::B' }; ``` Though it may seem like no valid specialization of this template can be instantiated, an explicit specialization of either member classes for an implicit instantiated specialization of `A` would permit the definition of the other member class to be instantiated, e.g.: ```cpp template struct Aint::B { }; Aint::C c; // ok ``` So this patch also does away with this error. This means that circular inheritance is diagnosed during instantiation of the definition as a consequence of requiring the base class types to be complete (matching the behavior of GCC and EDG). --- Full diff: https://github.com/llvm/llvm-project/pull/92597.diff 8 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-2) - (modified) clang/lib/AST/Type.cpp (+9) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+50-108) - (modified) clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp (+7-3) - (added) clang/test/CXX/class.derived/class.derived.general/p2.cpp (+116) - (modified) clang/test/SemaTemplate/dependent-names.cpp (+8-6) - (modified) clang/test/SemaTemplate/destructor-template.cpp (+8-6) - (modified) clang/test/SemaTemplate/typo-dependent-name.cpp (+5-2) ``diff diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 59f44bc26eaf2..ee781d3155f66 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9449,8 +9449,6 @@ def err_static_data_member_not_allowed_in_local_class : Error< def err_base_clause_on_union : Error<"unions cannot have base classes">; def err_base_must_be_class : Error<"base specifier must name a class">; def err_union_as_base_class : Error<"unions cannot be base classes">; -def err_circular_inheritance : Error< - "circular inheritance between %0 and %1">; def err_base_class_has_flexible_array_member : Error< "base class %0 has a flexible array member">; def err_incomplete_base_class : Error<"base class has incomplete type">; diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index e31741cd44240..545725d1d7511 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2372,6 +2372,15 @@ bool Type::isIncompleteType(NamedDecl **Def) const { *Def = Rec; return !Rec->isCompleteDefinition(); } + case InjectedClassName: { +CXXRecordDecl *Rec = cast(CanonicalType)->getDecl(); +if (Rec->isBeingDefined()) { + if (Def) +*Def = Rec; + return true; +} +return false; + } case ConstantArray: case VariableArray: // An array is incomplete if its element type is incomplete diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8225381985052..c92f5f5406fec 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2656,38 +2656,6 @@ bool Sema::isCurrentClassNameTypo(IdentifierInfo *, const CXXScopeSpec *SS) { return false; } -/// Determine whether the given class is a base class of the given -/// class, including looking at dependent bases. -static bool findCircularInheritance(const CXXRecordDecl *Class, -const CXXRecordDecl *Current) { - SmallVector Queue; - - Class = Class->getCanonicalDecl(); - while (true) { -for (const auto : Current->bases()) { - CXXRecordDecl *Base = I.getType()->getAsCXXRecordDecl(); - if (!Base) -continue; - - Base = Base->getDefinition(); - if (!Base) -continue; - - if (Base->getCanonicalDecl() == Class) -return true; - - Queue.push_back(Base); -} - -if (Queue.empty()) - return false; - -Current = Queue.pop_back_val(); - } - - return false; -} - /// Check the validity of a C++ base class specifier. /// /// \returns a new CXXBaseSpecifier if well-formed, emits diagnostics @@ -2704,111 +2672,79 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, Access = AS_public; QualType BaseType = TInfo->getType(); + SourceLocation
[clang] [Clang][Sema] Diagnose current instantiation used as an incomplete base class (PR #92597)
https://github.com/sdkrystian created https://github.com/llvm/llvm-project/pull/92597 Consider the following: ```cpp template struct A { struct B : A { }; }; ``` According to [[class.derived.general] p2](http://eel.is/c++draft/class.derived.general#2): > [...] A _class-or-decltype_ shall denote a (possibly cv-qualified) class type > that is not an incompletely defined class; any cv-qualifiers are ignored. > [...] Although GCC and EDG rejects this, Clang accepts it. This is incorrect, as `A` is incomplete within its own definition (outside of a complete-class context). This patch correctly diagnoses instances where the current instantiation is used as a base class before it is complete. Conversely, Clang erroneously rejects the following: ```cpp template struct A { struct B; struct C : B { }; struct B : C { }; // error: circular inheritance between 'C' and 'A::B' }; ``` Though it may seem like no valid specialization of this template can be instantiated, an explicit specialization of either member classes for an implicit instantiated specialization of `A` would permit the definition of the other member class to be instantiated, e.g.: ```cpp template<> struct A::B { }; A::C c; // ok ``` So this patch also does away with this error. This means that circular inheritance is diagnosed during instantiation of the definition as a consequence of requiring the base class types to be complete (matching the behavior of GCC and EDG). >From 9d95d211797843f3dc612fe4340354b5fbf6a2fe Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 17 May 2024 13:30:04 -0400 Subject: [PATCH 1/4] [Clang][Sema] Diagnose current instantiation used a incomplete base class --- clang/lib/AST/Type.cpp| 4 + clang/lib/Sema/SemaDeclCXX.cpp| 116 +- .../basic.lookup.qual/class.qual/p2.cpp | 10 +- clang/test/SemaTemplate/dependent-names.cpp | 9 +- .../test/SemaTemplate/destructor-template.cpp | 14 ++- .../test/SemaTemplate/typo-dependent-name.cpp | 7 +- 6 files changed, 84 insertions(+), 76 deletions(-) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index e31741cd44240..4ad764b67f81f 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2372,6 +2372,10 @@ bool Type::isIncompleteType(NamedDecl **Def) const { *Def = Rec; return !Rec->isCompleteDefinition(); } + case InjectedClassName: { +CXXRecordDecl *Rec = cast(CanonicalType)->getDecl(); +return Rec->isBeingDefined(); + } case ConstantArray: case VariableArray: // An array is incomplete if its element type is incomplete diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8225381985052..84033a602f131 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2704,28 +2704,53 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, Access = AS_public; QualType BaseType = TInfo->getType(); + SourceLocation BaseLoc = TInfo->getTypeLoc().getBeginLoc(); if (BaseType->containsErrors()) { // Already emitted a diagnostic when parsing the error type. return nullptr; } - // C++ [class.union]p1: - // A union shall not have base classes. - if (Class->isUnion()) { -Diag(Class->getLocation(), diag::err_base_clause_on_union) - << SpecifierRange; -return nullptr; - } - if (EllipsisLoc.isValid() && - !TInfo->getType()->containsUnexpandedParameterPack()) { + if (EllipsisLoc.isValid() && !BaseType->containsUnexpandedParameterPack()) { Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs) << TInfo->getTypeLoc().getSourceRange(); EllipsisLoc = SourceLocation(); } - SourceLocation BaseLoc = TInfo->getTypeLoc().getBeginLoc(); + auto *BaseDecl = + dyn_cast_if_present(computeDeclContext(BaseType)); + // C++ [class.derived.general]p2: + // A class-or-decltype shall denote a (possibly cv-qualified) class type + // that is not an incompletely defined class; any cv-qualifiers are + // ignored. + if (BaseDecl) { +// C++ [class.union.general]p4: +// [...] A union shall not be used as a base class. +if (BaseDecl->isUnion()) { + Diag(BaseLoc, diag::err_union_as_base_class) << SpecifierRange; + return nullptr; +} + +// For the MS ABI, propagate DLL attributes to base class templates. +if (Context.getTargetInfo().getCXXABI().isMicrosoft() || +Context.getTargetInfo().getTriple().isPS()) { + if (Attr *ClassAttr = getDLLAttr(Class)) { +if (auto *BaseSpec = +dyn_cast(BaseDecl)) { + propagateDLLAttrToBaseClassTemplate(Class, ClassAttr, BaseSpec, + BaseLoc); +} + } +} - if (BaseType->isDependentType()) { +if (RequireCompleteType(BaseLoc, BaseType, diag::err_incomplete_base_class, +SpecifierRange)) { +
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: Test fixed by `112eadd55f06bee15caadff688ea0b45acbfa804`. https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] df575be - [clang][NFC] Add `const` qualifier in `Sema::isIncompatibleTypedef`
Author: Vlad Serebrennikov Date: 2024-05-17T23:10:12+03:00 New Revision: df575be9d864886684e536cd76c5a96bb0d443a6 URL: https://github.com/llvm/llvm-project/commit/df575be9d864886684e536cd76c5a96bb0d443a6 DIFF: https://github.com/llvm/llvm-project/commit/df575be9d864886684e536cd76c5a96bb0d443a6.diff LOG: [clang][NFC] Add `const` qualifier in `Sema::isIncompatibleTypedef` Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index cd06bd9c230df..d4d4a82525a02 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3309,7 +3309,7 @@ class Sema final : public SemaBase { /// Subroutines of ActOnDeclarator(). TypedefDecl *ParseTypedefDecl(Scope *S, Declarator , QualType T, TypeSourceInfo *TInfo); - bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); + bool isIncompatibleTypedef(const TypeDecl *Old, TypedefNameDecl *New); /// Describes the kind of merge to perform for availability /// attributes (including "deprecated", "unavailable", and "availability"). diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6c545d695fc9f..f2b9202255cd4 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2465,9 +2465,9 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, /// entity if their types are the same. /// FIXME: This is notionally doing the same thing as ASTReaderDecl's /// isSameEntity. -static void filterNonConflictingPreviousTypedefDecls(Sema , - TypedefNameDecl *Decl, - LookupResult ) { +static void +filterNonConflictingPreviousTypedefDecls(Sema , const TypedefNameDecl *Decl, + LookupResult ) { // This is only interesting when modules are enabled. if (!S.getLangOpts().Modules && !S.getLangOpts().ModulesLocalVisibility) return; @@ -2504,9 +2504,9 @@ static void filterNonConflictingPreviousTypedefDecls(Sema , Filter.done(); } -bool Sema::isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New) { +bool Sema::isIncompatibleTypedef(const TypeDecl *Old, TypedefNameDecl *New) { QualType OldType; - if (TypedefNameDecl *OldTypedef = dyn_cast(Old)) + if (const TypedefNameDecl *OldTypedef = dyn_cast(Old)) OldType = OldTypedef->getUnderlyingType(); else OldType = Context.getTypeDeclType(Old); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 112eadd - [Bounds-Safety] Fix `pragma-attribute-supported-attributes-list.test`
Author: Dan Liew Date: 2024-05-17T13:09:22-07:00 New Revision: 112eadd55f06bee15caadff688ea0b45acbfa804 URL: https://github.com/llvm/llvm-project/commit/112eadd55f06bee15caadff688ea0b45acbfa804 DIFF: https://github.com/llvm/llvm-project/commit/112eadd55f06bee15caadff688ea0b45acbfa804.diff LOG: [Bounds-Safety] Fix `pragma-attribute-supported-attributes-list.test` 0ec3b972e58bcbcdc1bebe1696ea37f2931287c3 changed the `counted_by` attribute to be `LateAttrParseExperimentalExt`. This means the attribute is no longer supported by `#pragma clang attribute`. However, the `pragma-attribute-supported-attributes-list.test` wasn't updated to account for that. rdar://125400257 Added: Modified: clang/test/Misc/pragma-attribute-supported-attributes-list.test Removed: diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test index fd0e6d71baa80..99732694f72a5 100644 --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -63,7 +63,6 @@ // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record) // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record) // CHECK-NEXT: CoroWrapper (SubjectMatchRule_function) -// CHECK-NEXT: CountedBy (SubjectMatchRule_field) // CHECK-NEXT: DLLExport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface) // CHECK-NEXT: DLLImport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface) // CHECK-NEXT: Destructor (SubjectMatchRule_function) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)
Endilll wrote: > It might violate https://eel.is/c++draft/temp.inst#11 to attempt to > instantiate the unused S::operator int? I don't think this clause of the standard is violated: you need to instantiate a declaration of the conversion function to at the end of definition of `M`, otherwise you can't "determine the correctness of the default member initializer" in `int x = S();`; https://github.com/llvm/llvm-project/pull/87933 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)
delcypher wrote: Looks like I broke the `clang/test/Misc/pragma-attribute-supported-attributes-list.test` test. I'll push a follow up fix to that test once I've confirmed I've fixed it. https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
https://github.com/zahiraam updated https://github.com/llvm/llvm-project/pull/88978 >From 3acc848f4fcc68445dfc849f9c6f8d384d3692af Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Tue, 16 Apr 2024 13:09:58 -0700 Subject: [PATCH 1/8] Adding C23 constexpr math functions fmin and frexp. --- clang/include/clang/Basic/Builtins.td | 4 +-- clang/lib/AST/ExprConstant.cpp| 16 - clang/test/CodeGen/constexpr-math.cpp | 51 +++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-math.cpp diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 52c0dd52c28b1..a35c77286229f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -3440,7 +3440,7 @@ def Fmod : FPMathTemplate, LibBuiltin<"math.h"> { def Frexp : FPMathTemplate, LibBuiltin<"math.h"> { let Spellings = ["frexp"]; - let Attributes = [NoThrow]; + let Attributes = [NoThrow, Constexpr]; let Prototype = "T(T, int*)"; let AddBuiltinPrefixedAlias = 1; } @@ -3618,7 +3618,7 @@ def Fmax : FPMathTemplate, LibBuiltin<"math.h"> { def Fmin : FPMathTemplate, LibBuiltin<"math.h"> { let Spellings = ["fmin"]; - let Attributes = [NoThrow, Const]; + let Attributes = [NoThrow, Const, Constexpr]; let Prototype = "T(T, T)"; let AddBuiltinPrefixedAlias = 1; let OnlyBuiltinPrefixedAliasIsConstexpr = 1; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5a36621dc5cce..506621ac7e9c1 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo , const BinaryOperator *E, // If during the evaluation of an expression, the result is not // mathematically defined [...], the behavior is undefined. // FIXME: C++ rules require us to not conform to IEEE 754 here. - if (LHS.isNaN()) { + if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) { Info.CCEDiag(E, diag::note_constexpr_float_arithmetic) << LHS.isNaN(); return Info.noteUndefinedBehavior(); } @@ -14547,6 +14547,18 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { default: return false; + case Builtin::BI__builtin_frexpf: + case Builtin::BI__builtin_frexp: { +LValue Pointer; +if (!EvaluateFloat(E->getArg(0), Result, Info) || +!EvaluatePointer(E->getArg(1), Pointer, Info)) + return false; +llvm::RoundingMode RM = +E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).getRoundingMode(); +int FrexpExp; +Result = llvm::frexp(Result, FrexpExp, RM); +return true; + } case Builtin::BI__builtin_huge_val: case Builtin::BI__builtin_huge_valf: case Builtin::BI__builtin_huge_vall: @@ -14638,6 +14650,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { return true; } + case Builtin::BIfmin: + case Builtin::BIfminf: case Builtin::BI__builtin_fmin: case Builtin::BI__builtin_fminf: case Builtin::BI__builtin_fminl: diff --git a/clang/test/CodeGen/constexpr-math.cpp b/clang/test/CodeGen/constexpr-math.cpp new file mode 100644 index 0..446bf3f4f7a50 --- /dev/null +++ b/clang/test/CodeGen/constexpr-math.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \ +// RUN: -emit-llvm -o - %s | FileCheck %s + +// RUN %clang_cc1 -x c++ -triple x86_64-linux-gnu -emit-llvm -o - %s \ +// RUN -std=c++23 + +#define INFINITY ((float)(1e+300 * 1e+300)) +#define NAN (-(float)(INFINITY * 0.0F)) + +//constexpr double frexp ( double num, int* exp ); +//constexpr float foo ( float num, int* exp ); + +int func() +{ + int i; + + // fmin + constexpr double f1 = __builtin_fmin(15.24, 1.3); + constexpr double f2 = __builtin_fmin(-0.0, +0.0); + constexpr double f3 = __builtin_fmin(+0.0, -0.0); + constexpr float f4 = __builtin_fminf(NAN, NAN); + constexpr float f5 = __builtin_fminf(NAN, -1); + constexpr float f6 = __builtin_fminf(-INFINITY, 0); + constexpr float f7 = __builtin_fminf(INFINITY, 0); + + // frexp + constexpr double f8 = __builtin_frexp(123.45, ); + constexpr double f9 = __builtin_frexp(0.0, ); + constexpr double f10 = __builtin_frexp(-0.0, ); + constexpr double f11 = __builtin_frexpf(NAN, ); + constexpr double f12 = __builtin_frexpf(-NAN, ); + constexpr double f13 = __builtin_frexpf(INFINITY, ); + constexpr double f14 = __builtin_frexpf(INFINITY, ); + + return 0; +} + +// CHECK: store double 1.30e+00, ptr {{.*}} +// CHECK: store double -0.00e+00, ptr {{.*}} +// CHECK: store double -0.00e+00, ptr {{.*}} +// CHECK: store float 0xFFF8, ptr {{.*}} +// CHECK: store float -1.00e+00, ptr {{.*}} +// CHECK: store float 0xFFF0, ptr {{.*}} + +// CHECK: store double 0x3FEEDCCD, ptr {{.*}} +// CHECK: store double 0.00e+00, ptr {{.*}} +// CHECK: store double -0.00e+00, ptr {{.*}} +// CHECK: store
[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)
@@ -20,7 +20,7 @@ .text #endif -#if !defined(__USING_SJLJ_EXCEPTIONS__) +#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) asl wrote: Ok. Then does the clang change really belong here? `LIBUNWIND_USES_WASM_EXCEPTIONS` also seems to be unused. https://github.com/llvm/llvm-project/pull/92192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] Run ObjCContractPass in Distributed Thin-LTO Pipeline (PR #92331)
aeubanks wrote: it seems like this should just be in the default codegen pipeline? you'd need to change the pass to bail out early if there are no relevant intrinsics (by checking if the module contains the intrinsic declaration) to not affect compile times https://github.com/llvm/llvm-project/pull/92331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)
@@ -20,7 +20,7 @@ .text #endif -#if !defined(__USING_SJLJ_EXCEPTIONS__) +#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) aheejin wrote: `__wasm__` is defined whenever we compile the code to wasm, and `__USING_WASM_EXCEPTIONS__` is defined when we compile the code to wasm and use Wasm exceptions (`-fwasm-exeptions`). And this code should be excluded whenever it is compiled to wasm, even if `-fwasm-exceptions` is not used. https://github.com/llvm/llvm-project/pull/92192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libunwind] [libunwind][WebAssembly] Make libunwind compilable (PR #92192)
@@ -20,7 +20,7 @@ .text #endif -#if !defined(__USING_SJLJ_EXCEPTIONS__) +#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) asl wrote: You are defining `__USING_WASM_EXCEPTIONS__`. Why you are not using it here and everywhere else? https://github.com/llvm/llvm-project/pull/92192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits