From 324f918438715b4a0d024af5930628c1674f4fcd Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 19 Jan 2019 08:50:56 +0000 Subject: Update the file headers across all of the LLVM projects in the monorepo to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index ed780efd4c..574fa4d64a 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1,9 +1,8 @@ //===--- SemaExprObjC.cpp - Semantic Analysis for ObjC Expressions --------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // -- cgit v1.2.3 From d4197d25f51c022ce7ca24d39f6619aa621d7804 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Sat, 26 Jan 2019 14:15:10 +0000 Subject: [AST] Pack GenericSelectionExpr Store the controlling expression, the association expressions and the corresponding TypeSourceInfos as trailing objects. Additionally use the bit-fields of Stmt to store one SourceLocation, saving one additional pointer. This saves 3 pointers in total per GenericSelectionExpr. Differential Revision: https://reviews.llvm.org/D57104 Reviewed By: aaron.ballman Reviewers: aaron.ballman, steveire git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352276 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 574fa4d64a..4ca3b851c1 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -4342,13 +4342,10 @@ Expr *Sema::stripARCUnbridgedCast(Expr *e) { subExprs[i] = sub; } - return new (Context) GenericSelectionExpr(Context, gse->getGenericLoc(), - gse->getControllingExpr(), - subTypes, subExprs, - gse->getDefaultLoc(), - gse->getRParenLoc(), - gse->containsUnexpandedParameterPack(), - gse->getResultIndex()); + return GenericSelectionExpr::Create( + Context, gse->getGenericLoc(), gse->getControllingExpr(), subTypes, + subExprs, gse->getDefaultLoc(), gse->getRParenLoc(), + gse->containsUnexpandedParameterPack(), gse->getResultIndex()); } else { assert(isa(e) && "bad form of unbridged cast!"); return cast(e)->getSubExpr(); -- cgit v1.2.3 From b43033c532d2cea761b9766ed4b47d7b7840693b Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Mon, 28 Jan 2019 14:18:11 +0000 Subject: [AST] Introduce GenericSelectionExpr::Association Introduce a new class GenericSelectionExpr::Association which bundle together an association expression and its TypeSourceInfo. An iterator GenericSelectionExpr::AssociationIterator is additionally added to make it possible to iterate over ranges of Associations. This iterator is a kind of proxy iterator which abstract over how exactly the expressions and the TypeSourceInfos are stored. Differential Revision: https://reviews.llvm.org/D57106 Reviewed By: aaron.ballman Reviewers: aaron.ballman, steveire, dblaikie, mclow.lists git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352369 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 4ca3b851c1..fdb59874cc 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -4332,14 +4332,16 @@ Expr *Sema::stripARCUnbridgedCast(Expr *e) { assert(!gse->isResultDependent()); unsigned n = gse->getNumAssocs(); - SmallVector subExprs(n); - SmallVector subTypes(n); - for (unsigned i = 0; i != n; ++i) { - subTypes[i] = gse->getAssocTypeSourceInfo(i); - Expr *sub = gse->getAssocExpr(i); - if (i == gse->getResultIndex()) + SmallVector subExprs; + SmallVector subTypes; + subExprs.reserve(n); + subTypes.reserve(n); + for (const GenericSelectionExpr::Association &assoc : gse->associations()) { + subTypes.push_back(assoc.getTypeSourceInfo()); + Expr *sub = assoc.getAssociationExpr(); + if (assoc.isSelected()) sub = stripARCUnbridgedCast(sub); - subExprs[i] = sub; + subExprs.push_back(sub); } return GenericSelectionExpr::Create( -- cgit v1.2.3 From 5cc8b40460b34dece34bf972a1632148185171b3 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Mon, 28 Jan 2019 18:40:26 +0000 Subject: Revert "[AST] Introduce GenericSelectionExpr::Association" This breaks GCC 4.8.4. Reported by email by Hans Wennborg. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352403 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index fdb59874cc..4ca3b851c1 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -4332,16 +4332,14 @@ Expr *Sema::stripARCUnbridgedCast(Expr *e) { assert(!gse->isResultDependent()); unsigned n = gse->getNumAssocs(); - SmallVector subExprs; - SmallVector subTypes; - subExprs.reserve(n); - subTypes.reserve(n); - for (const GenericSelectionExpr::Association &assoc : gse->associations()) { - subTypes.push_back(assoc.getTypeSourceInfo()); - Expr *sub = assoc.getAssociationExpr(); - if (assoc.isSelected()) + SmallVector subExprs(n); + SmallVector subTypes(n); + for (unsigned i = 0; i != n; ++i) { + subTypes[i] = gse->getAssocTypeSourceInfo(i); + Expr *sub = gse->getAssocExpr(i); + if (i == gse->getResultIndex()) sub = stripARCUnbridgedCast(sub); - subExprs.push_back(sub); + subExprs[i] = sub; } return GenericSelectionExpr::Create( -- cgit v1.2.3 From d507ee11ead38846eec05eae085c6935abcead47 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Tue, 29 Jan 2019 12:57:11 +0000 Subject: Re-commit "[AST] Introduce GenericSelectionExpr::Association" This time with a fix to make gcc 4.8 happy. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352486 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 4ca3b851c1..fdb59874cc 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -4332,14 +4332,16 @@ Expr *Sema::stripARCUnbridgedCast(Expr *e) { assert(!gse->isResultDependent()); unsigned n = gse->getNumAssocs(); - SmallVector subExprs(n); - SmallVector subTypes(n); - for (unsigned i = 0; i != n; ++i) { - subTypes[i] = gse->getAssocTypeSourceInfo(i); - Expr *sub = gse->getAssocExpr(i); - if (i == gse->getResultIndex()) + SmallVector subExprs; + SmallVector subTypes; + subExprs.reserve(n); + subTypes.reserve(n); + for (const GenericSelectionExpr::Association &assoc : gse->associations()) { + subTypes.push_back(assoc.getTypeSourceInfo()); + Expr *sub = assoc.getAssociationExpr(); + if (assoc.isSelected()) sub = stripARCUnbridgedCast(sub); - subExprs[i] = sub; + subExprs.push_back(sub); } return GenericSelectionExpr::Create( -- cgit v1.2.3 From 24cae3f9a09510fe5c6937d74d83c418e4c01365 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Mon, 4 Feb 2019 23:30:57 +0000 Subject: [SemaObjC] Don't infer the availabilty of +new from -init if the receiver has Class type rdar://47713266 Differential revision: https://reviews.llvm.org/D57712 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353115 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index fdb59874cc..4b7e320b15 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -2805,8 +2805,8 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, } else { if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) { if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) { - // FIXME: Is this correct? Why are we assuming that a message to - // Class will call a method in the current interface? + // As a guess, try looking for the method in the current interface. + // This very well may not produce the "right" method. // First check the public methods in the class interface. Method = ClassDecl->lookupClassMethod(Sel); @@ -2814,8 +2814,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, if (!Method) Method = ClassDecl->lookupPrivateClassMethod(Sel); - if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, nullptr, - false, false, ClassDecl)) + if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs)) return ExprError(); } } -- cgit v1.2.3 From 4874bff565a9f92c41a1efad0b3d633371b5930c Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Fri, 8 Mar 2019 04:45:37 +0000 Subject: [ObjC] Emit a boxed expression as a compile-time constant if the expression inside the parentheses is a valid UTF-8 string literal. Previously clang emitted an expression like @("abc") as a message send to stringWithUTF8String. This commit makes clang emit the boxed expression as a compile-time constant instead. This commit also has the effect of silencing the nullable-to-nonnull conversion warning clang started emitting after r317727, which originally motivated this commit (see https://oleb.net/2018/@keypath). rdar://problem/42684601 Differential Revision: https://reviews.llvm.org/D58729 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355662 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 4b7e320b15..d6c656e06b 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -25,6 +25,7 @@ #include "clang/Sema/Scope.h" #include "clang/Sema/ScopeInfo.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/ConvertUTF.h" using namespace clang; using namespace sema; @@ -524,6 +525,30 @@ ExprResult Sema::BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { NSStringPointer = Context.getObjCObjectPointerType(NSStringObject); } + // The boxed expression can be emitted as a compile time constant if it is + // a string literal whose character encoding is compatible with UTF-8. + if (auto *CE = dyn_cast(ValueExpr)) + if (CE->getCastKind() == CK_ArrayToPointerDecay) + if (auto *SL = + dyn_cast(CE->getSubExpr()->IgnoreParens())) { + assert((SL->isAscii() || SL->isUTF8()) && + "unexpected character encoding"); + StringRef Str = SL->getString(); + const llvm::UTF8 *StrBegin = Str.bytes_begin(); + const llvm::UTF8 *StrEnd = Str.bytes_end(); + // Check that this is a valid UTF-8 string. + if (llvm::isLegalUTF8String(&StrBegin, StrEnd)) { + BoxedType = Context.getAttributedType( + AttributedType::getNullabilityAttrKind( + NullabilityKind::NonNull), + NSStringPointer, NSStringPointer); + return new (Context) ObjCBoxedExpr(CE, BoxedType, nullptr, SR); + } + + Diag(SL->getBeginLoc(), diag::warn_objc_boxing_invalid_utf8_string) + << NSStringPointer << SL->getSourceRange(); + } + if (!StringWithUTF8StringMethod) { IdentifierInfo *II = &Context.Idents.get("stringWithUTF8String"); Selector stringWithUTF8String = Context.Selectors.getUnarySelector(II); -- cgit v1.2.3 From 62e8a2946b0928cb349cee4acb6fb64f950312f2 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Mon, 25 Mar 2019 17:08:51 +0000 Subject: [Sema][NFCI] Don't allocate storage for the various CorrectionCandidateCallback unless we are going to do some typo correction The various CorrectionCandidateCallbacks are currently heap-allocated unconditionally. This was needed because of delayed typo correction. However these allocations represent currently 15.4% of all allocations (number of allocations) when parsing all of Boost (!), mostly because of ParseCastExpression, ParseStatementOrDeclarationAfterAttrtibutes and isCXXDeclarationSpecifier. Note that all of these callback objects are small. Let's not do this. Instead initially allocate the callback on the stack, and only do a heap allocation if we are going to do some typo correction. Do this by: 1. Adding a clone function to each callback, which will do a polymorphic clone of the callback. This clone function is required to be implemented by every callback (of which there is a fair amount). Make sure this is the case by making it pure virtual. 2. Use this clone function when we are going to try to correct a typo. This additionally cut the time of -fsyntax-only on all of Boost by 0.5% (not that much, but still something). No functional changes intended. Differential Revision: https://reviews.llvm.org/D58827 Reviewed By: rnk git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356925 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index d6c656e06b..818a981b49 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1946,11 +1946,10 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, } // Attempt to correct for typos in property names. - if (TypoCorrection Corrected = - CorrectTypo(DeclarationNameInfo(MemberName, MemberLoc), - LookupOrdinaryName, nullptr, nullptr, - llvm::make_unique>(), - CTK_ErrorRecovery, IFace, false, OPT)) { + DeclFilterCCC CCC{}; + if (TypoCorrection Corrected = CorrectTypo( + DeclarationNameInfo(MemberName, MemberLoc), LookupOrdinaryName, + nullptr, nullptr, CCC, CTK_ErrorRecovery, IFace, false, OPT)) { DeclarationName TypoResult = Corrected.getCorrection(); if (TypoResult.isIdentifier() && TypoResult.getAsIdentifierInfo() == Member) { @@ -2107,7 +2106,7 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, namespace { -class ObjCInterfaceOrSuperCCC : public CorrectionCandidateCallback { +class ObjCInterfaceOrSuperCCC final : public CorrectionCandidateCallback { public: ObjCInterfaceOrSuperCCC(ObjCMethodDecl *Method) { // Determine whether "super" is acceptable in the current context. @@ -2119,6 +2118,10 @@ class ObjCInterfaceOrSuperCCC : public CorrectionCandidateCallback { return candidate.getCorrectionDeclAs() || candidate.isKeyword("super"); } + + std::unique_ptr clone() override { + return llvm::make_unique(*this); + } }; } // end anonymous namespace @@ -2194,9 +2197,9 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S, } } + ObjCInterfaceOrSuperCCC CCC(getCurMethodDecl()); if (TypoCorrection Corrected = CorrectTypo( - Result.getLookupNameInfo(), Result.getLookupKind(), S, nullptr, - llvm::make_unique(getCurMethodDecl()), + Result.getLookupNameInfo(), Result.getLookupKind(), S, nullptr, CCC, CTK_ErrorRecovery, nullptr, false, nullptr, false)) { if (Corrected.isKeyword()) { // If we've found the keyword "super" (the only keyword that would be -- cgit v1.2.3