diff options
Diffstat (limited to 'lib')
25 files changed, 100 insertions, 82 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 5cab48882251..1caceab85eea 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -1837,9 +1837,10 @@ bool CXXMethodDecl::hasInlineBody() const {    const FunctionDecl *CheckFn = getTemplateInstantiationPattern();    if (!CheckFn)      CheckFn = this; -   +    const FunctionDecl *fn; -  return CheckFn->hasBody(fn) && !fn->isOutOfLine(); +  return CheckFn->isDefined(fn) && !fn->isOutOfLine() && +         (fn->doesThisDeclarationHaveABody() || fn->willHaveBody());  }  bool CXXMethodDecl::isLambdaStaticInvoker() const { diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 6713fca04571..fe45b5e47f36 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -1052,7 +1052,9 @@ CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,            :Type->getType()->isRValueReferenceType()? VK_XValue            :VK_RValue),           OK_Ordinary, -         Type->getType()->isDependentType(), true, true, +         Type->getType()->isDependentType() || +             Type->getType()->getContainedDeducedType(), +         true, true,           Type->getType()->containsUnexpandedParameterPack()),      Type(Type),      LParenLoc(LParenLoc), diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 0c0c861e5d56..a26b608082f5 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -9788,6 +9788,8 @@ public:    bool Success(const APValue &V, const Expr *e) { return true; } +  bool ZeroInitialization(const Expr *E) { return true; } +    bool VisitCastExpr(const CastExpr *E) {      switch (E->getCastKind()) {      default: diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 73be2e173fda..5d75aa5a7528 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -8050,6 +8050,7 @@ class MipsTargetInfo : public TargetInfo {      NoDSP, DSP1, DSP2    } DspRev;    bool HasMSA; +  bool DisableMadd4;  protected:    bool HasFP64; @@ -8060,7 +8061,7 @@ public:        : TargetInfo(Triple), IsMips16(false), IsMicromips(false),          IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),          CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP), -        HasMSA(false), HasFP64(false) { +        HasMSA(false), DisableMadd4(false), HasFP64(false) {      TheCXXABI.set(TargetCXXABI::GenericMIPS);      setABI((getTriple().getArch() == llvm::Triple::mips || @@ -8306,6 +8307,9 @@ public:      if (HasMSA)        Builder.defineMacro("__mips_msa", Twine(1)); +    if (DisableMadd4) +      Builder.defineMacro("__mips_no_madd4", Twine(1)); +      Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));      Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));      Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth())); @@ -8468,6 +8472,8 @@ public:          DspRev = std::max(DspRev, DSP2);        else if (Feature == "+msa")          HasMSA = true; +      else if (Feature == "+nomadd4") +        DisableMadd4 = true;        else if (Feature == "+fp64")          HasFP64 = true;        else if (Feature == "-fp64") diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index c17828974e92..eb230aad4d35 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -5573,17 +5573,14 @@ void ARMABIInfo::setCCs() {    // AAPCS apparently requires runtime support functions to be soft-float, but    // that's almost certainly for historic reasons (Thumb1 not supporting VFP    // most likely). It's more convenient for AAPCS16_VFP to be hard-float. -  switch (getABIKind()) { -  case APCS: -  case AAPCS16_VFP: -    if (abiCC != getLLVMDefaultCC()) + +  // The Run-time ABI for the ARM Architecture section 4.1.2 requires +  // AEABI-complying FP helper functions to use the base AAPCS. +  // These AEABI functions are expanded in the ARM llvm backend, all the builtin +  // support functions emitted by clang such as the _Complex helpers follow the +  // abiCC. +  if (abiCC != getLLVMDefaultCC())        BuiltinCC = abiCC; -    break; -  case AAPCS: -  case AAPCS_VFP: -    BuiltinCC = llvm::CallingConv::ARM_AAPCS; -    break; -  }  }  ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, @@ -6754,14 +6751,6 @@ MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {        return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);      } -    // Use indirect if the aggregate cannot fit into registers for -    // passing arguments according to the ABI -    unsigned Threshold = IsO32 ? 16 : 64; - -    if(getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(Threshold)) -      return ABIArgInfo::getIndirect(CharUnits::fromQuantity(Align), true, -                                     getContext().getTypeAlign(Ty) / 8 > Align); -      // If we have reached here, aggregates are passed directly by coercing to      // another structure type. Padding is inserted if the offset of the      // aggregate is unaligned. diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 2be7f0f69004..9a858df8ab2d 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -217,7 +217,7 @@ StringRef ToolChain::getDefaultUniversalArchName() const {    }  } -bool ToolChain::IsUnwindTablesDefault() const { +bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const {    return false;  } diff --git a/lib/Driver/ToolChains/Arch/Mips.cpp b/lib/Driver/ToolChains/Arch/Mips.cpp index 1da90d1dc7ba..b45dcd6db678 100644 --- a/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/lib/Driver/ToolChains/Arch/Mips.cpp @@ -297,6 +297,8 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,    AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,                     options::OPT_modd_spreg, "nooddspreg"); +  AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4, +                   "nomadd4");    AddTargetFeature(Args, Features, options::OPT_mlong_calls,                     options::OPT_mno_long_calls, "long-calls");    AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt,"mt"); diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index b82cc2d4fa5d..baf7a93d2d92 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -2538,7 +2538,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,    bool AsynchronousUnwindTables =        Args.hasFlag(options::OPT_fasynchronous_unwind_tables,                     options::OPT_fno_asynchronous_unwind_tables, -                   (getToolChain().IsUnwindTablesDefault() || +                   (getToolChain().IsUnwindTablesDefault(Args) ||                      getToolChain().getSanitizerArgs().needsUnwindTables()) &&                         !KernelOrKext);    if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, diff --git a/lib/Driver/ToolChains/CrossWindows.cpp b/lib/Driver/ToolChains/CrossWindows.cpp index 7d0c438b1360..04b71c48cd4c 100644 --- a/lib/Driver/ToolChains/CrossWindows.cpp +++ b/lib/Driver/ToolChains/CrossWindows.cpp @@ -214,7 +214,7 @@ CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,    }  } -bool CrossWindowsToolChain::IsUnwindTablesDefault() const { +bool CrossWindowsToolChain::IsUnwindTablesDefault(const ArgList &Args) const {    // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does    // not know how to emit them.    return getArch() == llvm::Triple::x86_64; diff --git a/lib/Driver/ToolChains/CrossWindows.h b/lib/Driver/ToolChains/CrossWindows.h index 5375a6324a3f..2f66446ec732 100644 --- a/lib/Driver/ToolChains/CrossWindows.h +++ b/lib/Driver/ToolChains/CrossWindows.h @@ -56,7 +56,7 @@ public:                          const llvm::opt::ArgList &Args);    bool IsIntegratedAssemblerDefault() const override { return true; } -  bool IsUnwindTablesDefault() const override; +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;    bool isPICDefault() const override;    bool isPIEDefault() const override;    bool isPICDefaultForced() const override; diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 0d63858f2cd4..6b7f0c71dfb7 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1174,13 +1174,12 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {    unsigned Major, Minor, Micro;    bool HadExtra; -  // iOS 10 is the maximum deployment target for 32-bit targets. -  if (iOSVersion && getTriple().isArch32Bit() && -      Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, -                                HadExtra) && -      Major > 10) -    getDriver().Diag(diag::err_invalid_ios_deployment_target) -        << iOSVersion->getAsString(Args); +  // The iOS deployment target that is explicitly specified via a command line +  // option or an environment variable. +  std::string ExplicitIOSDeploymentTargetStr; + +  if (iOSVersion) +    ExplicitIOSDeploymentTargetStr = iOSVersion->getAsString(Args);    // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and    // -m(iphone|tv|watch)simulator-version-min=X.Y. @@ -1223,13 +1222,9 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {      if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))        WatchOSTarget = env; -    // iOS 10 is the maximum deployment target for 32-bit targets. -    if (!iOSTarget.empty() && getTriple().isArch32Bit() && -        Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro, -                                  HadExtra) && -        Major > 10) -      getDriver().Diag(diag::err_invalid_ios_deployment_target) -          << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget; +    if (!iOSTarget.empty()) +      ExplicitIOSDeploymentTargetStr = +          std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;      // If there is no command-line argument to specify the Target version and      // no environment variable defined, see if we can set the default based @@ -1393,12 +1388,19 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {          HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)        getDriver().Diag(diag::err_drv_invalid_version_number)            << iOSVersion->getAsString(Args); -    // iOS 10 is the maximum deployment target for 32-bit targets. If the -    // inferred deployment target is iOS 11 or later, set it to 10.99. +    // For 32-bit targets, the deployment target for iOS has to be earlier than +    // iOS 11.      if (getTriple().isArch32Bit() && Major >= 11) { -      Major = 10; -      Minor = 99; -      Micro = 99; +      // If the deployment target is explicitly specified, print a diagnostic. +      if (!ExplicitIOSDeploymentTargetStr.empty()) { +        getDriver().Diag(diag::warn_invalid_ios_deployment_target) +            << ExplicitIOSDeploymentTargetStr; +      // Otherwise, set it to 10.99.99. +      } else { +        Major = 10; +        Minor = 99; +        Micro = 99; +      }      }    } else if (Platform == TvOS) {      if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, @@ -1834,8 +1836,8 @@ Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,    return DAL;  } -bool MachO::IsUnwindTablesDefault() const { -  return getArch() == llvm::Triple::x86_64; +bool MachO::IsUnwindTablesDefault(const ArgList &Args) const { +  return !UseSjLjExceptions(Args);  }  bool MachO::UseDwarfDebugFlags() const { diff --git a/lib/Driver/ToolChains/Darwin.h b/lib/Driver/ToolChains/Darwin.h index 6cb1d04b78c0..77c569e8f865 100644 --- a/lib/Driver/ToolChains/Darwin.h +++ b/lib/Driver/ToolChains/Darwin.h @@ -216,7 +216,7 @@ public:    bool UseObjCMixedDispatch() const override { return true; } -  bool IsUnwindTablesDefault() const override; +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;    RuntimeLibType GetDefaultRuntimeLibType() const override {      return ToolChain::RLT_CompilerRT; diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index bc26ee1de46d..72a9f85ba389 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -2291,7 +2291,7 @@ void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {    CudaInstallation.print(OS);  } -bool Generic_GCC::IsUnwindTablesDefault() const { +bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {    return getArch() == llvm::Triple::x86_64;  } diff --git a/lib/Driver/ToolChains/Gnu.h b/lib/Driver/ToolChains/Gnu.h index cdf610054401..f29342b95a07 100644 --- a/lib/Driver/ToolChains/Gnu.h +++ b/lib/Driver/ToolChains/Gnu.h @@ -284,7 +284,7 @@ public:    void printVerboseInfo(raw_ostream &OS) const override; -  bool IsUnwindTablesDefault() const override; +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;    bool isPICDefault() const override;    bool isPIEDefault() const override;    bool isPICDefaultForced() const override; diff --git a/lib/Driver/ToolChains/MSVC.cpp b/lib/Driver/ToolChains/MSVC.cpp index 9e9d943610be..b871c856d2a0 100644 --- a/lib/Driver/ToolChains/MSVC.cpp +++ b/lib/Driver/ToolChains/MSVC.cpp @@ -699,7 +699,7 @@ bool MSVCToolChain::IsIntegratedAssemblerDefault() const {    return true;  } -bool MSVCToolChain::IsUnwindTablesDefault() const { +bool MSVCToolChain::IsUnwindTablesDefault(const ArgList &Args) const {    // Emit unwind tables by default on Win64. All non-x86_32 Windows platforms    // such as ARM and PPC actually require unwind tables, but LLVM doesn't know    // how to generate them yet. diff --git a/lib/Driver/ToolChains/MSVC.h b/lib/Driver/ToolChains/MSVC.h index 055830c52e0d..d153691a5c90 100644 --- a/lib/Driver/ToolChains/MSVC.h +++ b/lib/Driver/ToolChains/MSVC.h @@ -73,7 +73,7 @@ public:                  Action::OffloadKind DeviceOffloadKind) const override;    bool IsIntegratedAssemblerDefault() const override; -  bool IsUnwindTablesDefault() const override; +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;    bool isPICDefault() const override;    bool isPIEDefault() const override;    bool isPICDefaultForced() const override; diff --git a/lib/Driver/ToolChains/MinGW.cpp b/lib/Driver/ToolChains/MinGW.cpp index 7550bab486f1..632b76d92bdd 100644 --- a/lib/Driver/ToolChains/MinGW.cpp +++ b/lib/Driver/ToolChains/MinGW.cpp @@ -347,7 +347,7 @@ Tool *toolchains::MinGW::buildLinker() const {    return new tools::MinGW::Linker(*this);  } -bool toolchains::MinGW::IsUnwindTablesDefault() const { +bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {    return getArch() == llvm::Triple::x86_64;  } diff --git a/lib/Driver/ToolChains/MinGW.h b/lib/Driver/ToolChains/MinGW.h index cf1628a4ccdd..9b3d7c553f1d 100644 --- a/lib/Driver/ToolChains/MinGW.h +++ b/lib/Driver/ToolChains/MinGW.h @@ -60,7 +60,7 @@ public:          const llvm::opt::ArgList &Args);    bool IsIntegratedAssemblerDefault() const override; -  bool IsUnwindTablesDefault() const override; +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;    bool isPICDefault() const override;    bool isPIEDefault() const override;    bool isPICDefaultForced() const override; diff --git a/lib/Driver/ToolChains/NetBSD.h b/lib/Driver/ToolChains/NetBSD.h index 412d0815e81a..5163ff72d81b 100644 --- a/lib/Driver/ToolChains/NetBSD.h +++ b/lib/Driver/ToolChains/NetBSD.h @@ -65,7 +65,10 @@ public:        const llvm::opt::ArgList &DriverArgs,        llvm::opt::ArgStringList &CC1Args) const override; -  bool IsUnwindTablesDefault() const override { return true; } +  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override { +    return true; +  } +    SanitizerMask getSupportedSanitizers() const override;  protected: diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 64128dfdf534..92d61369b40f 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -497,6 +497,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,      Builder.defineMacro("__cpp_ref_qualifiers", "200710");      Builder.defineMacro("__cpp_alias_templates", "200704");    } +  if (LangOpts.ThreadsafeStatics) +    Builder.defineMacro("__cpp_threadsafe_static_init", "200806");    // C++14 features.    if (LangOpts.CPlusPlus14) { @@ -519,6 +521,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,      Builder.defineMacro("__cpp_noexcept_function_type", "201510");      Builder.defineMacro("__cpp_capture_star_this", "201603");      Builder.defineMacro("__cpp_if_constexpr", "201606"); +    Builder.defineMacro("__cpp_deduction_guides", "201611");      Builder.defineMacro("__cpp_template_auto", "201606");      Builder.defineMacro("__cpp_namespace_attributes", "201411");      Builder.defineMacro("__cpp_enumerator_attributes", "201411"); @@ -528,8 +531,6 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,      Builder.defineMacro("__cpp_structured_bindings", "201606");      Builder.defineMacro("__cpp_nontype_template_args", "201411");      Builder.defineMacro("__cpp_fold_expressions", "201603"); -    // FIXME: This is not yet listed in SD-6. -    Builder.defineMacro("__cpp_deduction_guides", "201611");    }    if (LangOpts.AlignedAllocation)      Builder.defineMacro("__cpp_aligned_new", "201606"); diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index b68559485a5e..27651c9ca85c 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -166,20 +166,11 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,    }    if (FnD) { -    // If this is a friend function, mark that it's late-parsed so that -    // it's still known to be a definition even before we attach the -    // parsed body.  Sema needs to treat friend function definitions -    // differently during template instantiation, and it's possible for -    // the containing class to be instantiated before all its member -    // function definitions are parsed. -    // -    // If you remove this, you can remove the code that clears the flag -    // after parsing the member. -    if (D.getDeclSpec().isFriendSpecified()) { -      FunctionDecl *FD = FnD->getAsFunction(); -      Actions.CheckForFunctionRedefinition(FD); -      FD->setLateTemplateParsed(true); -    } +    FunctionDecl *FD = FnD->getAsFunction(); +    // Track that this function will eventually have a body; Sema needs +    // to know this. +    Actions.CheckForFunctionRedefinition(FD); +    FD->setWillHaveBody(true);    } else {      // If semantic analysis could not build a function declaration,      // just throw away the late-parsed declaration. @@ -558,10 +549,6 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {    ParseFunctionStatementBody(LM.D, FnScope); -  // Clear the late-template-parsed bit if we set it before. -  if (LM.D) -    LM.D->getAsFunction()->setLateTemplateParsed(false); -    while (Tok.isNot(tok::eof))      ConsumeAnyToken(); diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index ba2049d8a606..d603101c3fd9 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -552,7 +552,14 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType,      Qualifiers SrcQuals, DestQuals;      Self.Context.getUnqualifiedArrayType(UnwrappedSrcType, SrcQuals);      Self.Context.getUnqualifiedArrayType(UnwrappedDestType, DestQuals); -     + +    // We do not meaningfully track object const-ness of Objective-C object +    // types. Remove const from the source type if either the source or +    // the destination is an Objective-C object type. +    if (UnwrappedSrcType->isObjCObjectType() || +        UnwrappedDestType->isObjCObjectType()) +      SrcQuals.removeConst(); +      Qualifiers RetainedSrcQuals, RetainedDestQuals;      if (CheckCVR) {        RetainedSrcQuals.setCVRQualifiers(SrcQuals.getCVRQualifiers()); diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 91a8c619b26c..4de7d422072d 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -2401,10 +2401,7 @@ formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl,  static std::string GetDefaultValueString(const ParmVarDecl *Param,                                           const SourceManager &SM,                                           const LangOptions &LangOpts) { -  const Expr *defaultArg = Param->getDefaultArg(); -  if (!defaultArg) -    return ""; -  const SourceRange SrcRange = defaultArg->getSourceRange(); +  const SourceRange SrcRange = Param->getDefaultArgRange();    CharSourceRange CharSrcRange = CharSourceRange::getTokenRange(SrcRange);    bool Invalid = CharSrcRange.isInvalid();    if (Invalid) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 31b24f91c1d9..692a77e2b62f 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6999,6 +6999,21 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,            return;          }        } + +      if (cast<VarDecl>(ShadowedDecl)->hasLocalStorage()) { +        // A variable can't shadow a local variable in an enclosing scope, if +        // they are separated by a non-capturing declaration context. +        for (DeclContext *ParentDC = NewDC; +             ParentDC && !ParentDC->Equals(OldDC); +             ParentDC = getLambdaAwareParentOfDeclContext(ParentDC)) { +          // Only block literals, captured statements, and lambda expressions +          // can capture; other scopes don't. +          if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) && +              !isLambdaCallOperator(ParentDC)) { +            return; +          } +        } +      }      }    } @@ -12075,8 +12090,9 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,      FD->setInvalidDecl();    } -  // See if this is a redefinition. -  if (!FD->isLateTemplateParsed()) { +  // See if this is a redefinition. If 'will have body' is already set, then +  // these checks were already performed when it was set. +  if (!FD->willHaveBody() && !FD->isLateTemplateParsed()) {      CheckForFunctionRedefinition(FD, nullptr, SkipBody);      // If we're skipping the body, we're done. Don't enter the scope. @@ -13278,6 +13294,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,          AddMsStructLayoutForRecord(RD);        }      } +    New->setLexicalDeclContext(CurContext);      return New;    }; diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index abe912fb548b..6fee23aa8bc1 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3771,6 +3771,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,    if (PatternDef) {      Pattern = PatternDef->getBody(PatternDef);      PatternDecl = PatternDef; +    if (PatternDef->willHaveBody()) +      PatternDef = nullptr;    }    // FIXME: We need to track the instantiation stack in order to know which  | 
