[llvm-branch-commits] [clang] 17f8c45 - [clang] Use SourceLocations in unions [NFCI]
Author: Mikhail Maltsev Date: 2021-01-14T10:56:53Z New Revision: 17f8c458de631c0311828931a5bdf72b1a13c29d URL: https://github.com/llvm/llvm-project/commit/17f8c458de631c0311828931a5bdf72b1a13c29d DIFF: https://github.com/llvm/llvm-project/commit/17f8c458de631c0311828931a5bdf72b1a13c29d.diff LOG: [clang] Use SourceLocations in unions [NFCI] Currently, there are many instances where `SourceLocation` objects are converted to raw representation to be stored in structs that are used as fields of tagged unions. This is done to make the corresponding structs trivial. Triviality allows avoiding undefined behavior when implicitly changing the active member of the union. However, in most cases, we can explicitly construct an active member using placement new. This patch adds the required active member selections and replaces `SourceLocation`-s represented as `unsigned int` with proper `SourceLocation`-s. One notable exception is `DeclarationNameLoc`: the objects of this class are often not properly initialized (so the code currently relies on its default constructor which uses memset). This class will be fixed in a separate patch. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D94237 Added: Modified: clang/include/clang/AST/DependentDiagnostic.h clang/include/clang/AST/Expr.h clang/include/clang/AST/TemplateBase.h clang/include/clang/Basic/SourceManager.h clang/include/clang/Sema/DeclSpec.h clang/include/clang/Sema/Designator.h clang/include/clang/Sema/Initialization.h clang/lib/AST/Expr.cpp clang/lib/AST/TemplateBase.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaType.cpp Removed: diff --git a/clang/include/clang/AST/DependentDiagnostic.h b/clang/include/clang/AST/DependentDiagnostic.h index 5a8624608e74..18276d54d540 100644 --- a/clang/include/clang/AST/DependentDiagnostic.h +++ b/clang/include/clang/AST/DependentDiagnostic.h @@ -48,7 +48,7 @@ class DependentDiagnostic { QualType BaseObjectType, const PartialDiagnostic &PDiag) { DependentDiagnostic *DD = Create(Context, Parent, PDiag); -DD->AccessData.Loc = Loc.getRawEncoding(); +DD->AccessData.Loc = Loc; DD->AccessData.IsMember = IsMemberAccess; DD->AccessData.Access = AS; DD->AccessData.TargetDecl = TargetDecl; @@ -73,7 +73,7 @@ class DependentDiagnostic { SourceLocation getAccessLoc() const { assert(getKind() == Access); -return SourceLocation::getFromRawEncoding(AccessData.Loc); +return AccessData.Loc; } NamedDecl *getAccessTarget() const { @@ -112,7 +112,7 @@ class DependentDiagnostic { PartialDiagnostic Diag; struct { -unsigned Loc; +SourceLocation Loc; unsigned Access : 2; unsigned IsMember : 1; NamedDecl *TargetDecl; diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index c8d87ec48a3f..a44d06967431 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4994,10 +4994,10 @@ class DesignatedInitExpr final uintptr_t NameOrField; /// The location of the '.' in the designated initializer. -unsigned DotLoc; +SourceLocation DotLoc; /// The location of the field name in the designated initializer. -unsigned FieldLoc; +SourceLocation FieldLoc; }; /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". @@ -5006,12 +5006,12 @@ class DesignatedInitExpr final /// initializer expression's list of subexpressions. unsigned Index; /// The location of the '[' starting the array range designator. -unsigned LBracketLoc; +SourceLocation LBracketLoc; /// The location of the ellipsis separating the start and end /// indices. Only valid for GNU array-range designators. -unsigned EllipsisLoc; +SourceLocation EllipsisLoc; /// The location of the ']' terminating the array range designator. -unsigned RBracketLoc; +SourceLocation RBracketLoc; }; /// Represents a single C99 designator. @@ -5043,29 +5043,32 @@ class DesignatedInitExpr final Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc) : Kind(FieldDesignator) { + new (&Field) DesignatedInitExpr::FieldDesignator; Field.NameOrField = reinterpret_cast(FieldName) | 0x01; - Field.DotLoc = DotLoc.getRawEncoding(); - Field.FieldLoc = FieldLoc.getRawEncoding(); + Field.DotLoc = DotLoc; + Field.FieldLoc = FieldLoc; } /// Initializes an array designator. Designator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc) : Kind(ArrayDesignator) { + new (&ArrayOrRange) Desi
[llvm-branch-commits] [clang-tools-extra] 176f5e9 - [clang-tidy] Use DenseSet in UpgradeDurationConversionsCheck, NFCI
Author: Mikhail Maltsev Date: 2021-01-14T13:50:16Z New Revision: 176f5e95e1afad75ff045a00f0fa9c781bd5f54a URL: https://github.com/llvm/llvm-project/commit/176f5e95e1afad75ff045a00f0fa9c781bd5f54a DIFF: https://github.com/llvm/llvm-project/commit/176f5e95e1afad75ff045a00f0fa9c781bd5f54a.diff LOG: [clang-tidy] Use DenseSet in UpgradeDurationConversionsCheck, NFCI This change replaces `unordered_set` (which used to store internal representation of `SourceLocation`-s) with `DenseSet` (which stores `SourceLocation`-s directly). Reviewed By: aaron.ballman, njames93 Differential Revision: https://reviews.llvm.org/D94601 Added: Modified: clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h Removed: diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp index 208d1df27763..539b575d1880 100644 --- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp @@ -128,7 +128,7 @@ void UpgradeDurationConversionsCheck::check( if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context) .empty()) { -if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) { +if (MatchedTemplateLocations.count(Loc) == 0) { // For each location matched in a template instantiation, we check if the // location can also be found in `MatchedTemplateLocations`. If it is not // found, that means the expression did not create a match without the @@ -144,7 +144,7 @@ void UpgradeDurationConversionsCheck::check( internal::Matcher IsInsideTemplate = hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl(; if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty()) -MatchedTemplateLocations.insert(Loc.getRawEncoding()); +MatchedTemplateLocations.insert(Loc); DiagnosticBuilder Diag = diag(Loc, Message); CharSourceRange SourceRange = Lexer::makeFileCharRange( diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h index 7a450a8e9249..23af29299f78 100644 --- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.h @@ -11,7 +11,8 @@ #include "../ClangTidyCheck.h" -#include +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/DenseSet.h" namespace clang { namespace tidy { @@ -32,7 +33,7 @@ class UpgradeDurationConversionsCheck : public ClangTidyCheck { void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - std::unordered_set MatchedTemplateLocations; + llvm::DenseSet MatchedTemplateLocations; }; } // namespace abseil ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] a0e3091 - [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI
Author: Mikhail Maltsev Date: 2021-01-22T13:01:41Z New Revision: a0e30914f8c8bb60795a008ce2d9e3c0a4f9b7a2 URL: https://github.com/llvm/llvm-project/commit/a0e30914f8c8bb60795a008ce2d9e3c0a4f9b7a2 DIFF: https://github.com/llvm/llvm-project/commit/a0e30914f8c8bb60795a008ce2d9e3c0a4f9b7a2.diff LOG: [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI The class `SymbolOccurrences` can store either a single `SourceRange` in-place or multiple `SourceRanges` on the heap. In the latter case the number of source ranges is stored in the internal representation of the beginning `SourceLocation` of the in-place `SourceRange` object. This change gets rid of such hack by placing `SourceRange` in a union which holds either a valid `SourceRange` or an `unsigned int` (a number of ranges). The change also adds `static_assert`s that check that `SourceRange` and `SourceLocation` are trivially destructible (this is required for the current patch and for D94237 which has already been committed). Reviewed By: MarkMurrayARM, simon_tatham Differential Revision: https://reviews.llvm.org/D94599 Added: Modified: clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h clang/lib/Basic/SourceLocation.cpp clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp Removed: diff --git a/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h b/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h index 3b903cb822f3..c4bfaa9cc377 100644 --- a/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h +++ b/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h @@ -69,17 +69,18 @@ class SymbolOccurrence { OccurrenceKind getKind() const { return Kind; } ArrayRef getNameRanges() const { -if (MultipleRanges) { - return llvm::makeArrayRef(MultipleRanges.get(), -RangeOrNumRanges.getBegin().getRawEncoding()); -} -return RangeOrNumRanges; +if (MultipleRanges) + return llvm::makeArrayRef(MultipleRanges.get(), NumRanges); +return SingleRange; } private: OccurrenceKind Kind; std::unique_ptr MultipleRanges; - SourceRange RangeOrNumRanges; + union { +SourceRange SingleRange; +unsigned NumRanges; + }; }; using SymbolOccurrences = std::vector; diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index fde139932c40..6f6412028d77 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -42,6 +42,14 @@ void PrettyStackTraceLoc::print(raw_ostream &OS) const { // SourceLocation //===--===// +static_assert(std::is_trivially_destructible::value, + "SourceLocation must be trivially destructible because it is " + "used in unions"); + +static_assert(std::is_trivially_destructible::value, + "SourceRange must be trivially destructible because it is " + "used in unions"); + unsigned SourceLocation::getHashValue() const { return llvm::DenseMapInfo::getHashValue(ID); } diff --git a/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp b/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp index 9e69d37e81ad..762864c953d8 100644 --- a/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp @@ -21,13 +21,12 @@ SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind, "mismatching number of locations and lengths"); assert(!Locations.empty() && "no locations"); if (Locations.size() == 1) { -RangeOrNumRanges = SourceRange( +new (&SingleRange) SourceRange( Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size())); return; } MultipleRanges = std::make_unique(Locations.size()); - RangeOrNumRanges.setBegin( - SourceLocation::getFromRawEncoding(Locations.size())); + NumRanges = Locations.size(); for (const auto &Loc : llvm::enumerate(Locations)) { MultipleRanges[Loc.index()] = SourceRange( Loc.value(), ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] 7da3e3a - [libcxx] Mark a test as unsupported for C++03
Author: Mikhail Maltsev Date: 2021-01-07T12:06:08Z New Revision: 7da3e3a8983a079cbed874b924dd34dd6b6a4001 URL: https://github.com/llvm/llvm-project/commit/7da3e3a8983a079cbed874b924dd34dd6b6a4001 DIFF: https://github.com/llvm/llvm-project/commit/7da3e3a8983a079cbed874b924dd34dd6b6a4001.diff LOG: [libcxx] Mark a test as unsupported for C++03 The nullptr_t_integral_cast.pass.cpp test is currently xfailed for C++03, but actually, it only fails with the first version of libc++ ABI. This patch changes XFAIL to UNSUPPORTED to avoid unexpected passes with ABI v2 or later. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D93941 Added: Modified: libcxx/test/std/language.support/support.types/nullptr_t_integral_cast.pass.cpp Removed: diff --git a/libcxx/test/std/language.support/support.types/nullptr_t_integral_cast.pass.cpp b/libcxx/test/std/language.support/support.types/nullptr_t_integral_cast.pass.cpp index 4c39f4c532b8..779905659e6c 100644 --- a/libcxx/test/std/language.support/support.types/nullptr_t_integral_cast.pass.cpp +++ b/libcxx/test/std/language.support/support.types/nullptr_t_integral_cast.pass.cpp @@ -6,9 +6,9 @@ // //===--===// -// NOTE: nullptr_t emulation cannot handle a reinterpret_cast to an -// integral type -// XFAIL: c++03 +// NOTE: nullptr_t emulation (used in libc++ ABI v.1) cannot handle a +// reinterpret_cast to an integral type +// UNSUPPORTED: c++03 // typedef decltype(nullptr) nullptr_t; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 9f76788 - [clang][Sema] Compare SourceLocations directly [NFCI]
Author: Mikhail Maltsev Date: 2021-01-09T14:13:18Z New Revision: 9f76788b0930ed48f5f20a25f1b30d63c8486531 URL: https://github.com/llvm/llvm-project/commit/9f76788b0930ed48f5f20a25f1b30d63c8486531 DIFF: https://github.com/llvm/llvm-project/commit/9f76788b0930ed48f5f20a25f1b30d63c8486531.diff LOG: [clang][Sema] Compare SourceLocations directly [NFCI] The ordered comparison operators are defined for the SourceLocation class, so SourceLocation objects can be compared directly. There is no need to extract the internal representation for comparison. Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D94231 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaStmt.cpp Removed: diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 3a1294ce431f..dd31f3f98487 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -436,9 +436,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Res != ResEnd; ++Res) { if (isa(*Res) || isa(*Res) || (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) { -if (!IIDecl || -(*Res)->getLocation().getRawEncoding() < - IIDecl->getLocation().getRawEncoding()) +if (!IIDecl || (*Res)->getLocation() < IIDecl->getLocation()) IIDecl = *Res; } } diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index a47fdf625bba..b24a8ab110b2 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -672,8 +672,7 @@ static bool CmpCaseVals(const std::pair& lhs, return true; if (lhs.first == rhs.first && - lhs.second->getCaseLoc().getRawEncoding() - < rhs.second->getCaseLoc().getRawEncoding()) + lhs.second->getCaseLoc() < rhs.second->getCaseLoc()) return true; return false; } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] c1e08f0 - [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]
Author: Mikhail Maltsev Date: 2021-01-12T10:22:35Z New Revision: c1e08f0073e35cf17c0a0343cf7efff914dbd66d URL: https://github.com/llvm/llvm-project/commit/c1e08f0073e35cf17c0a0343cf7efff914dbd66d DIFF: https://github.com/llvm/llvm-project/commit/c1e08f0073e35cf17c0a0343cf7efff914dbd66d.diff LOG: [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI] This code currently uses a union object to increase the alignment of the type ObjCTypeParamList. The original intent of this trick was to be able to use the expression `this + 1` to access the beginning of a tail-allocated array of `ObjCTypeParamDecl *` pointers. The code has since been refactored and uses `llvm::TrailingObjects` to manage the tail-allocated array. This template takes care of alignment, so the hack is no longer necessary. This patch removes the union so that the `SourceRange` class can be used directly instead of being re-implemented with raw representations of source locations. Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D94224 Added: Modified: clang/include/clang/AST/DeclObjC.h clang/lib/AST/DeclObjC.cpp Removed: diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 88cedbd91b6d..b1bce069920c 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -656,20 +656,8 @@ class ObjCTypeParamDecl : public TypedefNameDecl { /// \endcode class ObjCTypeParamList final : private llvm::TrailingObjects { - /// Stores the components of a SourceRange as a POD. - struct PODSourceRange { -unsigned Begin; -unsigned End; - }; - - union { -/// Location of the left and right angle brackets. -PODSourceRange Brackets; - -// Used only for alignment. -ObjCTypeParamDecl *AlignmentHack; - }; - + /// Location of the left and right angle brackets. + SourceRange Brackets; /// The number of parameters in the list, which are tail-allocated. unsigned NumParams; @@ -717,17 +705,9 @@ class ObjCTypeParamList final return *(end() - 1); } - SourceLocation getLAngleLoc() const { -return SourceLocation::getFromRawEncoding(Brackets.Begin); - } - - SourceLocation getRAngleLoc() const { -return SourceLocation::getFromRawEncoding(Brackets.End); - } - - SourceRange getSourceRange() const { -return SourceRange(getLAngleLoc(), getRAngleLoc()); - } + SourceLocation getLAngleLoc() const { return Brackets.getBegin(); } + SourceLocation getRAngleLoc() const { return Brackets.getEnd(); } + SourceRange getSourceRange() const { return Brackets; } /// Gather the default set of type arguments to be substituted for /// these type parameters when dealing with an unspecialized type. diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 961230fb54ce..5f82fcec90e3 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -1461,9 +1461,7 @@ SourceRange ObjCTypeParamDecl::getSourceRange() const { ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc, ArrayRef typeParams, SourceLocation rAngleLoc) -: NumParams(typeParams.size()) { - Brackets.Begin = lAngleLoc.getRawEncoding(); - Brackets.End = rAngleLoc.getRawEncoding(); +: Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) { std::copy(typeParams.begin(), typeParams.end(), begin()); } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] 6af8758 - [libcxx] Handle target triples with dashes in platform name
Author: Mikhail Maltsev Date: 2020-09-11T14:42:05+01:00 New Revision: 6af8758ba4d7c42298a14fcc2433f9ab49215ac1 URL: https://github.com/llvm/llvm-project/commit/6af8758ba4d7c42298a14fcc2433f9ab49215ac1 DIFF: https://github.com/llvm/llvm-project/commit/6af8758ba4d7c42298a14fcc2433f9ab49215ac1.diff LOG: [libcxx] Handle target triples with dashes in platform name Target triples may contain a dash in the platform name (e.g. "aarch64-arm-none-eabi"). Account for it when splitting the triple into components. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D87508 Added: Modified: libcxx/utils/libcxx/test/config.py Removed: diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py index 086db1d7f560..42438b3ccf2e 100644 --- a/libcxx/utils/libcxx/test/config.py +++ b/libcxx/utils/libcxx/test/config.py @@ -245,7 +245,7 @@ def configure_features(self): # XFAIL markers for tests that are known to fail with versions of # libc++ as were shipped with a particular triple. if self.use_system_cxx_lib: -(arch, vendor, platform) = self.config.target_triple.split('-') +(arch, vendor, platform) = self.config.target_triple.split('-', 2) (sysname, version) = re.match(r'([^0-9]+)([0-9\.]*)', platform).groups() self.config.available_features.add('with_system_cxx_lib={}-{}-{}{}'.format(arch, vendor, sysname, version)) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits