Skip to content

Commit

Permalink
Revert "Rename llvm::array_lengthof into llvm::size to match std::siz…
Browse files Browse the repository at this point in the history
…e from C++17"

This reverts commit ef82063.

- It conflicts with the existing llvm::size in STLExtras, which will now
  never be called.
- Calling it without llvm:: breaks C++17 compat
  • Loading branch information
d0k committed Jan 26, 2022
1 parent 297bbf1 commit f15014f
Show file tree
Hide file tree
Showing 143 changed files with 382 additions and 386 deletions.
12 changes: 6 additions & 6 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -5772,11 +5772,11 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
/*SupportsMapper=*/true, &MapperQualifierLoc,
&MapperIdInfo),
MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
assert(llvm::size(MapTypeModifiers) == MapModifiers.size() &&
assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
"Unexpected number of map type modifiers.");
llvm::copy(MapModifiers, std::begin(MapTypeModifiers));

assert(llvm::size(MapTypeModifiersLoc) ==
assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
MapModifiersLoc.size() &&
"Unexpected number of map type modifier locations.");
llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
Expand Down Expand Up @@ -6694,11 +6694,11 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
: OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
/*SupportsMapper=*/true, &MapperQualifierLoc,
&MapperIdInfo) {
assert(llvm::size(MotionModifiers) == TheMotionModifiers.size() &&
assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
"Unexpected number of motion modifiers.");
llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));

assert(llvm::size(MotionModifiersLoc) ==
assert(llvm::array_lengthof(MotionModifiersLoc) ==
TheMotionModifiersLoc.size() &&
"Unexpected number of motion modifier locations.");
llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
Expand Down Expand Up @@ -6896,11 +6896,11 @@ class OMPFromClause final
: OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
/*SupportsMapper=*/true, &MapperQualifierLoc,
&MapperIdInfo) {
assert(llvm::size(MotionModifiers) == TheMotionModifiers.size() &&
assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
"Unexpected number of motion modifiers.");
llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));

assert(llvm::size(MotionModifiersLoc) ==
assert(llvm::array_lengthof(MotionModifiersLoc) ==
TheMotionModifiersLoc.size() &&
"Unexpected number of motion modifier locations.");
llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6594,7 +6594,7 @@ QualType ASTContext::getPromotedIntegerType(QualType Promotable) const {
uint64_t FromSize = getTypeSize(BT);
QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy,
LongLongTy, UnsignedLongLongTy };
for (size_t Idx = 0; Idx < llvm::size(PromoteTypes); ++Idx) {
for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) {
uint64_t ToSize = getTypeSize(PromoteTypes[Idx]);
if (FromSize < ToSize ||
(FromSize == ToSize &&
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/AttrDocTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const llvm::StringRef AttrDoc[] = {
};

llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
if(K < llvm::size(AttrDoc))
if(K < llvm::array_lengthof(AttrDoc))
return AttrDoc[K];
return "";
}
6 changes: 3 additions & 3 deletions clang/lib/AST/CommentCommandTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace comments {

CommandTraits::CommandTraits(llvm::BumpPtrAllocator &Allocator,
const CommentOptions &CommentOptions) :
NextID(llvm::size(Commands)), Allocator(Allocator) {
NextID(llvm::array_lengthof(Commands)), Allocator(Allocator) {
registerCommentOptions(CommentOptions);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ const CommandInfo *CommandTraits::registerBlockCommand(StringRef CommandName) {

const CommandInfo *CommandTraits::getBuiltinCommandInfo(
unsigned CommandID) {
if (CommandID < llvm::size(Commands))
if (CommandID < llvm::array_lengthof(Commands))
return &Commands[CommandID];
return nullptr;
}
Expand All @@ -131,7 +131,7 @@ const CommandInfo *CommandTraits::getRegisteredCommandInfo(

const CommandInfo *CommandTraits::getRegisteredCommandInfo(
unsigned CommandID) const {
return RegisteredCommands[CommandID - llvm::size(Commands)];
return RegisteredCommands[CommandID - llvm::array_lengthof(Commands)];
}

} // end namespace comments
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/DiagnosticIDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const StaticDiagInfoRec StaticDiagInfo[] = {

} // namespace

static const unsigned StaticDiagInfoSize = llvm::size(StaticDiagInfo);
static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo);

/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
/// or null if the ID is invalid.
Expand Down Expand Up @@ -317,7 +317,7 @@ static const StaticDiagCategoryRec CategoryNameTable[] = {

/// getNumberOfCategories - Return the number of categories
unsigned DiagnosticIDs::getNumberOfCategories() {
return llvm::size(CategoryNameTable) - 1;
return llvm::array_lengthof(CategoryNameTable) - 1;
}

/// getCategoryNameFromID - Given a category ID, return the name of the
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/NVPTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
/// DWARF.
Optional<unsigned>
getDWARFAddressSpace(unsigned AddressSpace) const override {
if (AddressSpace >= llvm::size(NVPTXDWARFAddrSpaceMap) ||
if (AddressSpace >= llvm::array_lengthof(NVPTXDWARFAddrSpaceMap) ||
NVPTXDWARFAddrSpaceMap[AddressSpace] < 0)
return llvm::None;
return NVPTXDWARFAddrSpaceMap[AddressSpace];
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3206,7 +3206,7 @@ void CodeGenFunction::EmitCheck(
assert(IsSanitizerScope);
assert(Checked.size() > 0);
assert(CheckHandler >= 0 &&
size_t(CheckHandler) < llvm::size(SanitizerHandlers));
size_t(CheckHandler) < llvm::array_lengthof(SanitizerHandlers));
const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;

llvm::Value *FatalCond = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
&CGM.getContext().Idents.get("count")
};
Selector FastEnumSel =
CGM.getContext().Selectors.getSelector(llvm::size(II), &II[0]);
CGM.getContext().Selectors.getSelector(llvm::array_lengthof(II), &II[0]);

QualType ItemsTy =
getContext().getConstantArrayType(getContext().getObjCIdType(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void Compilation::initCompilationForDiagnostics() {
options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M,
options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ,
options::OPT_MQ, options::OPT_MT, options::OPT_MV};
for (unsigned i = 0, e = llvm::size(OutputOpts); i != e; ++i) {
for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
if (TranslatedArgs->hasArg(OutputOpts[i]))
TranslatedArgs->eraseArg(OutputOpts[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
{"flang", "--driver-mode=flang"},
};

for (size_t i = 0; i < llvm::size(DriverSuffixes); ++i) {
for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i) {
StringRef Suffix(DriverSuffixes[i].Suffix);
if (ProgName.endswith(Suffix)) {
Pos = ProgName.size() - Suffix.size();
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver,
"TVOS_DEPLOYMENT_TARGET",
"WATCHOS_DEPLOYMENT_TARGET",
};
static_assert(llvm::size(EnvVars) == Darwin::LastDarwinPlatform + 1,
static_assert(llvm::array_lengthof(EnvVars) == Darwin::LastDarwinPlatform + 1,
"Missing platform");
for (const auto &I : llvm::enumerate(llvm::makeArrayRef(EnvVars))) {
if (char *Env = ::getenv(I.value()))
Expand All @@ -1715,11 +1715,11 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver,
Targets[Darwin::TvOS] = "";
} else {
// Don't allow conflicts in any other platform.
unsigned FirstTarget = llvm::size(Targets);
for (unsigned I = 0; I != llvm::size(Targets); ++I) {
unsigned FirstTarget = llvm::array_lengthof(Targets);
for (unsigned I = 0; I != llvm::array_lengthof(Targets); ++I) {
if (Targets[I].empty())
continue;
if (FirstTarget == llvm::size(Targets))
if (FirstTarget == llvm::array_lengthof(Targets))
FirstTarget = I;
else
TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static constexpr TypeInfo TypeInfos[] = {
#include "clang/Driver/Types.def"
#undef TYPE
};
static const unsigned numTypes = llvm::size(TypeInfos);
static const unsigned numTypes = llvm::array_lengthof(TypeInfos);

static const TypeInfo &getInfo(unsigned id) {
assert(id > 0 && id - 1 < numTypes && "Invalid Type ID.");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/PrintPreprocessedOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
} else if (Tok.isLiteral() && !Tok.needsCleaning() &&
Tok.getLiteralData()) {
OS.write(Tok.getLiteralData(), Tok.getLength());
} else if (Tok.getLength() < llvm::size(Buffer)) {
} else if (Tok.getLength() < llvm::array_lengthof(Buffer)) {
const char *TokPtr = Buffer;
unsigned Len = PP.getSpelling(Tok, TokPtr);
OS.write(TokPtr, Len);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ void Parser::ParseExternalSourceSymbolAttribute(
ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(),
GeneratedDeclaration};
Attrs.addNew(&ExternalSourceSymbol, SourceRange(Loc, T.getCloseLocation()),
ScopeName, ScopeLoc, Args, llvm::size(Args), Syntax);
ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
}

/// Parse the contents of the "objc_bridge_related" attribute.
Expand Down Expand Up @@ -1493,7 +1493,7 @@ void Parser::ParseSwiftNewTypeAttribute(

ArgsUnion Args[] = {SwiftType};
Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, T.getCloseLocation()),
ScopeName, ScopeLoc, Args, llvm::size(Args), Syntax);
ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
}


Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) {
if (DKind == OMPD_unknown)
return OMPD_unknown;

for (unsigned I = 0; I < llvm::size(F); ++I) {
for (unsigned I = 0; I < llvm::array_lengthof(F); ++I) {
if (DKind != F[I][0])
continue;

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/DeclSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
// is already used (consider a function returning a function pointer) or too
// small (function with too many parameters), go to the heap.
if (!TheDeclarator.InlineStorageUsed &&
NumParams <= llvm::size(TheDeclarator.InlineParams)) {
NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
I.Fun.Params = TheDeclarator.InlineParams;
new (I.Fun.Params) ParamInfo[NumParams];
I.Fun.DeleteParams = false;
Expand Down Expand Up @@ -308,7 +308,7 @@ void Declarator::setDecompositionBindings(
// Allocate storage for bindings and stash them away.
if (Bindings.size()) {
if (!InlineStorageUsed &&
Bindings.size() <= llvm::size(InlineBindings)) {
Bindings.size() <= llvm::array_lengthof(InlineBindings)) {
BindingGroup.Bindings = InlineBindings;
BindingGroup.DeleteBindings = false;
InlineStorageUsed = true;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/ParsedAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace {

const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
// If we have a ParsedAttrInfo for this ParsedAttr then return that.
if ((size_t)A.getParsedKind() < llvm::size(AttrInfoMap))
if ((size_t)A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
return *AttrInfoMap[A.getParsedKind()];

// If this is an ignored attribute then return an appropriate ParsedAttrInfo.
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4726,7 +4726,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
"extern", "inline", "static", "typedef"
};

const unsigned NumCTypeSpecs = llvm::size(CTypeSpecs);
const unsigned NumCTypeSpecs = llvm::array_lengthof(CTypeSpecs);
for (unsigned I = 0; I != NumCTypeSpecs; ++I)
Consumer.addKeywordResult(CTypeSpecs[I]);

Expand Down Expand Up @@ -4780,7 +4780,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
static const char *const CXXExprs[] = {
"delete", "new", "operator", "throw", "typeid"
};
const unsigned NumCXXExprs = llvm::size(CXXExprs);
const unsigned NumCXXExprs = llvm::array_lengthof(CXXExprs);
for (unsigned I = 0; I != NumCXXExprs; ++I)
Consumer.addKeywordResult(CXXExprs[I]);

Expand All @@ -4806,7 +4806,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
// Statements.
static const char *const CStmts[] = {
"do", "else", "for", "goto", "if", "return", "switch", "while" };
const unsigned NumCStmts = llvm::size(CStmts);
const unsigned NumCStmts = llvm::array_lengthof(CStmts);
for (unsigned I = 0; I != NumCStmts; ++I)
Consumer.addKeywordResult(CStmts[I]);

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14357,7 +14357,7 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
};
const unsigned NumTypes = llvm::size(Types);
const unsigned NumTypes = llvm::array_lengthof(Types);
QualType SizeType;
for (unsigned I = 0; I != NumTypes; ++I)
if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ int main(){

// <rdar://problem/11949235>
template<class T, unsigned N>
inline unsigned size(T (&)[N]) {
inline unsigned array_lengthof(T (&)[N]) {
return N;
}

void testNonTypeTemplateInstantiation() {
const char *S[] = { "a", "b" };
clang_analyzer_eval(size(S) == 2);
clang_analyzer_eval(array_lengthof(S) == 2);
#ifndef NO_INLINE
// expected-warning@-2 {{TRUE}}
#else
Expand Down
10 changes: 5 additions & 5 deletions clang/test/SemaTemplate/instantiate-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace PR7985 {
template<int N> struct integral_c { };

template <typename T, int N>
integral_c<N> size(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T[N]' against 'const Data<}}
integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T[N]' against 'const Data<}}

template<typename T>
struct Data {
Expand All @@ -105,14 +105,14 @@ namespace PR7985 {
const Data<float*> Description<float*>::data[];

void test() {
integral_c<1> ic1 = size(Description<int>::data);
(void)sizeof(size(Description<float>::data));
integral_c<1> ic1 = array_lengthof(Description<int>::data);
(void)sizeof(array_lengthof(Description<float>::data));

(void)sizeof(size( // expected-error{{no matching function for call to 'size'}}
(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
));

size(Description<float*>::data); // expected-error{{no matching function for call to 'size'}}
array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
}
}

Expand Down
Loading

0 comments on commit f15014f

Please sign in to comment.