From 61d542a8476a6e51a76b7d9c135ca1a335479ce2 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 20 Jun 2017 14:30:18 +0000 Subject: [PATCH 001/214] [OpenCL] Fix OpenCL and SPIR version metadata generation. Summary: OpenCL and SPIR version metadata must be generated once per module instead of once per mangled global value. Reviewers: Anastasia, yaxunl Reviewed By: Anastasia Subscribers: ahatanak, cfe-commits Differential Revision: https://reviews.llvm.org/D34235 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305796 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 34 +++++++++++++++++++++++++ lib/CodeGen/CodeGenModule.h | 3 +++ lib/CodeGen/TargetInfo.cpp | 41 ------------------------------ test/CodeGenOpenCL/spir_version.cl | 17 +++++++------ 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 19a055075604..20d945fe50d3 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -506,6 +506,26 @@ void CodeGenModule::Release() { LangOpts.CUDADeviceFlushDenormalsToZero ? 1 : 0); } + // Emit OpenCL specific module metadata: OpenCL/SPIR version. + if (LangOpts.OpenCL) { + EmitOpenCLMetadata(); + // Emit SPIR version. + if (getTriple().getArch() == llvm::Triple::spir || + getTriple().getArch() == llvm::Triple::spir64) { + // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the + // opencl.spir.version named metadata. + llvm::Metadata *SPIRVerElts[] = { + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + Int32Ty, LangOpts.OpenCLVersion / 100)), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + Int32Ty, (LangOpts.OpenCLVersion / 100 > 1) ? 0 : 2))}; + llvm::NamedMDNode *SPIRVerMD = + TheModule.getOrInsertNamedMetadata("opencl.spir.version"); + llvm::LLVMContext &Ctx = TheModule.getContext(); + SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts)); + } + } + if (uint32_t PLevel = Context.getLangOpts().PICLevel) { assert(PLevel < 3 && "Invalid PIC Level"); getModule().setPICLevel(static_cast(PLevel)); @@ -529,6 +549,20 @@ void CodeGenModule::Release() { EmitTargetMetadata(); } +void CodeGenModule::EmitOpenCLMetadata() { + // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the + // opencl.ocl.version named metadata node. + llvm::Metadata *OCLVerElts[] = { + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + Int32Ty, LangOpts.OpenCLVersion / 100)), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + Int32Ty, (LangOpts.OpenCLVersion % 100) / 10))}; + llvm::NamedMDNode *OCLVerMD = + TheModule.getOrInsertNamedMetadata("opencl.ocl.version"); + llvm::LLVMContext &Ctx = TheModule.getContext(); + OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts)); +} + void CodeGenModule::UpdateCompletedType(const TagDecl *TD) { // Make sure that this type is translated. Types.UpdateCompletedType(TD); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 59e56a6ba194..c5f1a2b409ee 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -1321,6 +1321,9 @@ class CodeGenModule : public CodeGenTypeCache { /// Emits target specific Metadata for global declarations. void EmitTargetMetadata(); + /// Emits OpenCL specific Metadata e.g. OpenCL version. + void EmitOpenCLMetadata(); + /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and /// .gcda files in a way that persists in .bc files. void EmitCoverageFile(); diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 427ec06a2fff..d6a5e75a40cf 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -7344,8 +7344,6 @@ class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo { }; } -static void appendOpenCLVersionMD (CodeGen::CodeGenModule &CGM); - void AMDGPUTargetCodeGenInfo::setTargetAttributes( const Decl *D, llvm::GlobalValue *GV, @@ -7402,8 +7400,6 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( if (NumVGPR != 0) F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR)); } - - appendOpenCLVersionMD(M); } unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const { @@ -8074,8 +8070,6 @@ class SPIRTargetCodeGenInfo : public TargetCodeGenInfo { public: SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {} - void emitTargetMD(const Decl *D, llvm::GlobalValue *GV, - CodeGen::CodeGenModule &M) const override; unsigned getOpenCLKernelCallingConv() const override; }; @@ -8090,41 +8084,6 @@ void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI) { } } -/// Emit SPIR specific metadata: OpenCL and SPIR version. -void SPIRTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV, - CodeGen::CodeGenModule &CGM) const { - llvm::LLVMContext &Ctx = CGM.getModule().getContext(); - llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx); - llvm::Module &M = CGM.getModule(); - // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the - // opencl.spir.version named metadata. - llvm::Metadata *SPIRVerElts[] = { - llvm::ConstantAsMetadata::get( - llvm::ConstantInt::get(Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)), - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - Int32Ty, (CGM.getLangOpts().OpenCLVersion / 100 > 1) ? 0 : 2))}; - llvm::NamedMDNode *SPIRVerMD = - M.getOrInsertNamedMetadata("opencl.spir.version"); - SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts)); - appendOpenCLVersionMD(CGM); -} - -static void appendOpenCLVersionMD(CodeGen::CodeGenModule &CGM) { - llvm::LLVMContext &Ctx = CGM.getModule().getContext(); - llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx); - llvm::Module &M = CGM.getModule(); - // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the - // opencl.ocl.version named metadata node. - llvm::Metadata *OCLVerElts[] = { - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)), - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - Int32Ty, (CGM.getLangOpts().OpenCLVersion % 100) / 10))}; - llvm::NamedMDNode *OCLVerMD = - M.getOrInsertNamedMetadata("opencl.ocl.version"); - OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts)); -} - unsigned SPIRTargetCodeGenInfo::getOpenCLKernelCallingConv() const { return llvm::CallingConv::SPIR_KERNEL; } diff --git a/test/CodeGenOpenCL/spir_version.cl b/test/CodeGenOpenCL/spir_version.cl index 8a191282b3c7..ac5b8e8c7fa5 100644 --- a/test/CodeGenOpenCL/spir_version.cl +++ b/test/CodeGenOpenCL/spir_version.cl @@ -10,17 +10,18 @@ // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-AMDGCN-CL20 kernel void foo() {} +kernel void bar() {} -// CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]} -// CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]} -// CHECK-SPIR-CL10: [[SPIR]] = !{i32 1, i32 2} -// CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0} -// CHECK-SPIR-CL12: !opencl.spir.version = !{[[VER:![0-9]+]]} -// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[VER]]} +// CHECK-SPIR-CL10-DAG: !opencl.spir.version = !{[[SPIR:![0-9]+]]} +// CHECK-SPIR-CL10-DAG: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-SPIR-CL10-DAG: [[SPIR]] = !{i32 1, i32 2} +// CHECK-SPIR-CL10-DAG: [[OCL]] = !{i32 1, i32 0} +// CHECK-SPIR-CL12-DAG: !opencl.spir.version = !{[[VER:![0-9]+]]} +// CHECK-SPIR-CL12-DAG: !opencl.ocl.version = !{[[VER]]} // CHECK-SPIR-CL12: [[VER]] = !{i32 1, i32 2} -// CHECK-SPIR-CL20: !opencl.spir.version = !{[[VER:![0-9]+]]} -// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[VER]]} +// CHECK-SPIR-CL20-DAG: !opencl.spir.version = !{[[VER:![0-9]+]]} +// CHECK-SPIR-CL20-DAG: !opencl.ocl.version = !{[[VER]]} // CHECK-SPIR-CL20: [[VER]] = !{i32 2, i32 0} // CHECK-AMDGCN-CL10-NOT: !opencl.spir.version From 7a2305ca4dfb7a94e5e524ed034aeb3768d8bf9a Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 20 Jun 2017 14:36:58 +0000 Subject: [PATCH 002/214] [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros This is useful for being able to parse the preprocessor directive blocks even if the header, that defined the macro that is checked, hasn't been included. Differential Revision: https://reviews.llvm.org/D34263 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305797 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Preprocessor.h | 13 ++- include/clang/Lex/PreprocessorOptions.h | 4 + lib/Lex/PPDirectives.cpp | 38 ++++++-- lib/Lex/PPExpressions.cpp | 29 +++++-- test/Index/singe-file-parse.m | 11 --- test/Index/single-file-parse.m | 111 ++++++++++++++++++++++++ 6 files changed, 179 insertions(+), 27 deletions(-) delete mode 100644 test/Index/singe-file-parse.m create mode 100644 test/Index/single-file-parse.m diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 302d006ea16c..712e1ab9fbf5 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1835,11 +1835,20 @@ class Preprocessor { /// \brief A fast PTH version of SkipExcludedConditionalBlock. void PTHSkipExcludedConditionalBlock(); + /// Information about the result for evaluating an expression for a + /// preprocessor directive. + struct DirectiveEvalResult { + /// Whether the expression was evaluated as true or not. + bool Conditional; + /// True if the expression contained identifiers that were undefined. + bool IncludedUndefinedIds; + }; + /// \brief Evaluate an integer constant expression that may occur after a - /// \#if or \#elif directive and return it as a bool. + /// \#if or \#elif directive and return a \p DirectiveEvalResult object. /// /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro. - bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); + DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); /// \brief Install the standard preprocessor pragmas: /// \#pragma GCC poison/system_header/dependency and \#pragma once. diff --git a/include/clang/Lex/PreprocessorOptions.h b/include/clang/Lex/PreprocessorOptions.h index 024db926eb41..d91c665cf1dd 100644 --- a/include/clang/Lex/PreprocessorOptions.h +++ b/include/clang/Lex/PreprocessorOptions.h @@ -96,6 +96,10 @@ class PreprocessorOptions { std::string TokenCache; /// When enabled, preprocessor is in a mode for parsing a single file only. + /// + /// Disables #includes of other files and if there are unresolved identifiers + /// in preprocessor directive conditions it causes all blocks to be parsed so + /// that the client can get the maximum amount of information from the parser. bool SingleFileParseMode = false; /// When enabled, the preprocessor will construct editor placeholder tokens. diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 89c2ebd00a68..422bfc896875 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -538,7 +538,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, assert(CurPPLexer->LexingRawMode && "We have to be skipping here!"); CurPPLexer->LexingRawMode = false; IdentifierInfo *IfNDefMacro = nullptr; - const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro); + const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro).Conditional; CurPPLexer->LexingRawMode = true; if (Callbacks) { const SourceLocation CondEnd = CurPPLexer->getSourceLocation(); @@ -635,7 +635,7 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() { // Evaluate the condition of the #elif. IdentifierInfo *IfNDefMacro = nullptr; CurPTHLexer->ParsingPreprocessorDirective = true; - bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro); + bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro).Conditional; CurPTHLexer->ParsingPreprocessorDirective = false; // If this condition is true, enter it! @@ -2654,7 +2654,13 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, } // Should we include the stuff contained by this directive? - if (!MI == isIfndef) { + if (PPOpts->SingleFileParseMode && !MI) { + // In 'single-file-parse mode' undefined identifiers trigger parsing of all + // the directive blocks. + CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(), + /*wasskip*/true, /*foundnonskip*/false, + /*foundelse*/false); + } else if (!MI == isIfndef) { // Yes, remember that we are inside a conditional, then lex the next token. CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(), /*wasskip*/false, /*foundnonskip*/true, @@ -2676,7 +2682,8 @@ void Preprocessor::HandleIfDirective(Token &IfToken, // Parse and evaluate the conditional expression. IdentifierInfo *IfNDefMacro = nullptr; const SourceLocation ConditionalBegin = CurPPLexer->getSourceLocation(); - const bool ConditionalTrue = EvaluateDirectiveExpression(IfNDefMacro); + const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro); + const bool ConditionalTrue = DER.Conditional; const SourceLocation ConditionalEnd = CurPPLexer->getSourceLocation(); // If this condition is equivalent to #ifndef X, and if this is the first @@ -2695,7 +2702,12 @@ void Preprocessor::HandleIfDirective(Token &IfToken, (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False)); // Should we include the stuff contained by this directive? - if (ConditionalTrue) { + if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) { + // In 'single-file-parse mode' undefined identifiers trigger parsing of all + // the directive blocks. + CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/true, + /*foundnonskip*/false, /*foundelse*/false); + } else if (ConditionalTrue) { // Yes, remember that we are inside a conditional, then lex the next token. CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false, /*foundnonskip*/true, /*foundelse*/false); @@ -2756,6 +2768,14 @@ void Preprocessor::HandleElseDirective(Token &Result) { if (Callbacks) Callbacks->Else(Result.getLocation(), CI.IfLoc); + if (PPOpts->SingleFileParseMode && CI.WasSkipping) { + // In 'single-file-parse mode' undefined identifiers trigger parsing of all + // the directive blocks. + CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false, + /*foundnonskip*/true, /*foundelse*/true); + return; + } + // Finally, skip the rest of the contents of this block. SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, /*FoundElse*/true, Result.getLocation()); @@ -2791,6 +2811,14 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) { SourceRange(ConditionalBegin, ConditionalEnd), PPCallbacks::CVK_NotEvaluated, CI.IfLoc); + if (PPOpts->SingleFileParseMode && CI.WasSkipping) { + // In 'single-file-parse mode' undefined identifiers trigger parsing of all + // the directive blocks. + CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/true, + /*foundnonskip*/false, /*foundelse*/false); + return; + } + // Finally, skip the rest of the contents of this block. SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, /*FoundElse*/CI.FoundElse, diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 862a4713e4bc..12f5084298df 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -73,6 +73,7 @@ class PPValue { static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, Token &PeekTok, bool ValueLive, + bool &IncludedUndefinedIds, Preprocessor &PP); /// DefinedTracker - This struct is used while parsing expressions to keep track @@ -93,6 +94,7 @@ struct DefinedTracker { /// TheMacro - When the state is DefinedMacro or NotDefinedMacro, this /// indicates the macro that was checked. IdentifierInfo *TheMacro; + bool IncludedUndefinedIds = false; }; /// EvaluateDefined - Process a 'defined(sym)' expression. @@ -128,6 +130,7 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, MacroDefinition Macro = PP.getMacroDefinition(II); Result.Val = !!Macro; Result.Val.setIsUnsigned(false); // Result is signed intmax_t. + DT.IncludedUndefinedIds = !Macro; // If there is a macro, mark it used. if (Result.Val != 0 && ValueLive) @@ -255,6 +258,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, Result.Val.setIsUnsigned(false); // "0" is signed intmax_t 0. Result.setIdentifier(II); Result.setRange(PeekTok.getLocation()); + DT.IncludedUndefinedIds = (II->getTokenID() != tok::kw_true && + II->getTokenID() != tok::kw_false); PP.LexNonComment(PeekTok); return false; } @@ -400,7 +405,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // Just use DT unmodified as our result. } else { // Otherwise, we have something like (x+y), and we consumed '(x'. - if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive, PP)) + if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive, + DT.IncludedUndefinedIds, PP)) return true; if (PeekTok.isNot(tok::r_paren)) { @@ -532,6 +538,7 @@ static void diagnoseUnexpectedOperator(Preprocessor &PP, PPValue &LHS, /// evaluation, such as division by zero warnings. static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, Token &PeekTok, bool ValueLive, + bool &IncludedUndefinedIds, Preprocessor &PP) { unsigned PeekPrec = getPrecedence(PeekTok.getKind()); // If this token isn't valid, report the error. @@ -571,6 +578,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, // Parse the RHS of the operator. DefinedTracker DT; if (EvaluateValue(RHS, PeekTok, DT, RHSIsLive, PP)) return true; + IncludedUndefinedIds = DT.IncludedUndefinedIds; // Remember the precedence of this operator and get the precedence of the // operator immediately to the right of the RHS. @@ -601,7 +609,8 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, RHSPrec = ThisPrec+1; if (PeekPrec >= RHSPrec) { - if (EvaluateDirectiveSubExpr(RHS, RHSPrec, PeekTok, RHSIsLive, PP)) + if (EvaluateDirectiveSubExpr(RHS, RHSPrec, PeekTok, RHSIsLive, + IncludedUndefinedIds, PP)) return true; PeekPrec = getPrecedence(PeekTok.getKind()); } @@ -769,7 +778,8 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, // Parse anything after the : with the same precedence as ?. We allow // things of equal precedence because ?: is right associative. if (EvaluateDirectiveSubExpr(AfterColonVal, ThisPrec, - PeekTok, AfterColonLive, PP)) + PeekTok, AfterColonLive, + IncludedUndefinedIds, PP)) return true; // Now that we have the condition, the LHS and the RHS of the :, evaluate. @@ -806,7 +816,8 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, /// EvaluateDirectiveExpression - Evaluate an integer constant expression that /// may occur after a #if or #elif directive. If the expression is equivalent /// to "!defined(X)" return X in IfNDefMacro. -bool Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { +Preprocessor::DirectiveEvalResult +Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { SaveAndRestore PPDir(ParsingIfOrElifDirective, true); // Save the current state of 'DisableMacroExpansion' and reset it to false. If // 'DisableMacroExpansion' is true, then we must be in a macro argument list @@ -833,7 +844,7 @@ bool Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { // Restore 'DisableMacroExpansion'. DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; - return false; + return {false, DT.IncludedUndefinedIds}; } // If we are at the end of the expression after just parsing a value, there @@ -847,20 +858,20 @@ bool Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { // Restore 'DisableMacroExpansion'. DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; - return ResVal.Val != 0; + return {ResVal.Val != 0, DT.IncludedUndefinedIds}; } // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the // operator and the stuff after it. if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question), - Tok, true, *this)) { + Tok, true, DT.IncludedUndefinedIds, *this)) { // Parse error, skip the rest of the macro line. if (Tok.isNot(tok::eod)) DiscardUntilEndOfDirective(); // Restore 'DisableMacroExpansion'. DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; - return false; + return {false, DT.IncludedUndefinedIds}; } // If we aren't at the tok::eod token, something bad happened, like an extra @@ -872,5 +883,5 @@ bool Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { // Restore 'DisableMacroExpansion'. DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; - return ResVal.Val != 0; + return {ResVal.Val != 0, DT.IncludedUndefinedIds}; } diff --git a/test/Index/singe-file-parse.m b/test/Index/singe-file-parse.m deleted file mode 100644 index d13915b30c5f..000000000000 --- a/test/Index/singe-file-parse.m +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: c-index-test -single-file-parse %s | FileCheck %s - -#include - -// CHECK-NOT: TypedefDecl=intptr_t - -// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=MyCls -@interface MyCls -// CHECK: [[@LINE+1]]:8: ObjCInstanceMethodDecl=some_meth --(void)some_meth; -@end diff --git a/test/Index/single-file-parse.m b/test/Index/single-file-parse.m new file mode 100644 index 000000000000..6e2189c43ddb --- /dev/null +++ b/test/Index/single-file-parse.m @@ -0,0 +1,111 @@ +// RUN: c-index-test -single-file-parse %s | FileCheck %s + +#include + +// CHECK-NOT: TypedefDecl=intptr_t + +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=MyCls +@interface MyCls +// CHECK: [[@LINE+1]]:8: ObjCInstanceMethodDecl=some_meth +-(void)some_meth; +@end + +#if 1 +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test1 +@interface Test1 @end +#else +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test2 @end +#endif + +#if 0 +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test3 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test4 +@interface Test4 @end +#endif + +#if SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test5 +@interface Test5 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test6 +@interface Test6 @end +#endif + +#define SOMETHING_DEFINED 1 +#if SOMETHING_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test7 +@interface Test7 @end +#else +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test8 @end +#endif + +#if defined(SOMETHING_NOT_DEFINED) +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test9 +@interface Test9 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test10 +@interface Test10 @end +#endif + +#if defined(SOMETHING_DEFINED) +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test11 +@interface Test11 @end +#else +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test12 @end +#endif + +#if SOMETHING_NOT_DEFINED1 +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test13 +@interface Test13 @end +#elif SOMETHING_NOT_DEFINED2 +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test14 +@interface Test14 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test15 +@interface Test15 @end +#endif + +#ifdef SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test19 +@interface Test19 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test20 +@interface Test20 @end +#endif + +#ifdef SOMETHING_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test21 +@interface Test21 @end +#else +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test22 @end +#endif + +#ifndef SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test23 +@interface Test23 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test24 +@interface Test24 @end +#endif + +#ifndef SOMETHING_DEFINED +// CHECK-NOT: [[@LINE+1]]:12: +@interface Test25 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test26 +@interface Test26 @end +#endif + +#if 1 < SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test27 +@interface Test27 @end +#else +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test28 +@interface Test28 @end +#endif From 65043f330617de8cc3740da0448c7e12110589b0 Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Tue, 20 Jun 2017 14:50:45 +0000 Subject: [PATCH 003/214] [OpenCL] Diagnose scoped address-space qualified variables Produce an error if variables qualified with a local or a constant address space are not declared in the outermost scope of a kernel. Patch by Simon Perretta. Differential Revision: https://reviews.llvm.org/D34024 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305798 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaDecl.cpp | 18 ++++++++++++++++-- test/SemaOpenCL/storageclass.cl | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 36b41c35b93d..0dd151cbd9c6 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -8311,6 +8311,9 @@ def err_opencl_ext_vector_component_invalid_length : Error< "vector component access has invalid length %0. Supported: 1,2,3,4,8,16.">; def err_opencl_function_variable : Error< "%select{non-kernel function|function scope}0 variable cannot be declared in %1 address space">; +def err_opencl_addrspace_scope : Error< + "variables in the %0 address space can only be declared in the outermost " + "scope of a kernel function">; def err_static_function_scope : Error< "variables in function scope cannot be declared static">; def err_opencl_bitfields : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index cba220daf774..d6164b3ff5e7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7260,11 +7260,11 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { NewVD->setInvalidDecl(); return; } - // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables - // in functions. if (T.getAddressSpace() == LangAS::opencl_constant || T.getAddressSpace() == LangAS::opencl_local) { FunctionDecl *FD = getCurFunctionDecl(); + // OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables + // in functions. if (FD && !FD->hasAttr()) { if (T.getAddressSpace() == LangAS::opencl_constant) Diag(NewVD->getLocation(), diag::err_opencl_function_variable) @@ -7275,6 +7275,20 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { NewVD->setInvalidDecl(); return; } + // OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be + // in the outermost scope of a kernel function. + if (FD && FD->hasAttr()) { + if (!getCurScope()->isFunctionScope()) { + if (T.getAddressSpace() == LangAS::opencl_constant) + Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope) + << "constant"; + else + Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope) + << "local"; + NewVD->setInvalidDecl(); + return; + } + } } else if (T.getAddressSpace() != LangAS::Default) { // Do not allow other address spaces on automatic variable. Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1; diff --git a/test/SemaOpenCL/storageclass.cl b/test/SemaOpenCL/storageclass.cl index e611313b4a70..9a461068f237 100644 --- a/test/SemaOpenCL/storageclass.cl +++ b/test/SemaOpenCL/storageclass.cl @@ -13,6 +13,11 @@ void kernel foo(int x) { constant int L1 = 0; local int L2; + if (true) { + local int L1; // expected-error {{variables in the local address space can only be declared in the outermost scope of a kernel function}} + constant int L1 = 42; // expected-error {{variables in the constant address space can only be declared in the outermost scope of a kernel function}} + } + auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}} global int L4; // expected-error{{function scope variable cannot be declared in global address space}} __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}} From 130156f32c5c7a9de4278d1607d552b6e8b665a4 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 20 Jun 2017 14:59:57 +0000 Subject: [PATCH 004/214] D31187: Fix removal of out-of-line definitions. Consider: struct MyClass { void f() {} } MyClass::f(){} // expected error redefinition of f. #1 Some clients (eg. cling) need to call removeDecl for the redefined (#1) decl. This patch enables us to remove the lookup entry is registered in the semantic decl context and not in the primary decl context of the lexical decl context where we currently are trying to remove it from. It is not trivial to test this piece and writing a full-blown unit test seems too much. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305799 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 032a20afa834..77ba6cf445dd 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -1352,7 +1352,7 @@ void DeclContext::removeDecl(Decl *D) { // Remove only decls that have a name if (!ND->getDeclName()) return; - auto *DC = this; + auto *DC = D->getDeclContext(); do { StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr; if (Map) { From d77a5c39338d09827950957fbbc8c2347c4d97a0 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 20 Jun 2017 16:12:26 +0000 Subject: [PATCH 005/214] Split the expectations in tests from r305719 over multiple lines to enhance readability As suggested by Duncan Exon Smith! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305803 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Parser/objc-at-implementation-eof-crash.m | 5 ++++- test/Parser/objc-at-interface-eof-crash.m | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/Parser/objc-at-implementation-eof-crash.m b/test/Parser/objc-at-implementation-eof-crash.m index 01469ecb119e..0dcece81795e 100644 --- a/test/Parser/objc-at-implementation-eof-crash.m +++ b/test/Parser/objc-at-implementation-eof-crash.m @@ -16,6 +16,9 @@ - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}} mgr fileExistsAtPath:0 } // expected-error {{expected ']'}} -@implementation ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}} // expected-warning {{cannot find interface declaration for 'ClassC'}} +@implementation ClassC // \ + // expected-error {{missing '@end'}} \ + // expected-error {{expected '}'}} \ + // expected-warning {{cannot find interface declaration for 'ClassC'}} @end diff --git a/test/Parser/objc-at-interface-eof-crash.m b/test/Parser/objc-at-interface-eof-crash.m index 7776838c9eb2..485e810494bb 100644 --- a/test/Parser/objc-at-interface-eof-crash.m +++ b/test/Parser/objc-at-interface-eof-crash.m @@ -16,6 +16,8 @@ - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}} mgr fileExistsAtPath:0 } // expected-error {{expected ']'}} -@interface ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}} +@interface ClassC // \ + // expected-error {{missing '@end'}} \ + // expected-error {{expected '}'}} @end From 026fbae01b0717526f23327002db117c3bc13525 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 20 Jun 2017 16:16:11 +0000 Subject: [PATCH 006/214] Add a missing '[' to the tests from r305719 This clarifies the tests as the missing ']' is important, and not the '['. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305804 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Parser/objc-at-implementation-eof-crash.m | 2 +- test/Parser/objc-at-interface-eof-crash.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Parser/objc-at-implementation-eof-crash.m b/test/Parser/objc-at-implementation-eof-crash.m index 0dcece81795e..76e56c10703e 100644 --- a/test/Parser/objc-at-implementation-eof-crash.m +++ b/test/Parser/objc-at-implementation-eof-crash.m @@ -13,7 +13,7 @@ @interface ClassB @implementation ClassB // expected-note {{implementation started here}} - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}} - mgr fileExistsAtPath:0 + [mgr fileExistsAtPath:0 } // expected-error {{expected ']'}} @implementation ClassC // \ diff --git a/test/Parser/objc-at-interface-eof-crash.m b/test/Parser/objc-at-interface-eof-crash.m index 485e810494bb..2c7bfd688f06 100644 --- a/test/Parser/objc-at-interface-eof-crash.m +++ b/test/Parser/objc-at-interface-eof-crash.m @@ -13,7 +13,7 @@ @interface ClassB @implementation ClassB // expected-note {{implementation started here}} - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}} - mgr fileExistsAtPath:0 + [mgr fileExistsAtPath:0 } // expected-error {{expected ']'}} @interface ClassC // \ From f5f37badaf42c9f95d12cedd7d097cf7673c8817 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Tue, 20 Jun 2017 16:31:31 +0000 Subject: [PATCH 007/214] [GSoC] Flag value completion for clang This is patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. In this patch, Options.td was mainly changed in order to add value class in Options.inc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305805 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.h | 5 +++-- include/clang/Driver/Options.td | 22 +++++++++++----------- lib/Driver/Driver.cpp | 20 +++++++++++++++++++- lib/Driver/DriverOptions.cpp | 8 ++++---- test/Driver/autocomplete.c | 30 ++++++++++++++++++++++++++++++ utils/bash-autocomplete.sh | 30 +++++++++++++++++++++++++++--- 6 files changed, 94 insertions(+), 21 deletions(-) diff --git a/include/clang/Driver/Options.h b/include/clang/Driver/Options.h index 57e4452f3e8c..2da3cb4828c8 100644 --- a/include/clang/Driver/Options.h +++ b/include/clang/Driver/Options.h @@ -39,8 +39,9 @@ enum ClangFlags { enum ID { OPT_INVALID = 0, // This is not an option ID. -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR) OPT_##ID, +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + OPT_##ID, #include "clang/Driver/Options.inc" LastOption #undef OPTION diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 6c51976e98fe..bd4d521752a1 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -493,7 +493,7 @@ def cl_mad_enable : Flag<["-"], "cl-mad-enable">, Group, Flags<[CC def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.">; def cl_std_EQ : Joined<["-"], "cl-std=">, Group, Flags<[CC1Option]>, - HelpText<"OpenCL language standard to compile for.">; + HelpText<"OpenCL language standard to compile for.">, Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">; def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. Allow denormals to be flushed to zero.">; def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>, @@ -804,7 +804,7 @@ def fno_sanitize_coverage : CommaJoined<["-"], "fno-sanitize-coverage=">, Group, Flags<[CoreOption, DriverOption]>, HelpText<"Disable specified features of coverage instrumentation for " - "Sanitizers">; + "Sanitizers">, Values<"func,bb,edge,indirect-calls,trace-bb,trace-cmp,trace-div,trace-gep,8bit-counters,trace-pc,trace-pc-guard,no-prune,inline-8bit-counters">; def fsanitize_memory_track_origins_EQ : Joined<["-"], "fsanitize-memory-track-origins=">, Group, HelpText<"Enable origins tracking in MemorySanitizer">; @@ -923,7 +923,7 @@ def ftrapping_math : Flag<["-"], "ftrapping-math">, Group, Flags<[CC1Op def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group, Flags<[CC1Option]>; def ffp_contract : Joined<["-"], "ffp-contract=">, Group, Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast (everywhere)" - " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">; + " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">, Values<"fast,on,off">; def ffor_scope : Flag<["-"], "ffor-scope">, Group; def fno_for_scope : Flag<["-"], "fno-for-scope">, Group; @@ -1000,7 +1000,7 @@ def flat__namespace : Flag<["-"], "flat_namespace">; def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group; def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group; def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, Group, - HelpText<"Set LTO mode to either 'full' or 'thin'">; + HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">; def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group, HelpText<"Enable LTO in 'full' mode">; def fno_lto : Flag<["-"], "fno-lto">, Group, @@ -1158,7 +1158,7 @@ def fno_experimental_new_pass_manager : Flag<["-"], "fno-experimental-new-pass-m Group, Flags<[CC1Option]>, HelpText<"Disables an experimental new pass manager in LLVM.">; def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>, - HelpText<"Use the given vector functions library">; + HelpText<"Use the given vector functions library">, Values<"Accelerate,SVML,none">; def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group, HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>; def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group, @@ -1342,7 +1342,7 @@ def fno_short_wchar : Flag<["-"], "fno-short-wchar">, Group, Flags<[CC1 HelpText<"Force wchar_t to be an unsigned int">; def fshow_overloads_EQ : Joined<["-"], "fshow-overloads=">, Group, Flags<[CC1Option]>, HelpText<"Which overload candidates to show when overload resolution fails: " - "best|all; defaults to all">; + "best|all; defaults to all">, Values<"best,all">; def fshow_column : Flag<["-"], "fshow-column">, Group, Flags<[CC1Option]>; def fshow_source_location : Flag<["-"], "fshow-source-location">, Group; def fspell_checking : Flag<["-"], "fspell-checking">, Group; @@ -1456,7 +1456,7 @@ def fuse_init_array : Flag<["-"], "fuse-init-array">, Group, Flags<[CC1 def fno_var_tracking : Flag<["-"], "fno-var-tracking">, Group; def fverbose_asm : Flag<["-"], "fverbose-asm">, Group; def fvisibility_EQ : Joined<["-"], "fvisibility=">, Group, - HelpText<"Set the default symbol visibility for all global declarations">; + HelpText<"Set the default symbol visibility for all global declarations">, Values<"hidden,default">; def fvisibility_inlines_hidden : Flag<["-"], "fvisibility-inlines-hidden">, Group, HelpText<"Give inline C++ member functions default visibility by default">, Flags<[CC1Option]>; @@ -1677,7 +1677,7 @@ def minline_all_stringops : Flag<["-"], "minline-all-stringops">, Group, Group; def malign_double : Flag<["-"], "malign-double">, Group, Flags<[CC1Option]>, HelpText<"Align doubles to two words in structs (x86 only)">; -def mfloat_abi_EQ : Joined<["-"], "mfloat-abi=">, Group; +def mfloat_abi_EQ : Joined<["-"], "mfloat-abi=">, Group, Values<"soft,softfp,hard">; def mfpmath_EQ : Joined<["-"], "mfpmath=">, Group; def mfpu_EQ : Joined<["-"], "mfpu=">, Group; def mhwdiv_EQ : Joined<["-"], "mhwdiv=">, Group; @@ -1709,9 +1709,9 @@ def mstack_alignment : Joined<["-"], "mstack-alignment=">, Group, Flags def mstack_probe_size : Joined<["-"], "mstack-probe-size=">, Group, Flags<[CC1Option]>, HelpText<"Set the stack probe size">; def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>, - HelpText<"The thread model to use, e.g. posix, single (posix by default)">; + HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">; def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>, - HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">; + HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">; def mmmx : Flag<["-"], "mmmx">, Group; def mno_3dnowa : Flag<["-"], "mno-3dnowa">, Group; @@ -2205,7 +2205,7 @@ def std_default_EQ : Joined<["-"], "std-default=">; def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>, Group, HelpText<"Language standard to compile for">; def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>, - HelpText<"C++ standard library to use">; + HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">; def sub__library : JoinedOrSeparate<["-"], "sub_library">; def sub__umbrella : JoinedOrSeparate<["-"], "sub_umbrella">; def system_header_prefix : Joined<["--"], "system-header-prefix=">, diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index eb504fd4e541..850f6bc9dde7 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1227,7 +1227,25 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { if (Arg *A = C.getArgs().getLastArg(options::OPT_autocomplete)) { // Print out all options that start with a given argument. This is used for // shell autocompletion. - llvm::outs() << llvm::join(Opts->findByPrefix(A->getValue()), " ") << '\n'; + StringRef PassedFlags = A->getValue(); + std::vector SuggestedCompletions; + + if (PassedFlags.find(',') == StringRef::npos) { + // If the flag is in the form of "--autocomplete=-foo", + // we were requested to print out all option names that start with "-foo". + // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only". + SuggestedCompletions = Opts->findByPrefix(PassedFlags); + } else { + // If the flag is in the form of "--autocomplete=foo,bar", we were + // requested to print out all option values for "-foo" that start with + // "bar". For example, + // "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++". + StringRef Option, Arg; + std::tie(Option, Arg) = PassedFlags.split(','); + SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg); + } + + llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n'; return false; } diff --git a/lib/Driver/DriverOptions.cpp b/lib/Driver/DriverOptions.cpp index 6a7410901d25..ac63b96cf96d 100644 --- a/lib/Driver/DriverOptions.cpp +++ b/lib/Driver/DriverOptions.cpp @@ -21,10 +21,10 @@ using namespace llvm::opt; #undef PREFIX static const OptTable::Info InfoTable[] = { -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR) \ - { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \ - FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS }, +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + {PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, \ + PARAM, FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES}, #include "clang/Driver/Options.inc" #undef OPTION }; diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c index 94649f243738..78ac4b07cf07 100644 --- a/test/Driver/autocomplete.c +++ b/test/Driver/autocomplete.c @@ -4,3 +4,33 @@ // STD: -std={{.*}}-stdlib= // RUN: %clang --autocomplete=foo | not FileCheck %s -check-prefix=NONE // NONE: foo +// RUN: %clang --autocomplete=-stdlib=,l | FileCheck %s -check-prefix=STDLIB +// STDLIB: libc++ libstdc++ +// RUN: %clang --autocomplete=-stdlib=, | FileCheck %s -check-prefix=STDLIBALL +// STDLIBALL: libc++ libstdc++ platform +// RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI +// MEABI: default +// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL +// MEABIALL: default 4 5 gnu +// RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD +// CLSTD: CL2.0 +// RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL +// CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0 +// RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER +// FNOSANICOVER: func +// RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s -check-prefix=FNOSANICOVERALL +// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters +// RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s -check-prefix=FFPALL +// FFPALL: fast on off +// RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL +// FLTOALL: thin full +// RUN: %clang --autocomplete=-fveclib=, | FileCheck %s -check-prefix=FVECLIBALL +// FVECLIBALL: Accelerate SVML none +// RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s -check-prefix=FSOVERALL +// FSOVERALL: best all +// RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s -check-prefix=FVISIBILITYALL +// FVISIBILITYALL: hidden default +// RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s -check-prefix=MFLOATABIALL +// MFLOATABIALL: soft softfp hard +// RUN: %clang --autocomplete=-mthread-model, | FileCheck %s -check-prefix=MTHREADMODELALL +// MTHREADMODELALL: posix single diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index de4a435b8849..3e9f65f10db2 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -1,11 +1,35 @@ # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this. _clang() { - local cur prev words cword flags + local cur prev words cword arg _init_completion -n : || return - flags=$( clang --autocomplete="$cur" ) - if [[ "$flags" == "" || "$cur" == "" ]]; then + # bash always separates '=' as a token even if there's no space before/after '='. + # On the other hand, '=' is just a regular character for clang options that + # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=". + # So, we need to partially undo bash tokenization here for integrity. + local w1="${COMP_WORDS[$cword - 1]}" + local w2="${COMP_WORDS[$cword - 2]}" + if [[ "$cur" == -* ]]; then + # -foo + arg="$cur" + elif [[ "$w1" == -* && "$cur" == '=' ]]; then + # -foo= + arg="$w1=," + elif [[ "$w1" == -* ]]; then + # -foo or -foo bar + arg="$w1,$cur" + elif [[ "$w2" == -* && "$w1" == '=' ]]; then + # -foo=bar + arg="$w2=,$cur" + else + _filedir + fi + + local flags=$( clang --autocomplete="$arg" ) + if [[ "$cur" == "=" ]]; then + COMPREPLY=( $( compgen -W "$flags" -- "") ) + elif [[ "$flags" == "" ]]; then _filedir else COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) ) From c35b73c765d276f2433f2f89229022e5f08b003c Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 20 Jun 2017 17:38:07 +0000 Subject: [PATCH 008/214] Fix for Bug 33471: Preventing operator auto from resolving to a template operator. As the bug report says, struct A { template operator T(); }; void foo() { A().operator auto(); } causes: "undeduced type in IR-generation UNREACHABLE executed at llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:208!" The problem is that in this case, "T" is being deduced as "auto", which I believe is incorrect. The 'operator auto' implementation in Clang is standards compliant, however there is a defect report against core (1670). Differential Revision: https://reviews.llvm.org/D34370 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305812 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 10 ++++++++++ test/SemaCXX/cxx1y-deduced-return-type.cpp | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 1fb25f4e0e7c..9f657a446c02 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -862,6 +862,16 @@ static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC) { if (!Record->isCompleteDefinition()) return Found; + // For conversion operators, 'operator auto' should only match + // 'operator auto'. Since 'auto' is not a type, it shouldn't be considered + // as a candidate for template substitution. + auto *ContainedDeducedType = + R.getLookupName().getCXXNameType()->getContainedDeducedType(); + if (R.getLookupName().getNameKind() == + DeclarationName::CXXConversionFunctionName && + ContainedDeducedType && ContainedDeducedType->isUndeducedType()) + return Found; + for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(), UEnd = Record->conversion_end(); U != UEnd; ++U) { FunctionTemplateDecl *ConvTemplate = dyn_cast(*U); diff --git a/test/SemaCXX/cxx1y-deduced-return-type.cpp b/test/SemaCXX/cxx1y-deduced-return-type.cpp index bfe0ab9dcdbc..13ff751acae4 100644 --- a/test/SemaCXX/cxx1y-deduced-return-type.cpp +++ b/test/SemaCXX/cxx1y-deduced-return-type.cpp @@ -55,6 +55,25 @@ auto b(bool k) { return "goodbye"; } +// Allow 'operator auto' to call only the explicit operator auto. +struct BothOps { + template operator T(); + template operator T *(); + operator auto() { return 0; } + operator auto *() { return this; } +}; +struct JustTemplateOp { + template operator T(); + template operator T *(); +}; + +auto c() { + BothOps().operator auto(); // ok + BothOps().operator auto *(); // ok + JustTemplateOp().operator auto(); // expected-error {{no member named 'operator auto' in 'JustTemplateOp'}} + JustTemplateOp().operator auto *(); // expected-error {{no member named 'operator auto *' in 'JustTemplateOp'}} +} + auto *ptr_1() { return 100; // expected-error {{cannot deduce return type 'auto *' from returned value of type 'int'}} } From 6e3f80de39298b1ac410e59841c60853e807fa37 Mon Sep 17 00:00:00 2001 From: Abderrazek Zaafrani Date: Tue, 20 Jun 2017 18:54:57 +0000 Subject: [PATCH 009/214] [AArch64] ADD ARMv.2-A FP16 vector intrinsics Differential Revision: https://reviews.llvm.org/D34161 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305820 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/arm_neon.td | 185 ++ lib/Basic/Targets.cpp | 10 + lib/CodeGen/CGBuiltin.cpp | 183 +- lib/CodeGen/CodeGenModule.cpp | 1 + lib/CodeGen/CodeGenTypeCache.h | 2 +- test/CodeGen/aarch64-neon-intrinsics.c | 230 ++- test/CodeGen/aarch64-neon-ldst-one.c | 228 ++- test/CodeGen/aarch64-v8.2a-neon-intrinsics.c | 1633 ++++++++++++++++++ test/CodeGen/arm_neon_intrinsics.c | 240 ++- utils/TableGen/NeonEmitter.cpp | 6 +- 10 files changed, 2355 insertions(+), 363 deletions(-) create mode 100644 test/CodeGen/aarch64-v8.2a-neon-intrinsics.c diff --git a/include/clang/Basic/arm_neon.td b/include/clang/Basic/arm_neon.td index ad8d679a1664..d5c16a91a34f 100644 --- a/include/clang/Basic/arm_neon.td +++ b/include/clang/Basic/arm_neon.td @@ -227,6 +227,7 @@ def OP_UNAVAILABLE : Operation { // u: unsigned integer (int/float args) // f: float (int args) // F: double (int args) +// H: half (int args) // d: default // g: default, ignore 'Q' size modifier. // j: default, force 'Q' size modifier. @@ -345,6 +346,7 @@ def OP_MLSLHi : Op<(call "vmlsl", $p0, (call "vget_high", $p1), (call "vget_high", $p2))>; def OP_MLSLHi_N : Op<(call "vmlsl_n", $p0, (call "vget_high", $p1), $p2)>; def OP_MUL_N : Op<(op "*", $p0, (dup $p1))>; +def OP_MULX_N : Op<(call "vmulx", $p0, (dup $p1))>; def OP_MLA_N : Op<(op "+", $p0, (op "*", $p1, (dup $p2)))>; def OP_MLS_N : Op<(op "-", $p0, (op "*", $p1, (dup $p2)))>; def OP_FMLA_N : Op<(call "vfma", $p0, $p1, (dup $p2))>; @@ -1661,3 +1663,186 @@ def SCALAR_SQRDMLSH_LANEQ : SOpInst<"vqrdmlsh_laneq", "sssji", "SsSi", OP_SCALAR def SCALAR_VDUP_LANE : IInst<"vdup_lane", "sdi", "ScSsSiSlSfSdSUcSUsSUiSUlSPcSPs">; def SCALAR_VDUP_LANEQ : IInst<"vdup_laneq", "sji", "ScSsSiSlSfSdSUcSUsSUiSUlSPcSPs">; } + +// ARMv8.2-A FP16 intrinsics. +let ArchGuard = "defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(__aarch64__)" in { + + // ARMv8.2-A FP16 one-operand vector intrinsics. + + // Comparison + def CMEQH : SInst<"vceqz", "ud", "hQh">; + def CMGEH : SInst<"vcgez", "ud", "hQh">; + def CMGTH : SInst<"vcgtz", "ud", "hQh">; + def CMLEH : SInst<"vclez", "ud", "hQh">; + def CMLTH : SInst<"vcltz", "ud", "hQh">; + + // Vector conversion + def VCVT_F16 : SInst<"vcvt_f16", "Hd", "sUsQsQUs">; + def VCVT_S16 : SInst<"vcvt_s16", "xd", "hQh">; + def VCVT_U16 : SInst<"vcvt_u16", "ud", "hQh">; + def VCVTA_S16 : SInst<"vcvta_s16", "xd", "hQh">; + def VCVTA_U16 : SInst<"vcvta_u16", "ud", "hQh">; + def VCVTM_S16 : SInst<"vcvtm_s16", "xd", "hQh">; + def VCVTM_U16 : SInst<"vcvtm_u16", "ud", "hQh">; + def VCVTN_S16 : SInst<"vcvtn_s16", "xd", "hQh">; + def VCVTN_U16 : SInst<"vcvtn_u16", "ud", "hQh">; + def VCVTP_S16 : SInst<"vcvtp_s16", "xd", "hQh">; + def VCVTP_U16 : SInst<"vcvtp_u16", "ud", "hQh">; + + // Vector rounding + def FRINTZH : SInst<"vrnd", "dd", "hQh">; + def FRINTNH : SInst<"vrndn", "dd", "hQh">; + def FRINTAH : SInst<"vrnda", "dd", "hQh">; + def FRINTPH : SInst<"vrndp", "dd", "hQh">; + def FRINTMH : SInst<"vrndm", "dd", "hQh">; + def FRINTXH : SInst<"vrndx", "dd", "hQh">; + def FRINTIH : SInst<"vrndi", "dd", "hQh">; + + // Misc. + def VABSH : SInst<"vabs", "dd", "hQh">; + def VNEGH : SOpInst<"vneg", "dd", "hQh", OP_NEG>; + def VRECPEH : SInst<"vrecpe", "dd", "hQh">; + def FRSQRTEH : SInst<"vrsqrte", "dd", "hQh">; + def FSQRTH : SInst<"vsqrt", "dd", "hQh">; + + // ARMv8.2-A FP16 two-operands vector intrinsics. + + // Misc. + def VADDH : SOpInst<"vadd", "ddd", "hQh", OP_ADD>; + def VABDH : SInst<"vabd", "ddd", "hQh">; + def VSUBH : SOpInst<"vsub", "ddd", "hQh", OP_SUB>; + + // Comparison + let InstName = "vacge" in { + def VCAGEH : SInst<"vcage", "udd", "hQh">; + def VCALEH : SInst<"vcale", "udd", "hQh">; + } + let InstName = "vacgt" in { + def VCAGTH : SInst<"vcagt", "udd", "hQh">; + def VCALTH : SInst<"vcalt", "udd", "hQh">; + } + def VCEQH : SOpInst<"vceq", "udd", "hQh", OP_EQ>; + def VCGEH : SOpInst<"vcge", "udd", "hQh", OP_GE>; + def VCGTH : SOpInst<"vcgt", "udd", "hQh", OP_GT>; + let InstName = "vcge" in + def VCLEH : SOpInst<"vcle", "udd", "hQh", OP_LE>; + let InstName = "vcgt" in + def VCLTH : SOpInst<"vclt", "udd", "hQh", OP_LT>; + + // Vector conversion + let isVCVT_N = 1 in { + def VCVT_N_F16 : SInst<"vcvt_n_f16", "Hdi", "sUsQsQUs">; + def VCVT_N_S16 : SInst<"vcvt_n_s16", "xdi", "hQh">; + def VCVT_N_U16 : SInst<"vcvt_n_u16", "udi", "hQh">; + } + + // Max/Min + def VMAXH : SInst<"vmax", "ddd", "hQh">; + def VMINH : SInst<"vmin", "ddd", "hQh">; + def FMAXNMH : SInst<"vmaxnm", "ddd", "hQh">; + def FMINNMH : SInst<"vminnm", "ddd", "hQh">; + + // Multiplication/Division + def VMULH : SOpInst<"vmul", "ddd", "hQh", OP_MUL>; + def MULXH : SInst<"vmulx", "ddd", "hQh">; + def FDIVH : IOpInst<"vdiv", "ddd", "hQh", OP_DIV>; + + // Pairwise addition + def VPADDH : SInst<"vpadd", "ddd", "hQh">; + + // Pairwise Max/Min + def VPMAXH : SInst<"vpmax", "ddd", "hQh">; + def VPMINH : SInst<"vpmin", "ddd", "hQh">; + // Pairwise MaxNum/MinNum + def FMAXNMPH : SInst<"vpmaxnm", "ddd", "hQh">; + def FMINNMPH : SInst<"vpminnm", "ddd", "hQh">; + + // Reciprocal/Sqrt + def VRECPSH : SInst<"vrecps", "ddd", "hQh">; + def VRSQRTSH : SInst<"vrsqrts", "ddd", "hQh">; + + // ARMv8.2-A FP16 three-operands vector intrinsics. + + // Vector fused multiply-add operations + def VFMAH : SInst<"vfma", "dddd", "hQh">; + def VFMSH : SOpInst<"vfms", "dddd", "hQh", OP_FMLS>; + + // ARMv8.2-A FP16 lane vector intrinsics. + + // FMA lane + def VFMA_LANEH : IInst<"vfma_lane", "dddgi", "hQh">; + def VFMA_LANEQH : IInst<"vfma_laneq", "dddji", "hQh">; + + // FMA lane with scalar argument + def FMLA_NH : SOpInst<"vfma_n", "ddds", "hQh", OP_FMLA_N>; + // Scalar floating point fused multiply-add (scalar, by element) + def SCALAR_FMLA_LANEH : IInst<"vfma_lane", "sssdi", "Sh">; + def SCALAR_FMLA_LANEQH : IInst<"vfma_laneq", "sssji", "Sh">; + + // FMS lane + def VFMS_LANEH : IOpInst<"vfms_lane", "dddgi", "hQh", OP_FMS_LN>; + def VFMS_LANEQH : IOpInst<"vfms_laneq", "dddji", "hQh", OP_FMS_LNQ>; + // FMS lane with scalar argument + def FMLS_NH : SOpInst<"vfms_n", "ddds", "hQh", OP_FMLS_N>; + // Scalar floating foint fused multiply-subtract (scalar, by element) + def SCALAR_FMLS_LANEH : IOpInst<"vfms_lane", "sssdi", "Sh", OP_FMS_LN>; + def SCALAR_FMLS_LANEQH : IOpInst<"vfms_laneq", "sssji", "Sh", OP_FMS_LNQ>; + + // Mul lane + def VMUL_LANEH : IOpInst<"vmul_lane", "ddgi", "hQh", OP_MUL_LN>; + def VMUL_LANEQH : IOpInst<"vmul_laneq", "ddji", "hQh", OP_MUL_LN>; + def VMUL_NH : IOpInst<"vmul_n", "dds", "hQh", OP_MUL_N>; + // Scalar floating point multiply (scalar, by element) + def SCALAR_FMUL_LANEH : IOpInst<"vmul_lane", "ssdi", "Sh", OP_SCALAR_MUL_LN>; + def SCALAR_FMUL_LANEQH : IOpInst<"vmul_laneq", "ssji", "Sh", OP_SCALAR_MUL_LN>; + + // Mulx lane + def VMULX_LANEH : IOpInst<"vmulx_lane", "ddgi", "hQh", OP_MULX_LN>; + def VMULX_LANEQH : IOpInst<"vmulx_laneq", "ddji", "hQh", OP_MULX_LN>; + def VMULX_NH : IOpInst<"vmulx_n", "dds", "hQh", OP_MULX_N>; + // TODO: Scalar floating point multiply extended (scalar, by element) + // Below ones are commented out because they need vmulx_f16(float16_t, float16_t) + // which will be implemented later with fp16 scalar intrinsic (arm_fp16.h) + //def SCALAR_FMULX_LANEH : IOpInst<"vmulx_lane", "ssdi", "Sh", OP_SCALAR_MUL_LN>; + //def SCALAR_FMULX_LANEQH : IOpInst<"vmulx_laneq", "ssji", "Sh", OP_SCALAR_MUL_LN>; + + // ARMv8.2-A FP16 reduction vector intrinsics. + def VMAXVH : SInst<"vmaxv", "sd", "hQh">; + def VMINVH : SInst<"vminv", "sd", "hQh">; + def FMAXNMVH : SInst<"vmaxnmv", "sd", "hQh">; + def FMINNMVH : SInst<"vminnmv", "sd", "hQh">; + + // Data processing intrinsics - section 5 + + // Logical operations + let isHiddenLInst = 1 in + def VBSLH : SInst<"vbsl", "dudd", "hQh">; + + // Transposition operations + def VZIPH : WInst<"vzip", "2dd", "hQh">; + def VUZPH : WInst<"vuzp", "2dd", "hQh">; + def VTRNH : WInst<"vtrn", "2dd", "hQh">; + + // Set all lanes to same value. + /* Already implemented prior to ARMv8.2-A. + def VMOV_NH : WOpInst<"vmov_n", "ds", "hQh", OP_DUP>; + def VDUP_NH : WOpInst<"vdup_n", "ds", "hQh", OP_DUP>; + def VDUP_LANE1H : WOpInst<"vdup_lane", "dgi", "hQh", OP_DUP_LN>;*/ + + // Vector Extract + def VEXTH : WInst<"vext", "dddi", "hQh">; + + // Reverse vector elements + def VREV64H : WOpInst<"vrev64", "dd", "hQh", OP_REV64>; + + // Permutation + def VTRN1H : SOpInst<"vtrn1", "ddd", "hQh", OP_TRN1>; + def VZIP1H : SOpInst<"vzip1", "ddd", "hQh", OP_ZIP1>; + def VUZP1H : SOpInst<"vuzp1", "ddd", "hQh", OP_UZP1>; + def VTRN2H : SOpInst<"vtrn2", "ddd", "hQh", OP_TRN2>; + def VZIP2H : SOpInst<"vzip2", "ddd", "hQh", OP_ZIP2>; + def VUZP2H : SOpInst<"vuzp2", "ddd", "hQh", OP_UZP2>; + + def SCALAR_VDUP_LANEH : IInst<"vdup_lane", "sdi", "Sh">; + def SCALAR_VDUP_LANEQH : IInst<"vdup_laneq", "sji", "Sh">; +} diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index a3b8330707b9..e23a93e8ced7 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -6172,6 +6172,8 @@ class AArch64TargetInfo : public TargetInfo { unsigned Crypto; unsigned Unaligned; unsigned V8_1A; + unsigned V8_2A; + unsigned HasFullFP16; static const Builtin::Info BuiltinInfo[]; @@ -6303,6 +6305,8 @@ class AArch64TargetInfo : public TargetInfo { if (V8_1A) Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); + if (V8_2A && FPU == NeonMode && HasFullFP16) + Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1"); // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8) builtins work. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"); @@ -6330,6 +6334,8 @@ class AArch64TargetInfo : public TargetInfo { Crypto = 0; Unaligned = 1; V8_1A = 0; + V8_2A = 0; + HasFullFP16 = 0; for (const auto &Feature : Features) { if (Feature == "+neon") @@ -6342,6 +6348,10 @@ class AArch64TargetInfo : public TargetInfo { Unaligned = 0; if (Feature == "+v8.1a") V8_1A = 1; + if (Feature == "+v8.2a") + V8_2A = 1; + if (Feature == "+fullfp16") + HasFullFP16 = 1; } setDataLayout(); diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 8f0c22d1f7ef..a6451b7fc3c1 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -2956,8 +2956,9 @@ static llvm::VectorType *GetNeonType(CodeGenFunction *CGF, return llvm::VectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad)); case NeonTypeFlags::Int16: case NeonTypeFlags::Poly16: - case NeonTypeFlags::Float16: return llvm::VectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad)); + case NeonTypeFlags::Float16: + return llvm::VectorType::get(CGF->HalfTy, V1Ty ? 1 : (4 << IsQuad)); case NeonTypeFlags::Int32: return llvm::VectorType::get(CGF->Int32Ty, V1Ty ? 1 : (2 << IsQuad)); case NeonTypeFlags::Int64: @@ -2980,6 +2981,8 @@ static llvm::VectorType *GetFloatNeonType(CodeGenFunction *CGF, NeonTypeFlags IntTypeFlags) { int IsQuad = IntTypeFlags.isQuad(); switch (IntTypeFlags.getEltType()) { + case NeonTypeFlags::Int16: + return llvm::VectorType::get(CGF->HalfTy, (4 << IsQuad)); case NeonTypeFlags::Int32: return llvm::VectorType::get(CGF->FloatTy, (2 << IsQuad)); case NeonTypeFlags::Int64: @@ -3127,55 +3130,80 @@ static const NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = { NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0), NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0), NEONMAP0(vcvt_f32_v), + NEONMAP2(vcvt_n_f16_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), + NEONMAP1(vcvt_n_s16_v, arm_neon_vcvtfp2fxs, 0), NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0), NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0), + NEONMAP1(vcvt_n_u16_v, arm_neon_vcvtfp2fxu, 0), NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0), NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0), + NEONMAP0(vcvt_s16_v), NEONMAP0(vcvt_s32_v), NEONMAP0(vcvt_s64_v), + NEONMAP0(vcvt_u16_v), NEONMAP0(vcvt_u32_v), NEONMAP0(vcvt_u64_v), + NEONMAP1(vcvta_s16_v, arm_neon_vcvtas, 0), NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0), NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0), NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0), NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0), + NEONMAP1(vcvtaq_s16_v, arm_neon_vcvtas, 0), NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0), NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0), + NEONMAP1(vcvtaq_u16_v, arm_neon_vcvtau, 0), NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0), NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0), + NEONMAP1(vcvtm_s16_v, arm_neon_vcvtms, 0), NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0), NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0), + NEONMAP1(vcvtm_u16_v, arm_neon_vcvtmu, 0), NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0), NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0), + NEONMAP1(vcvtmq_s16_v, arm_neon_vcvtms, 0), NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0), NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0), + NEONMAP1(vcvtmq_u16_v, arm_neon_vcvtmu, 0), NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0), NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0), + NEONMAP1(vcvtn_s16_v, arm_neon_vcvtns, 0), NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0), NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0), + NEONMAP1(vcvtn_u16_v, arm_neon_vcvtnu, 0), NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0), NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0), + NEONMAP1(vcvtnq_s16_v, arm_neon_vcvtns, 0), NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0), NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0), + NEONMAP1(vcvtnq_u16_v, arm_neon_vcvtnu, 0), NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0), NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0), + NEONMAP1(vcvtp_s16_v, arm_neon_vcvtps, 0), NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0), NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0), + NEONMAP1(vcvtp_u16_v, arm_neon_vcvtpu, 0), NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0), NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0), + NEONMAP1(vcvtpq_s16_v, arm_neon_vcvtps, 0), NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0), NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0), + NEONMAP1(vcvtpq_u16_v, arm_neon_vcvtpu, 0), NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0), NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0), NEONMAP0(vcvtq_f32_v), + NEONMAP2(vcvtq_n_f16_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), + NEONMAP1(vcvtq_n_s16_v, arm_neon_vcvtfp2fxs, 0), NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0), NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0), + NEONMAP1(vcvtq_n_u16_v, arm_neon_vcvtfp2fxu, 0), NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0), NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0), + NEONMAP0(vcvtq_s16_v), NEONMAP0(vcvtq_s32_v), NEONMAP0(vcvtq_s64_v), + NEONMAP0(vcvtq_u16_v), NEONMAP0(vcvtq_u32_v), NEONMAP0(vcvtq_u64_v), NEONMAP0(vext_v), @@ -3338,19 +3366,27 @@ static const NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = { NEONMAP1(vcnt_v, ctpop, Add1ArgType), NEONMAP1(vcntq_v, ctpop, Add1ArgType), NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0), + NEONMAP0(vcvt_f16_v), NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0), NEONMAP0(vcvt_f32_v), + NEONMAP2(vcvt_n_f16_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), + NEONMAP1(vcvt_n_s16_v, aarch64_neon_vcvtfp2fxs, 0), NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), + NEONMAP1(vcvt_n_u16_v, aarch64_neon_vcvtfp2fxu, 0), NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), + NEONMAP0(vcvtq_f16_v), NEONMAP0(vcvtq_f32_v), + NEONMAP2(vcvtq_n_f16_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), + NEONMAP1(vcvtq_n_s16_v, aarch64_neon_vcvtfp2fxs, 0), NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), + NEONMAP1(vcvtq_n_u16_v, aarch64_neon_vcvtfp2fxu, 0), NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType), @@ -3819,9 +3855,20 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( case NEON::BI__builtin_neon_vcageq_v: case NEON::BI__builtin_neon_vcagt_v: case NEON::BI__builtin_neon_vcagtq_v: { - llvm::Type *VecFlt = llvm::VectorType::get( - VTy->getScalarSizeInBits() == 32 ? FloatTy : DoubleTy, - VTy->getNumElements()); + llvm::Type *Ty; + switch (VTy->getScalarSizeInBits()) { + default: llvm_unreachable("unexpected type"); + case 32: + Ty = FloatTy; + break; + case 64: + Ty = DoubleTy; + break; + case 16: + Ty = HalfTy; + break; + } + llvm::Type *VecFlt = llvm::VectorType::get(Ty, VTy->getNumElements()); llvm::Type *Tys[] = { VTy, VecFlt }; Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); return EmitNeonCall(F, Ops, NameHint); @@ -3838,8 +3885,16 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, Quad)); return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); + case NEON::BI__builtin_neon_vcvt_f16_v: + case NEON::BI__builtin_neon_vcvtq_f16_v: + Ops[0] = Builder.CreateBitCast(Ops[0], Ty); + Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float16, false, Quad)); + return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") + : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); + case NEON::BI__builtin_neon_vcvt_n_f16_v: case NEON::BI__builtin_neon_vcvt_n_f32_v: case NEON::BI__builtin_neon_vcvt_n_f64_v: + case NEON::BI__builtin_neon_vcvtq_n_f16_v: case NEON::BI__builtin_neon_vcvtq_n_f32_v: case NEON::BI__builtin_neon_vcvtq_n_f64_v: { llvm::Type *Tys[2] = { GetFloatNeonType(this, Type), Ty }; @@ -3847,11 +3902,15 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( Function *F = CGM.getIntrinsic(Int, Tys); return EmitNeonCall(F, Ops, "vcvt_n"); } + case NEON::BI__builtin_neon_vcvt_n_s16_v: case NEON::BI__builtin_neon_vcvt_n_s32_v: + case NEON::BI__builtin_neon_vcvt_n_u16_v: case NEON::BI__builtin_neon_vcvt_n_u32_v: case NEON::BI__builtin_neon_vcvt_n_s64_v: case NEON::BI__builtin_neon_vcvt_n_u64_v: + case NEON::BI__builtin_neon_vcvtq_n_s16_v: case NEON::BI__builtin_neon_vcvtq_n_s32_v: + case NEON::BI__builtin_neon_vcvtq_n_u16_v: case NEON::BI__builtin_neon_vcvtq_n_u32_v: case NEON::BI__builtin_neon_vcvtq_n_s64_v: case NEON::BI__builtin_neon_vcvtq_n_u64_v: { @@ -3863,44 +3922,63 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( case NEON::BI__builtin_neon_vcvt_u32_v: case NEON::BI__builtin_neon_vcvt_s64_v: case NEON::BI__builtin_neon_vcvt_u64_v: + case NEON::BI__builtin_neon_vcvt_s16_v: + case NEON::BI__builtin_neon_vcvt_u16_v: case NEON::BI__builtin_neon_vcvtq_s32_v: case NEON::BI__builtin_neon_vcvtq_u32_v: case NEON::BI__builtin_neon_vcvtq_s64_v: - case NEON::BI__builtin_neon_vcvtq_u64_v: { + case NEON::BI__builtin_neon_vcvtq_u64_v: + case NEON::BI__builtin_neon_vcvtq_s16_v: + case NEON::BI__builtin_neon_vcvtq_u16_v: { Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); return Usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); } + case NEON::BI__builtin_neon_vcvta_s16_v: case NEON::BI__builtin_neon_vcvta_s32_v: case NEON::BI__builtin_neon_vcvta_s64_v: case NEON::BI__builtin_neon_vcvta_u32_v: case NEON::BI__builtin_neon_vcvta_u64_v: + case NEON::BI__builtin_neon_vcvtaq_s16_v: case NEON::BI__builtin_neon_vcvtaq_s32_v: case NEON::BI__builtin_neon_vcvtaq_s64_v: + case NEON::BI__builtin_neon_vcvtaq_u16_v: case NEON::BI__builtin_neon_vcvtaq_u32_v: case NEON::BI__builtin_neon_vcvtaq_u64_v: + case NEON::BI__builtin_neon_vcvtn_s16_v: case NEON::BI__builtin_neon_vcvtn_s32_v: case NEON::BI__builtin_neon_vcvtn_s64_v: + case NEON::BI__builtin_neon_vcvtn_u16_v: case NEON::BI__builtin_neon_vcvtn_u32_v: case NEON::BI__builtin_neon_vcvtn_u64_v: + case NEON::BI__builtin_neon_vcvtnq_s16_v: case NEON::BI__builtin_neon_vcvtnq_s32_v: case NEON::BI__builtin_neon_vcvtnq_s64_v: + case NEON::BI__builtin_neon_vcvtnq_u16_v: case NEON::BI__builtin_neon_vcvtnq_u32_v: case NEON::BI__builtin_neon_vcvtnq_u64_v: + case NEON::BI__builtin_neon_vcvtp_s16_v: case NEON::BI__builtin_neon_vcvtp_s32_v: case NEON::BI__builtin_neon_vcvtp_s64_v: + case NEON::BI__builtin_neon_vcvtp_u16_v: case NEON::BI__builtin_neon_vcvtp_u32_v: case NEON::BI__builtin_neon_vcvtp_u64_v: + case NEON::BI__builtin_neon_vcvtpq_s16_v: case NEON::BI__builtin_neon_vcvtpq_s32_v: case NEON::BI__builtin_neon_vcvtpq_s64_v: + case NEON::BI__builtin_neon_vcvtpq_u16_v: case NEON::BI__builtin_neon_vcvtpq_u32_v: case NEON::BI__builtin_neon_vcvtpq_u64_v: + case NEON::BI__builtin_neon_vcvtm_s16_v: case NEON::BI__builtin_neon_vcvtm_s32_v: case NEON::BI__builtin_neon_vcvtm_s64_v: + case NEON::BI__builtin_neon_vcvtm_u16_v: case NEON::BI__builtin_neon_vcvtm_u32_v: case NEON::BI__builtin_neon_vcvtm_u64_v: + case NEON::BI__builtin_neon_vcvtmq_s16_v: case NEON::BI__builtin_neon_vcvtmq_s32_v: case NEON::BI__builtin_neon_vcvtmq_s64_v: + case NEON::BI__builtin_neon_vcvtmq_u16_v: case NEON::BI__builtin_neon_vcvtmq_u32_v: case NEON::BI__builtin_neon_vcvtmq_u64_v: { llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; @@ -6110,7 +6188,9 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, Ops[2] = EmitNeonSplat(Ops[2], cast(Ops[3])); return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); } + case NEON::BI__builtin_neon_vfmah_lane_f16: case NEON::BI__builtin_neon_vfmas_lane_f32: + case NEON::BI__builtin_neon_vfmah_laneq_f16: case NEON::BI__builtin_neon_vfmas_laneq_f32: case NEON::BI__builtin_neon_vfmad_lane_f64: case NEON::BI__builtin_neon_vfmad_laneq_f64: { @@ -6285,18 +6365,25 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, case NEON::BI__builtin_neon_vcvt_u32_v: case NEON::BI__builtin_neon_vcvt_s64_v: case NEON::BI__builtin_neon_vcvt_u64_v: + case NEON::BI__builtin_neon_vcvt_s16_v: + case NEON::BI__builtin_neon_vcvt_u16_v: case NEON::BI__builtin_neon_vcvtq_s32_v: case NEON::BI__builtin_neon_vcvtq_u32_v: case NEON::BI__builtin_neon_vcvtq_s64_v: - case NEON::BI__builtin_neon_vcvtq_u64_v: { + case NEON::BI__builtin_neon_vcvtq_u64_v: + case NEON::BI__builtin_neon_vcvtq_s16_v: + case NEON::BI__builtin_neon_vcvtq_u16_v: { Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); if (usgn) return Builder.CreateFPToUI(Ops[0], Ty); return Builder.CreateFPToSI(Ops[0], Ty); } + case NEON::BI__builtin_neon_vcvta_s16_v: case NEON::BI__builtin_neon_vcvta_s32_v: + case NEON::BI__builtin_neon_vcvtaq_s16_v: case NEON::BI__builtin_neon_vcvtaq_s32_v: case NEON::BI__builtin_neon_vcvta_u32_v: + case NEON::BI__builtin_neon_vcvtaq_u16_v: case NEON::BI__builtin_neon_vcvtaq_u32_v: case NEON::BI__builtin_neon_vcvta_s64_v: case NEON::BI__builtin_neon_vcvtaq_s64_v: @@ -6306,9 +6393,13 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvta"); } + case NEON::BI__builtin_neon_vcvtm_s16_v: case NEON::BI__builtin_neon_vcvtm_s32_v: + case NEON::BI__builtin_neon_vcvtmq_s16_v: case NEON::BI__builtin_neon_vcvtmq_s32_v: + case NEON::BI__builtin_neon_vcvtm_u16_v: case NEON::BI__builtin_neon_vcvtm_u32_v: + case NEON::BI__builtin_neon_vcvtmq_u16_v: case NEON::BI__builtin_neon_vcvtmq_u32_v: case NEON::BI__builtin_neon_vcvtm_s64_v: case NEON::BI__builtin_neon_vcvtmq_s64_v: @@ -6318,9 +6409,13 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtm"); } + case NEON::BI__builtin_neon_vcvtn_s16_v: case NEON::BI__builtin_neon_vcvtn_s32_v: + case NEON::BI__builtin_neon_vcvtnq_s16_v: case NEON::BI__builtin_neon_vcvtnq_s32_v: + case NEON::BI__builtin_neon_vcvtn_u16_v: case NEON::BI__builtin_neon_vcvtn_u32_v: + case NEON::BI__builtin_neon_vcvtnq_u16_v: case NEON::BI__builtin_neon_vcvtnq_u32_v: case NEON::BI__builtin_neon_vcvtn_s64_v: case NEON::BI__builtin_neon_vcvtnq_s64_v: @@ -6330,9 +6425,13 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtn"); } + case NEON::BI__builtin_neon_vcvtp_s16_v: case NEON::BI__builtin_neon_vcvtp_s32_v: + case NEON::BI__builtin_neon_vcvtpq_s16_v: case NEON::BI__builtin_neon_vcvtpq_s32_v: + case NEON::BI__builtin_neon_vcvtp_u16_v: case NEON::BI__builtin_neon_vcvtp_u32_v: + case NEON::BI__builtin_neon_vcvtpq_u16_v: case NEON::BI__builtin_neon_vcvtpq_u32_v: case NEON::BI__builtin_neon_vcvtp_s64_v: case NEON::BI__builtin_neon_vcvtpq_s64_v: @@ -6505,6 +6604,24 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); return Builder.CreateTrunc(Ops[0], Int16Ty); } + case NEON::BI__builtin_neon_vmaxv_f16: { + Int = Intrinsic::aarch64_neon_fmaxv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 4); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vmaxvq_f16: { + Int = Intrinsic::aarch64_neon_fmaxv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 8); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } case NEON::BI__builtin_neon_vminv_u8: { Int = Intrinsic::aarch64_neon_uminv; Ty = Int32Ty; @@ -6577,6 +6694,60 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); return Builder.CreateTrunc(Ops[0], Int16Ty); } + case NEON::BI__builtin_neon_vminv_f16: { + Int = Intrinsic::aarch64_neon_fminv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 4); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vminvq_f16: { + Int = Intrinsic::aarch64_neon_fminv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 8); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vmaxnmv_f16: { + Int = Intrinsic::aarch64_neon_fmaxnmv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 4); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxnmv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vmaxnmvq_f16: { + Int = Intrinsic::aarch64_neon_fmaxnmv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 8); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxnmv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vminnmv_f16: { + Int = Intrinsic::aarch64_neon_fminnmv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 4); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminnmv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } + case NEON::BI__builtin_neon_vminnmvq_f16: { + Int = Intrinsic::aarch64_neon_fminnmv; + Ty = HalfTy; + VTy = llvm::VectorType::get(HalfTy, 8); + llvm::Type *Tys[2] = { Ty, VTy }; + Ops.push_back(EmitScalarExpr(E->getArg(0))); + Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminnmv"); + return Builder.CreateTrunc(Ops[0], HalfTy); + } case NEON::BI__builtin_neon_vmul_n_f64: { Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); Value *RHS = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), DoubleTy); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 20d945fe50d3..5319ccec163f 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -98,6 +98,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, Int16Ty = llvm::Type::getInt16Ty(LLVMContext); Int32Ty = llvm::Type::getInt32Ty(LLVMContext); Int64Ty = llvm::Type::getInt64Ty(LLVMContext); + HalfTy = llvm::Type::getHalfTy(LLVMContext); FloatTy = llvm::Type::getFloatTy(LLVMContext); DoubleTy = llvm::Type::getDoubleTy(LLVMContext); PointerWidthInBits = C.getTargetInfo().getPointerWidth(0); diff --git a/lib/CodeGen/CodeGenTypeCache.h b/lib/CodeGen/CodeGenTypeCache.h index 450eab48a3b4..6910d36733dc 100644 --- a/lib/CodeGen/CodeGenTypeCache.h +++ b/lib/CodeGen/CodeGenTypeCache.h @@ -36,7 +36,7 @@ struct CodeGenTypeCache { /// i8, i16, i32, and i64 llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; /// float, double - llvm::Type *FloatTy, *DoubleTy; + llvm::Type *HalfTy, *FloatTy, *DoubleTy; /// int llvm::IntegerType *IntTy; diff --git a/test/CodeGen/aarch64-neon-intrinsics.c b/test/CodeGen/aarch64-neon-intrinsics.c index bcb680c4b518..cbc2e72fcbac 100644 --- a/test/CodeGen/aarch64-neon-intrinsics.c +++ b/test/CodeGen/aarch64-neon-intrinsics.c @@ -9037,10 +9037,9 @@ int64x2_t test_vld1q_s64(int64_t const *a) { // CHECK-LABEL: @test_vld1q_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>* -// CHECK: [[TMP2:%.*]] = load <8 x i16>, <8 x i16>* [[TMP1]] -// CHECK: [[TMP3:%.*]] = bitcast <8 x i16> [[TMP2]] to <8 x half> -// CHECK: ret <8 x half> [[TMP3]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>* +// CHECK: [[TMP2:%.*]] = load <8 x half>, <8 x half>* [[TMP1]] +// CHECK: ret <8 x half> [[TMP2]] float16x8_t test_vld1q_f16(float16_t const *a) { return vld1q_f16(a); } @@ -9152,10 +9151,9 @@ int64x1_t test_vld1_s64(int64_t const *a) { // CHECK-LABEL: @test_vld1_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i16>* -// CHECK: [[TMP2:%.*]] = load <4 x i16>, <4 x i16>* [[TMP1]] -// CHECK: [[TMP3:%.*]] = bitcast <4 x i16> [[TMP2]] to <4 x half> -// CHECK: ret <4 x half> [[TMP3]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x half>* +// CHECK: [[TMP2:%.*]] = load <4 x half>, <4 x half>* [[TMP1]] +// CHECK: ret <4 x half> [[TMP2]] float16x4_t test_vld1_f16(float16_t const *a) { return vld1_f16(a); } @@ -9342,10 +9340,10 @@ int64x2x2_t test_vld2q_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x2_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x i16>* -// CHECK: [[VLD2:%.*]] = call { <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld2.v8i16.p0v8i16(<8 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16> } [[VLD2]], { <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x half>* +// CHECK: [[VLD2:%.*]] = call { <8 x half>, <8 x half> } @llvm.aarch64.neon.ld2.v8f16.p0v8f16(<8 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half> } [[VLD2]], { <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 16, i1 false) @@ -9573,10 +9571,10 @@ int64x1x2_t test_vld2_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x2_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x i16>* -// CHECK: [[VLD2:%.*]] = call { <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld2.v4i16.p0v4i16(<4 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16> } [[VLD2]], { <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x half>* +// CHECK: [[VLD2:%.*]] = call { <4 x half>, <4 x half> } @llvm.aarch64.neon.ld2.v4f16.p0v4f16(<4 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half> } [[VLD2]], { <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 16, i32 8, i1 false) @@ -9804,10 +9802,10 @@ int64x2x3_t test_vld3q_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x3_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x i16>* -// CHECK: [[VLD3:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld3.v8i16.p0v8i16(<8 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16> } [[VLD3]], { <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x half>* +// CHECK: [[VLD3:%.*]] = call { <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld3.v8f16.p0v8f16(<8 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half> } [[VLD3]], { <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 48, i32 16, i1 false) @@ -10035,10 +10033,10 @@ int64x1x3_t test_vld3_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x3_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x i16>* -// CHECK: [[VLD3:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld3.v4i16.p0v4i16(<4 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16> } [[VLD3]], { <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x half>* +// CHECK: [[VLD3:%.*]] = call { <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld3.v4f16.p0v4f16(<4 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half> } [[VLD3]], { <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 24, i32 8, i1 false) @@ -10266,10 +10264,10 @@ int64x2x4_t test_vld4q_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x4_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x i16>* -// CHECK: [[VLD4:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld4.v8i16.p0v8i16(<8 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } [[VLD4]], { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <8 x half>* +// CHECK: [[VLD4:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld4.v8f16.p0v8f16(<8 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half>, <8 x half> } [[VLD4]], { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 64, i32 16, i1 false) @@ -10497,10 +10495,10 @@ int64x1x4_t test_vld4_s64(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x4_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x i16>* -// CHECK: [[VLD4:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld4.v4i16.p0v4i16(<4 x i16>* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } [[VLD4]], { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to <4 x half>* +// CHECK: [[VLD4:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld4.v4f16.p0v4f16(<4 x half>* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half>, <4 x half> } [[VLD4]], { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 8, i1 false) @@ -10666,9 +10664,9 @@ void test_vst1q_s64(int64_t *a, int64x2_t b) { // CHECK-LABEL: @test_vst1q_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP0]] to <8 x i16>* -// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: store <8 x i16> [[TMP3]], <8 x i16>* [[TMP2]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP0]] to <8 x half>* +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: store <8 x half> [[TMP3]], <8 x half>* [[TMP2]] // CHECK: ret void void test_vst1q_f16(float16_t *a, float16x8_t b) { vst1q_f16(a, b); @@ -10800,9 +10798,9 @@ void test_vst1_s64(int64_t *a, int64x1_t b) { // CHECK-LABEL: @test_vst1_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP0]] to <4 x i16>* -// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: store <4 x i16> [[TMP3]], <4 x i16>* [[TMP2]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP0]] to <4 x half>* +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: store <4 x half> [[TMP3]], <4 x half>* [[TMP2]] // CHECK: ret void void test_vst1_f16(float16_t *a, float16x4_t b) { vst1_f16(a, b); @@ -11056,9 +11054,9 @@ void test_vst2q_s64(int64_t *a, int64x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP6:%.*]] = bitcast <8 x half> [[TMP5]] to <16 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st2.v8i16.p0i8(<8 x i16> [[TMP7]], <8 x i16> [[TMP8]], i8* [[TMP2]]) +// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st2.v8f16.p0i8(<8 x half> [[TMP7]], <8 x half> [[TMP8]], i8* [[TMP2]]) // CHECK: ret void void test_vst2q_f16(float16_t *a, float16x8x2_t b) { vst2q_f16(a, b); @@ -11366,9 +11364,9 @@ void test_vst2_s64(int64_t *a, int64x1x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP6:%.*]] = bitcast <4 x half> [[TMP5]] to <8 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st2.v4i16.p0i8(<4 x i16> [[TMP7]], <4 x i16> [[TMP8]], i8* [[TMP2]]) +// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st2.v4f16.p0i8(<4 x half> [[TMP7]], <4 x half> [[TMP8]], i8* [[TMP2]]) // CHECK: ret void void test_vst2_f16(float16_t *a, float16x4x2_t b) { vst2_f16(a, b); @@ -11716,10 +11714,10 @@ void test_vst3q_s64(int64_t *a, int64x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP8:%.*]] = bitcast <8 x half> [[TMP7]] to <16 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st3.v8i16.p0i8(<8 x i16> [[TMP9]], <8 x i16> [[TMP10]], <8 x i16> [[TMP11]], i8* [[TMP2]]) +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st3.v8f16.p0i8(<8 x half> [[TMP9]], <8 x half> [[TMP10]], <8 x half> [[TMP11]], i8* [[TMP2]]) // CHECK: ret void void test_vst3q_f16(float16_t *a, float16x8x3_t b) { vst3q_f16(a, b); @@ -12085,10 +12083,10 @@ void test_vst3_s64(int64_t *a, int64x1x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP8:%.*]] = bitcast <4 x half> [[TMP7]] to <8 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st3.v4i16.p0i8(<4 x i16> [[TMP9]], <4 x i16> [[TMP10]], <4 x i16> [[TMP11]], i8* [[TMP2]]) +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st3.v4f16.p0i8(<4 x half> [[TMP9]], <4 x half> [[TMP10]], <4 x half> [[TMP11]], i8* [[TMP2]]) // CHECK: ret void void test_vst3_f16(float16_t *a, float16x4x3_t b) { vst3_f16(a, b); @@ -12494,11 +12492,11 @@ void test_vst4q_s64(int64_t *a, int64x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP10:%.*]] = bitcast <8 x half> [[TMP9]] to <16 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st4.v8i16.p0i8(<8 x i16> [[TMP11]], <8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], i8* [[TMP2]]) +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st4.v8f16.p0i8(<8 x half> [[TMP11]], <8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], i8* [[TMP2]]) // CHECK: ret void void test_vst4q_f16(float16_t *a, float16x8x4_t b) { vst4q_f16(a, b); @@ -12922,11 +12920,11 @@ void test_vst4_s64(int64_t *a, int64x1x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP10:%.*]] = bitcast <4 x half> [[TMP9]] to <8 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st4.v4i16.p0i8(<4 x i16> [[TMP11]], <4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], i8* [[TMP2]]) +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st4.v4f16.p0i8(<4 x half> [[TMP11]], <4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], i8* [[TMP2]]) // CHECK: ret void void test_vst4_f16(float16_t *a, float16x4x4_t b) { vst4_f16(a, b); @@ -13208,10 +13206,10 @@ int64x2x2_t test_vld1q_s64_x2(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x2_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld1x2.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16> } [[VLD1XN]], { <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <8 x half>, <8 x half> } @llvm.aarch64.neon.ld1x2.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half> } [[VLD1XN]], { <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 16, i1 false) @@ -13454,10 +13452,10 @@ int64x1x2_t test_vld1_s64_x2(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x2_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld1x2.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16> } [[VLD1XN]], { <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <4 x half>, <4 x half> } @llvm.aarch64.neon.ld1x2.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half> } [[VLD1XN]], { <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 16, i32 8, i1 false) @@ -13700,10 +13698,10 @@ int64x2x3_t test_vld1q_s64_x3(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x3_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld1x3.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16> } [[VLD1XN]], { <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld1x3.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half> } [[VLD1XN]], { <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 48, i32 16, i1 false) @@ -13946,10 +13944,10 @@ int64x1x3_t test_vld1_s64_x3(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x3_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld1x3.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16> } [[VLD1XN]], { <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld1x3.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half> } [[VLD1XN]], { <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 24, i32 8, i1 false) @@ -14192,10 +14190,10 @@ int64x2x4_t test_vld1q_s64_x4(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x4_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld1x4.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } [[VLD1XN]], { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld1x4.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half>, <8 x half> } [[VLD1XN]], { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 64, i32 16, i1 false) @@ -14438,10 +14436,10 @@ int64x1x4_t test_vld1_s64_x4(int64_t const *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x4_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD1XN:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld1x4.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } [[VLD1XN]], { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD1XN:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld1x4.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half>, <4 x half> } [[VLD1XN]], { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 8, i1 false) @@ -14752,10 +14750,10 @@ void test_vst1q_s64_x2(int64_t *a, int64x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP6:%.*]] = bitcast <8 x half> [[TMP5]] to <16 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP9:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x2.v8i16.p0i16(<8 x i16> [[TMP7]], <8 x i16> [[TMP8]], i16* [[TMP9]]) +// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP9:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x2.v8f16.p0f16(<8 x half> [[TMP7]], <8 x half> [[TMP8]], half* [[TMP9]]) // CHECK: ret void void test_vst1q_f16_x2(float16_t *a, float16x8x2_t b) { vst1q_f16_x2(a, b); @@ -15098,10 +15096,10 @@ void test_vst1_s64_x2(int64_t *a, int64x1x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP6:%.*]] = bitcast <4 x half> [[TMP5]] to <8 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP9:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x2.v4i16.p0i16(<4 x i16> [[TMP7]], <4 x i16> [[TMP8]], i16* [[TMP9]]) +// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP9:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x2.v4f16.p0f16(<4 x half> [[TMP7]], <4 x half> [[TMP8]], half* [[TMP9]]) // CHECK: ret void void test_vst1_f16_x2(float16_t *a, float16x4x2_t b) { vst1_f16_x2(a, b); @@ -15484,11 +15482,11 @@ void test_vst1q_s64_x3(int64_t *a, int64x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP8:%.*]] = bitcast <8 x half> [[TMP7]] to <16 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x3.v8i16.p0i16(<8 x i16> [[TMP9]], <8 x i16> [[TMP10]], <8 x i16> [[TMP11]], i16* [[TMP12]]) +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x3.v8f16.p0f16(<8 x half> [[TMP9]], <8 x half> [[TMP10]], <8 x half> [[TMP11]], half* [[TMP12]]) // CHECK: ret void void test_vst1q_f16_x3(float16_t *a, float16x8x3_t b) { vst1q_f16_x3(a, b); @@ -15894,11 +15892,11 @@ void test_vst1_s64_x3(int64_t *a, int64x1x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP8:%.*]] = bitcast <4 x half> [[TMP7]] to <8 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x3.v4i16.p0i16(<4 x i16> [[TMP9]], <4 x i16> [[TMP10]], <4 x i16> [[TMP11]], i16* [[TMP12]]) +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x3.v4f16.p0f16(<4 x half> [[TMP9]], <4 x half> [[TMP10]], <4 x half> [[TMP11]], half* [[TMP12]]) // CHECK: ret void void test_vst1_f16_x3(float16_t *a, float16x4x3_t b) { vst1_f16_x3(a, b); @@ -16344,12 +16342,12 @@ void test_vst1q_s64_x4(int64_t *a, int64x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP10:%.*]] = bitcast <8 x half> [[TMP9]] to <16 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x i16> -// CHECK: [[TMP15:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x4.v8i16.p0i16(<8 x i16> [[TMP11]], <8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], i16* [[TMP15]]) +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x half> +// CHECK: [[TMP15:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x4.v8f16.p0f16(<8 x half> [[TMP11]], <8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], half* [[TMP15]]) // CHECK: ret void void test_vst1q_f16_x4(float16_t *a, float16x8x4_t b) { vst1q_f16_x4(a, b); @@ -16818,12 +16816,12 @@ void test_vst1_s64_x4(int64_t *a, int64x1x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP10:%.*]] = bitcast <4 x half> [[TMP9]] to <8 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x i16> -// CHECK: [[TMP15:%.*]] = bitcast i8* [[TMP2]] to i16* -// CHECK: call void @llvm.aarch64.neon.st1x4.v4i16.p0i16(<4 x i16> [[TMP11]], <4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], i16* [[TMP15]]) +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x half> +// CHECK: [[TMP15:%.*]] = bitcast i8* [[TMP2]] to half* +// CHECK: call void @llvm.aarch64.neon.st1x4.v4f16.p0f16(<4 x half> [[TMP11]], <4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], half* [[TMP15]]) // CHECK: ret void void test_vst1_f16_x4(float16_t *a, float16x4x4_t b) { vst1_f16_x4(a, b); diff --git a/test/CodeGen/aarch64-neon-ldst-one.c b/test/CodeGen/aarch64-neon-ldst-one.c index 9bd9ab1cb61b..a3c5b140a0d2 100644 --- a/test/CodeGen/aarch64-neon-ldst-one.c +++ b/test/CodeGen/aarch64-neon-ldst-one.c @@ -90,12 +90,11 @@ int64x2_t test_vld1q_dup_s64(int64_t *a) { // CHECK-LABEL: define <8 x half> @test_vld1q_dup_f16(half* %a) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP2:%.*]] = load i16, i16* [[TMP1]] -// CHECK: [[TMP3:%.*]] = insertelement <8 x i16> undef, i16 [[TMP2]], i32 0 -// CHECK: [[LANE:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> [[TMP3]], <8 x i32> zeroinitializer -// CHECK: [[TMP4:%.*]] = bitcast <8 x i16> [[LANE]] to <8 x half> -// CHECK: ret <8 x half> [[TMP4]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP2:%.*]] = load half, half* [[TMP1]] +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> undef, half [[TMP2]], i32 0 +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP3]], <8 x half> [[TMP3]], <8 x i32> zeroinitializer +// CHECK: ret <8 x half> [[LANE]] float16x8_t test_vld1q_dup_f16(float16_t *a) { return vld1q_dup_f16(a); } @@ -239,12 +238,11 @@ int64x1_t test_vld1_dup_s64(int64_t *a) { // CHECK-LABEL: define <4 x half> @test_vld1_dup_f16(half* %a) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP2:%.*]] = load i16, i16* [[TMP1]] -// CHECK: [[TMP3:%.*]] = insertelement <4 x i16> undef, i16 [[TMP2]], i32 0 -// CHECK: [[LANE:%.*]] = shufflevector <4 x i16> [[TMP3]], <4 x i16> [[TMP3]], <4 x i32> zeroinitializer -// CHECK: [[TMP4:%.*]] = bitcast <4 x i16> [[LANE]] to <4 x half> -// CHECK: ret <4 x half> [[TMP4]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP2:%.*]] = load half, half* [[TMP1]] +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> undef, half [[TMP2]], i32 0 +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <4 x i32> zeroinitializer +// CHECK: ret <4 x half> [[LANE]] float16x4_t test_vld1_dup_f16(float16_t *a) { return vld1_dup_f16(a); } @@ -447,10 +445,10 @@ int64x2x2_t test_vld2q_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x2_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD2:%.*]] = call { <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld2r.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16> } [[VLD2]], { <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD2:%.*]] = call { <8 x half>, <8 x half> } @llvm.aarch64.neon.ld2r.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half> } [[VLD2]], { <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 16, i1 false) @@ -693,10 +691,10 @@ int64x1x2_t test_vld2_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x2_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD2:%.*]] = call { <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld2r.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16> } [[VLD2]], { <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD2:%.*]] = call { <4 x half>, <4 x half> } @llvm.aarch64.neon.ld2r.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half> } [[VLD2]], { <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 16, i32 8, i1 false) @@ -947,10 +945,10 @@ int64x2x3_t test_vld3q_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x3_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD3:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld3r.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16> } [[VLD3]], { <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD3:%.*]] = call { <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld3r.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half> } [[VLD3]], { <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 48, i32 16, i1 false) @@ -1207,10 +1205,10 @@ int64x1x3_t test_vld3_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x3_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD3:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld3r.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16> } [[VLD3]], { <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD3:%.*]] = call { <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld3r.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half> } [[VLD3]], { <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x3_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 24, i32 8, i1 false) @@ -1459,10 +1457,10 @@ int64x2x4_t test_vld4q_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x4_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD4:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld4r.v8i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } [[VLD4]], { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD4:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld4r.v8f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half>, <8 x half> } [[VLD4]], { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x8x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 64, i32 16, i1 false) @@ -1705,10 +1703,10 @@ int64x1x4_t test_vld4_dup_s64(int64_t *a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x4_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i16* -// CHECK: [[VLD4:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld4r.v4i16.p0i16(i16* [[TMP2]]) -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } [[VLD4]], { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP3]] +// CHECK: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to half* +// CHECK: [[VLD4:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld4r.v4f16.p0f16(half* [[TMP2]]) +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half>, <4 x half> } [[VLD4]], { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* [[TMP3]] // CHECK: [[TMP4:%.*]] = bitcast %struct.float16x4x4_t* [[RETVAL]] to i8* // CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP4]], i8* [[TMP5]], i64 32, i32 8, i1 false) @@ -1897,12 +1895,11 @@ int64x2_t test_vld1q_lane_s64(int64_t *a, int64x2_t b) { // CHECK-LABEL: define <8 x half> @test_vld1q_lane_f16(half* %a, <8 x half> %b) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP4:%.*]] = load i16, i16* [[TMP3]] -// CHECK: [[VLD1_LANE:%.*]] = insertelement <8 x i16> [[TMP2]], i16 [[TMP4]], i32 7 -// CHECK: [[TMP5:%.*]] = bitcast <8 x i16> [[VLD1_LANE]] to <8 x half> -// CHECK: ret <8 x half> [[TMP5]] +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP4:%.*]] = load half, half* [[TMP3]] +// CHECK: [[VLD1_LANE:%.*]] = insertelement <8 x half> [[TMP2]], half [[TMP4]], i32 7 +// CHECK: ret <8 x half> [[VLD1_LANE]] float16x8_t test_vld1q_lane_f16(float16_t *a, float16x8_t b) { return vld1q_lane_f16(a, b, 7); } @@ -2054,12 +2051,11 @@ int64x1_t test_vld1_lane_s64(int64_t *a, int64x1_t b) { // CHECK-LABEL: define <4 x half> @test_vld1_lane_f16(half* %a, <4 x half> %b) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP4:%.*]] = load i16, i16* [[TMP3]] -// CHECK: [[VLD1_LANE:%.*]] = insertelement <4 x i16> [[TMP2]], i16 [[TMP4]], i32 3 -// CHECK: [[TMP5:%.*]] = bitcast <4 x i16> [[VLD1_LANE]] to <4 x half> -// CHECK: ret <4 x half> [[TMP5]] +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP4:%.*]] = load half, half* [[TMP3]] +// CHECK: [[VLD1_LANE:%.*]] = insertelement <4 x half> [[TMP2]], half [[TMP4]], i32 3 +// CHECK: ret <4 x half> [[VLD1_LANE]] float16x4_t test_vld1_lane_f16(float16_t *a, float16x4_t b) { return vld1_lane_f16(a, b, 3); } @@ -2495,11 +2491,11 @@ int64x2x2_t test_vld2q_lane_s64(int64_t *a, int64x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP6:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP7:%.*]] = bitcast <8 x half> [[TMP6]] to <16 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[VLD2_LANE:%.*]] = call { <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld2lane.v8i16.p0i8(<8 x i16> [[TMP8]], <8 x i16> [[TMP9]], i64 7, i8* [[TMP3]]) -// CHECK: [[TMP10:%.*]] = bitcast i8* [[TMP2]] to { <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16> } [[VLD2_LANE]], { <8 x i16>, <8 x i16> }* [[TMP10]] +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[VLD2_LANE:%.*]] = call { <8 x half>, <8 x half> } @llvm.aarch64.neon.ld2lane.v8f16.p0i8(<8 x half> [[TMP8]], <8 x half> [[TMP9]], i64 7, i8* [[TMP3]]) +// CHECK: [[TMP10:%.*]] = bitcast i8* [[TMP2]] to { <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half> } [[VLD2_LANE]], { <8 x half>, <8 x half> }* [[TMP10]] // CHECK: [[TMP11:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* // CHECK: [[TMP12:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP11]], i8* [[TMP12]], i64 32, i32 16, i1 false) @@ -2927,11 +2923,11 @@ int64x1x2_t test_vld2_lane_s64(int64_t *a, int64x1x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP6:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP7:%.*]] = bitcast <4 x half> [[TMP6]] to <8 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[VLD2_LANE:%.*]] = call { <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld2lane.v4i16.p0i8(<4 x i16> [[TMP8]], <4 x i16> [[TMP9]], i64 3, i8* [[TMP3]]) -// CHECK: [[TMP10:%.*]] = bitcast i8* [[TMP2]] to { <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16> } [[VLD2_LANE]], { <4 x i16>, <4 x i16> }* [[TMP10]] +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[VLD2_LANE:%.*]] = call { <4 x half>, <4 x half> } @llvm.aarch64.neon.ld2lane.v4f16.p0i8(<4 x half> [[TMP8]], <4 x half> [[TMP9]], i64 3, i8* [[TMP3]]) +// CHECK: [[TMP10:%.*]] = bitcast i8* [[TMP2]] to { <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half> } [[VLD2_LANE]], { <4 x half>, <4 x half> }* [[TMP10]] // CHECK: [[TMP11:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* // CHECK: [[TMP12:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP11]], i8* [[TMP12]], i64 16, i32 8, i1 false) @@ -3364,12 +3360,12 @@ int64x2x3_t test_vld3q_lane_s64(int64_t *a, int64x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP8:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP9:%.*]] = bitcast <8 x half> [[TMP8]] to <16 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: [[VLD3_LANE:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld3lane.v8i16.p0i8(<8 x i16> [[TMP10]], <8 x i16> [[TMP11]], <8 x i16> [[TMP12]], i64 7, i8* [[TMP3]]) -// CHECK: [[TMP13:%.*]] = bitcast i8* [[TMP2]] to { <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16> } [[VLD3_LANE]], { <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP13]] +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: [[VLD3_LANE:%.*]] = call { <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld3lane.v8f16.p0i8(<8 x half> [[TMP10]], <8 x half> [[TMP11]], <8 x half> [[TMP12]], i64 7, i8* [[TMP3]]) +// CHECK: [[TMP13:%.*]] = bitcast i8* [[TMP2]] to { <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half> } [[VLD3_LANE]], { <8 x half>, <8 x half>, <8 x half> }* [[TMP13]] // CHECK: [[TMP14:%.*]] = bitcast %struct.float16x8x3_t* [[RETVAL]] to i8* // CHECK: [[TMP15:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP14]], i8* [[TMP15]], i64 48, i32 16, i1 false) @@ -3889,12 +3885,12 @@ int64x1x3_t test_vld3_lane_s64(int64_t *a, int64x1x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP8:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP9:%.*]] = bitcast <4 x half> [[TMP8]] to <8 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: [[VLD3_LANE:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld3lane.v4i16.p0i8(<4 x i16> [[TMP10]], <4 x i16> [[TMP11]], <4 x i16> [[TMP12]], i64 3, i8* [[TMP3]]) -// CHECK: [[TMP13:%.*]] = bitcast i8* [[TMP2]] to { <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16> } [[VLD3_LANE]], { <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP13]] +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: [[VLD3_LANE:%.*]] = call { <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld3lane.v4f16.p0i8(<4 x half> [[TMP10]], <4 x half> [[TMP11]], <4 x half> [[TMP12]], i64 3, i8* [[TMP3]]) +// CHECK: [[TMP13:%.*]] = bitcast i8* [[TMP2]] to { <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half> } [[VLD3_LANE]], { <4 x half>, <4 x half>, <4 x half> }* [[TMP13]] // CHECK: [[TMP14:%.*]] = bitcast %struct.float16x4x3_t* [[RETVAL]] to i8* // CHECK: [[TMP15:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP14]], i8* [[TMP15]], i64 24, i32 8, i1 false) @@ -4454,13 +4450,13 @@ int64x2x4_t test_vld4q_lane_s64(int64_t *a, int64x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP10:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP11:%.*]] = bitcast <8 x half> [[TMP10]] to <16 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x i16> -// CHECK: [[VLD4_LANE:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } @llvm.aarch64.neon.ld4lane.v8i16.p0i8(<8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], <8 x i16> [[TMP15]], i64 7, i8* [[TMP3]]) -// CHECK: [[TMP16:%.*]] = bitcast i8* [[TMP2]] to { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* -// CHECK: store { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } [[VLD4_LANE]], { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> }* [[TMP16]] +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x half> +// CHECK: [[VLD4_LANE:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> } @llvm.aarch64.neon.ld4lane.v8f16.p0i8(<8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], <8 x half> [[TMP15]], i64 7, i8* [[TMP3]]) +// CHECK: [[TMP16:%.*]] = bitcast i8* [[TMP2]] to { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* +// CHECK: store { <8 x half>, <8 x half>, <8 x half>, <8 x half> } [[VLD4_LANE]], { <8 x half>, <8 x half>, <8 x half>, <8 x half> }* [[TMP16]] // CHECK: [[TMP17:%.*]] = bitcast %struct.float16x8x4_t* [[RETVAL]] to i8* // CHECK: [[TMP18:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP17]], i8* [[TMP18]], i64 64, i32 16, i1 false) @@ -5043,13 +5039,13 @@ int64x1x4_t test_vld4_lane_s64(int64_t *a, int64x1x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP10:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP11:%.*]] = bitcast <4 x half> [[TMP10]] to <8 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x i16> -// CHECK: [[VLD4_LANE:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } @llvm.aarch64.neon.ld4lane.v4i16.p0i8(<4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], <4 x i16> [[TMP15]], i64 3, i8* [[TMP3]]) -// CHECK: [[TMP16:%.*]] = bitcast i8* [[TMP2]] to { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* -// CHECK: store { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> } [[VLD4_LANE]], { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> }* [[TMP16]] +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x half> +// CHECK: [[VLD4_LANE:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> } @llvm.aarch64.neon.ld4lane.v4f16.p0i8(<4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], <4 x half> [[TMP15]], i64 3, i8* [[TMP3]]) +// CHECK: [[TMP16:%.*]] = bitcast i8* [[TMP2]] to { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* +// CHECK: store { <4 x half>, <4 x half>, <4 x half>, <4 x half> } [[VLD4_LANE]], { <4 x half>, <4 x half>, <4 x half>, <4 x half> }* [[TMP16]] // CHECK: [[TMP17:%.*]] = bitcast %struct.float16x4x4_t* [[RETVAL]] to i8* // CHECK: [[TMP18:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP17]], i8* [[TMP18]], i64 32, i32 8, i1 false) @@ -5361,10 +5357,10 @@ void test_vst1q_lane_s64(int64_t *a, int64x2_t b) { // CHECK-LABEL: define void @test_vst1q_lane_f16(half* %a, <8 x half> %b) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: [[TMP3:%.*]] = extractelement <8 x i16> [[TMP2]], i32 7 -// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: store i16 [[TMP3]], i16* [[TMP4]] +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP3:%.*]] = extractelement <8 x half> [[TMP2]], i32 7 +// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: store half [[TMP3]], half* [[TMP4]] // CHECK: ret void void test_vst1q_lane_f16(float16_t *a, float16x8_t b) { vst1q_lane_f16(a, b, 7); @@ -5517,10 +5513,10 @@ void test_vst1_lane_s64(int64_t *a, int64x1_t b) { // CHECK-LABEL: define void @test_vst1_lane_f16(half* %a, <4 x half> %b) #0 { // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: [[TMP3:%.*]] = extractelement <4 x i16> [[TMP2]], i32 3 -// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: store i16 [[TMP3]], i16* [[TMP4]] +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP3:%.*]] = extractelement <4 x half> [[TMP2]], i32 3 +// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: store half [[TMP3]], half* [[TMP4]] // CHECK: ret void void test_vst1_lane_f16(float16_t *a, float16x4_t b) { vst1_lane_f16(a, b, 3); @@ -5789,9 +5785,9 @@ void test_vst2q_lane_s64(int64_t *a, int64x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP6:%.*]] = bitcast <8 x half> [[TMP5]] to <16 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st2lane.v8i16.p0i8(<8 x i16> [[TMP7]], <8 x i16> [[TMP8]], i64 7, i8* [[TMP2]]) +// CHECK: [[TMP7:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st2lane.v8f16.p0i8(<8 x half> [[TMP7]], <8 x half> [[TMP8]], i64 7, i8* [[TMP2]]) // CHECK: ret void void test_vst2q_lane_f16(float16_t *a, float16x8x2_t b) { vst2q_lane_f16(a, b, 7); @@ -6124,9 +6120,9 @@ void test_vst2_lane_s64(int64_t *a, int64x1x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i64 0, i64 1 // CHECK: [[TMP5:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP6:%.*]] = bitcast <4 x half> [[TMP5]] to <8 x i8> -// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st2lane.v4i16.p0i8(<4 x i16> [[TMP7]], <4 x i16> [[TMP8]], i64 3, i8* [[TMP2]]) +// CHECK: [[TMP7:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st2lane.v4f16.p0i8(<4 x half> [[TMP7]], <4 x half> [[TMP8]], i64 3, i8* [[TMP2]]) // CHECK: ret void void test_vst2_lane_f16(float16_t *a, float16x4x2_t b) { vst2_lane_f16(a, b, 3); @@ -6499,10 +6495,10 @@ void test_vst3q_lane_s64(int64_t *a, int64x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP8:%.*]] = bitcast <8 x half> [[TMP7]] to <16 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st3lane.v8i16.p0i8(<8 x i16> [[TMP9]], <8 x i16> [[TMP10]], <8 x i16> [[TMP11]], i64 7, i8* [[TMP2]]) +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st3lane.v8f16.p0i8(<8 x half> [[TMP9]], <8 x half> [[TMP10]], <8 x half> [[TMP11]], i64 7, i8* [[TMP2]]) // CHECK: ret void void test_vst3q_lane_f16(float16_t *a, float16x8x3_t b) { vst3q_lane_f16(a, b, 7); @@ -6898,10 +6894,10 @@ void test_vst3_lane_s64(int64_t *a, int64x1x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i64 0, i64 2 // CHECK: [[TMP7:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP8:%.*]] = bitcast <4 x half> [[TMP7]] to <8 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st3lane.v4i16.p0i8(<4 x i16> [[TMP9]], <4 x i16> [[TMP10]], <4 x i16> [[TMP11]], i64 3, i8* [[TMP2]]) +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st3lane.v4f16.p0i8(<4 x half> [[TMP9]], <4 x half> [[TMP10]], <4 x half> [[TMP11]], i64 3, i8* [[TMP2]]) // CHECK: ret void void test_vst3_lane_f16(float16_t *a, float16x4x3_t b) { vst3_lane_f16(a, b, 3); @@ -7337,11 +7333,11 @@ void test_vst4q_lane_s64(int64_t *a, int64x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP10:%.*]] = bitcast <8 x half> [[TMP9]] to <16 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x i16> -// CHECK: call void @llvm.aarch64.neon.st4lane.v8i16.p0i8(<8 x i16> [[TMP11]], <8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], i64 7, i8* [[TMP2]]) +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP4]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x half> +// CHECK: call void @llvm.aarch64.neon.st4lane.v8f16.p0i8(<8 x half> [[TMP11]], <8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], i64 7, i8* [[TMP2]]) // CHECK: ret void void test_vst4q_lane_f16(float16_t *a, float16x8x4_t b) { vst4q_lane_f16(a, b, 7); @@ -7800,11 +7796,11 @@ void test_vst4_lane_s64(int64_t *a, int64x1x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i64 0, i64 3 // CHECK: [[TMP9:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP10:%.*]] = bitcast <4 x half> [[TMP9]] to <8 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x i16> -// CHECK: call void @llvm.aarch64.neon.st4lane.v4i16.p0i8(<4 x i16> [[TMP11]], <4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], i64 3, i8* [[TMP2]]) +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP4]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x half> +// CHECK: call void @llvm.aarch64.neon.st4lane.v4f16.p0i8(<4 x half> [[TMP11]], <4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], i64 3, i8* [[TMP2]]) // CHECK: ret void void test_vst4_lane_f16(float16_t *a, float16x4x4_t b) { vst4_lane_f16(a, b, 3); diff --git a/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c b/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c new file mode 100644 index 000000000000..3f61238b64fb --- /dev/null +++ b/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c @@ -0,0 +1,1633 @@ +// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon -target-feature +fullfp16 -target-feature +v8.2a\ +// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -emit-llvm -o - %s \ +// RUN: | opt -S -mem2reg \ +// RUN: | FileCheck %s + +// REQUIRES: aarch64-registered-target + +#include + +// CHECK-LABEL: test_vabs_f16 +// CHECK: [[ABS:%.*]] = call <4 x half> @llvm.fabs.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[ABS]] +float16x4_t test_vabs_f16(float16x4_t a) { + return vabs_f16(a); +} + +// CHECK-LABEL: test_vabsq_f16 +// CHECK: [[ABS:%.*]] = call <8 x half> @llvm.fabs.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[ABS]] +float16x8_t test_vabsq_f16(float16x8_t a) { + return vabsq_f16(a); +} + +// CHECK-LABEL: test_vceqz_f16 +// CHECK: [[TMP1:%.*]] = fcmp oeq <4 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vceqz_f16(float16x4_t a) { + return vceqz_f16(a); +} + +// CHECK-LABEL: test_vceqzq_f16 +// CHECK: [[TMP1:%.*]] = fcmp oeq <8 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vceqzq_f16(float16x8_t a) { + return vceqzq_f16(a); +} + +// CHECK-LABEL: test_vcgez_f16 +// CHECK: [[TMP1:%.*]] = fcmp oge <4 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcgez_f16(float16x4_t a) { + return vcgez_f16(a); +} + +// CHECK-LABEL: test_vcgezq_f16 +// CHECK: [[TMP1:%.*]] = fcmp oge <8 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcgezq_f16(float16x8_t a) { + return vcgezq_f16(a); +} + +// CHECK-LABEL: test_vcgtz_f16 +// CHECK: [[TMP1:%.*]] = fcmp ogt <4 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcgtz_f16(float16x4_t a) { + return vcgtz_f16(a); +} + +// CHECK-LABEL: test_vcgtzq_f16 +// CHECK: [[TMP1:%.*]] = fcmp ogt <8 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcgtzq_f16(float16x8_t a) { + return vcgtzq_f16(a); +} + +// CHECK-LABEL: test_vclez_f16 +// CHECK: [[TMP1:%.*]] = fcmp ole <4 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vclez_f16(float16x4_t a) { + return vclez_f16(a); +} + +// CHECK-LABEL: test_vclezq_f16 +// CHECK: [[TMP1:%.*]] = fcmp ole <8 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vclezq_f16(float16x8_t a) { + return vclezq_f16(a); +} + +// CHECK-LABEL: test_vcltz_f16 +// CHECK: [[TMP1:%.*]] = fcmp olt <4 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcltz_f16(float16x4_t a) { + return vcltz_f16(a); +} + +// CHECK-LABEL: test_vcltzq_f16 +// CHECK: [[TMP1:%.*]] = fcmp olt <8 x half> %a, zeroinitializer +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcltzq_f16(float16x8_t a) { + return vcltzq_f16(a); +} + +// CHECK-LABEL: test_vcvt_f16_s16 +// CHECK: [[VCVT:%.*]] = sitofp <4 x i16> %a to <4 x half> +// CHECK: ret <4 x half> [[VCVT]] +float16x4_t test_vcvt_f16_s16 (int16x4_t a) { + return vcvt_f16_s16(a); +} + +// CHECK-LABEL: test_vcvtq_f16_s16 +// CHECK: [[VCVT:%.*]] = sitofp <8 x i16> %a to <8 x half> +// CHECK: ret <8 x half> [[VCVT]] +float16x8_t test_vcvtq_f16_s16 (int16x8_t a) { + return vcvtq_f16_s16(a); +} + +// CHECK-LABEL: test_vcvt_f16_u16 +// CHECK: [[VCVT:%.*]] = uitofp <4 x i16> %a to <4 x half> +// CHECK: ret <4 x half> [[VCVT]] +float16x4_t test_vcvt_f16_u16 (uint16x4_t a) { + return vcvt_f16_u16(a); +} + +// CHECK-LABEL: test_vcvtq_f16_u16 +// CHECK: [[VCVT:%.*]] = uitofp <8 x i16> %a to <8 x half> +// CHECK: ret <8 x half> [[VCVT]] +float16x8_t test_vcvtq_f16_u16 (uint16x8_t a) { + return vcvtq_f16_u16(a); +} + +// CHECK-LABEL: test_vcvt_s16_f16 +// CHECK: [[VCVT:%.*]] = fptosi <4 x half> %a to <4 x i16> +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvt_s16_f16 (float16x4_t a) { + return vcvt_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtq_s16_f16 +// CHECK: [[VCVT:%.*]] = fptosi <8 x half> %a to <8 x i16> +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtq_s16_f16 (float16x8_t a) { + return vcvtq_s16_f16(a); +} + +// CHECK-LABEL: test_vcvt_u16_f16 +// CHECK: [[VCVT:%.*]] = fptoui <4 x half> %a to <4 x i16> +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvt_u16_f16 (float16x4_t a) { + return vcvt_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtq_u16_f16 +// CHECK: [[VCVT:%.*]] = fptoui <8 x half> %a to <8 x i16> +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtq_u16_f16 (float16x8_t a) { + return vcvtq_u16_f16(a); +} + +// CHECK-LABEL: test_vcvta_s16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtas.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvta_s16_f16 (float16x4_t a) { + return vcvta_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtaq_s16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtas.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtaq_s16_f16 (float16x8_t a) { + return vcvtaq_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtm_s16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtms.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvtm_s16_f16 (float16x4_t a) { + return vcvtm_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtmq_s16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtms.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtmq_s16_f16 (float16x8_t a) { + return vcvtmq_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtm_u16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtmu.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +uint16x4_t test_vcvtm_u16_f16 (float16x4_t a) { + return vcvtm_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtmq_u16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtmu.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +uint16x8_t test_vcvtmq_u16_f16 (float16x8_t a) { + return vcvtmq_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtn_s16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtns.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvtn_s16_f16 (float16x4_t a) { + return vcvtn_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtnq_s16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtns.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtnq_s16_f16 (float16x8_t a) { + return vcvtnq_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtn_u16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtnu.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +uint16x4_t test_vcvtn_u16_f16 (float16x4_t a) { + return vcvtn_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtnq_u16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtnu.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +uint16x8_t test_vcvtnq_u16_f16 (float16x8_t a) { + return vcvtnq_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtp_s16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtps.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +int16x4_t test_vcvtp_s16_f16 (float16x4_t a) { + return vcvtp_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtpq_s16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtps.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +int16x8_t test_vcvtpq_s16_f16 (float16x8_t a) { + return vcvtpq_s16_f16(a); +} + +// CHECK-LABEL: test_vcvtp_u16_f16 +// CHECK: [[VCVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.fcvtpu.v4i16.v4f16(<4 x half> %a) +// CHECK: ret <4 x i16> [[VCVT]] +uint16x4_t test_vcvtp_u16_f16 (float16x4_t a) { + return vcvtp_u16_f16(a); +} + +// CHECK-LABEL: test_vcvtpq_u16_f16 +// CHECK: [[VCVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.fcvtpu.v8i16.v8f16(<8 x half> %a) +// CHECK: ret <8 x i16> [[VCVT]] +uint16x8_t test_vcvtpq_u16_f16 (float16x8_t a) { + return vcvtpq_u16_f16(a); +} + +// FIXME: Fix the zero constant when fp16 non-storage-only type becomes available. +// CHECK-LABEL: test_vneg_f16 +// CHECK: [[NEG:%.*]] = fsub <4 x half> , %a +// CHECK: ret <4 x half> [[NEG]] +float16x4_t test_vneg_f16(float16x4_t a) { + return vneg_f16(a); +} + +// CHECK-LABEL: test_vnegq_f16 +// CHECK: [[NEG:%.*]] = fsub <8 x half> , %a +// CHECK: ret <8 x half> [[NEG]] +float16x8_t test_vnegq_f16(float16x8_t a) { + return vnegq_f16(a); +} + +// CHECK-LABEL: test_vrecpe_f16 +// CHECK: [[RCP:%.*]] = call <4 x half> @llvm.aarch64.neon.frecpe.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RCP]] +float16x4_t test_vrecpe_f16(float16x4_t a) { + return vrecpe_f16(a); +} + +// CHECK-LABEL: test_vrecpeq_f16 +// CHECK: [[RCP:%.*]] = call <8 x half> @llvm.aarch64.neon.frecpe.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RCP]] +float16x8_t test_vrecpeq_f16(float16x8_t a) { + return vrecpeq_f16(a); +} + +// CHECK-LABEL: test_vrnd_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.trunc.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrnd_f16(float16x4_t a) { + return vrnd_f16(a); +} + +// CHECK-LABEL: test_vrndq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.trunc.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndq_f16(float16x8_t a) { + return vrndq_f16(a); +} + +// CHECK-LABEL: test_vrnda_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.round.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrnda_f16(float16x4_t a) { + return vrnda_f16(a); +} + +// CHECK-LABEL: test_vrndaq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.round.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndaq_f16(float16x8_t a) { + return vrndaq_f16(a); +} + +// CHECK-LABEL: test_vrndi_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.nearbyint.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrndi_f16(float16x4_t a) { + return vrndi_f16(a); +} + +// CHECK-LABEL: test_vrndiq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.nearbyint.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndiq_f16(float16x8_t a) { + return vrndiq_f16(a); +} + +// CHECK-LABEL: test_vrndm_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.floor.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrndm_f16(float16x4_t a) { + return vrndm_f16(a); +} + +// CHECK-LABEL: test_vrndmq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.floor.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndmq_f16(float16x8_t a) { + return vrndmq_f16(a); +} + +// CHECK-LABEL: test_vrndn_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.aarch64.neon.frintn.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrndn_f16(float16x4_t a) { + return vrndn_f16(a); +} + +// CHECK-LABEL: test_vrndnq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.aarch64.neon.frintn.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndnq_f16(float16x8_t a) { + return vrndnq_f16(a); +} + +// CHECK-LABEL: test_vrndp_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.ceil.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrndp_f16(float16x4_t a) { + return vrndp_f16(a); +} + +// CHECK-LABEL: test_vrndpq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.ceil.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndpq_f16(float16x8_t a) { + return vrndpq_f16(a); +} + +// CHECK-LABEL: test_vrndx_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.rint.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrndx_f16(float16x4_t a) { + return vrndx_f16(a); +} + +// CHECK-LABEL: test_vrndxq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.rint.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrndxq_f16(float16x8_t a) { + return vrndxq_f16(a); +} + +// CHECK-LABEL: test_vrsqrte_f16 +// CHECK: [[RND:%.*]] = call <4 x half> @llvm.aarch64.neon.frsqrte.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[RND]] +float16x4_t test_vrsqrte_f16(float16x4_t a) { + return vrsqrte_f16(a); +} + +// CHECK-LABEL: test_vrsqrteq_f16 +// CHECK: [[RND:%.*]] = call <8 x half> @llvm.aarch64.neon.frsqrte.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[RND]] +float16x8_t test_vrsqrteq_f16(float16x8_t a) { + return vrsqrteq_f16(a); +} + +// CHECK-LABEL: test_vsqrt_f16 +// CHECK: [[SQR:%.*]] = call <4 x half> @llvm.sqrt.v4f16(<4 x half> %a) +// CHECK: ret <4 x half> [[SQR]] +float16x4_t test_vsqrt_f16(float16x4_t a) { + return vsqrt_f16(a); +} + +// CHECK-LABEL: test_vsqrtq_f16 +// CHECK: [[SQR:%.*]] = call <8 x half> @llvm.sqrt.v8f16(<8 x half> %a) +// CHECK: ret <8 x half> [[SQR]] +float16x8_t test_vsqrtq_f16(float16x8_t a) { + return vsqrtq_f16(a); +} + +// CHECK-LABEL: test_vadd_f16 +// CHECK: [[ADD:%.*]] = fadd <4 x half> %a, %b +// CHECK: ret <4 x half> [[ADD]] +float16x4_t test_vadd_f16(float16x4_t a, float16x4_t b) { + return vadd_f16(a, b); +} + +// CHECK-LABEL: test_vaddq_f16 +// CHECK: [[ADD:%.*]] = fadd <8 x half> %a, %b +// CHECK: ret <8 x half> [[ADD]] +float16x8_t test_vaddq_f16(float16x8_t a, float16x8_t b) { + return vaddq_f16(a, b); +} + +// CHECK-LABEL: test_vabd_f16 +// CHECK: [[ABD:%.*]] = call <4 x half> @llvm.aarch64.neon.fabd.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[ABD]] +float16x4_t test_vabd_f16(float16x4_t a, float16x4_t b) { + return vabd_f16(a, b); +} + +// CHECK-LABEL: test_vabdq_f16 +// CHECK: [[ABD:%.*]] = call <8 x half> @llvm.aarch64.neon.fabd.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[ABD]] +float16x8_t test_vabdq_f16(float16x8_t a, float16x8_t b) { + return vabdq_f16(a, b); +} + +// CHECK-LABEL: test_vcage_f16 +// CHECK: [[ABS:%.*]] = call <4 x i16> @llvm.aarch64.neon.facge.v4i16.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x i16> [[ABS]] +uint16x4_t test_vcage_f16(float16x4_t a, float16x4_t b) { + return vcage_f16(a, b); +} + +// CHECK-LABEL: test_vcageq_f16 +// CHECK: [[ABS:%.*]] = call <8 x i16> @llvm.aarch64.neon.facge.v8i16.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x i16> [[ABS]] +uint16x8_t test_vcageq_f16(float16x8_t a, float16x8_t b) { + return vcageq_f16(a, b); +} + +// CHECK-LABEL: test_vcagt_f16 +// CHECK: [[ABS:%.*]] = call <4 x i16> @llvm.aarch64.neon.facgt.v4i16.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x i16> [[ABS]] +uint16x4_t test_vcagt_f16(float16x4_t a, float16x4_t b) { + return vcagt_f16(a, b); +} + +// CHECK-LABEL: test_vcagtq_f16 +// CHECK: [[ABS:%.*]] = call <8 x i16> @llvm.aarch64.neon.facgt.v8i16.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x i16> [[ABS]] +uint16x8_t test_vcagtq_f16(float16x8_t a, float16x8_t b) { + return vcagtq_f16(a, b); +} + +// CHECK-LABEL: test_vcale_f16 +// CHECK: [[ABS:%.*]] = call <4 x i16> @llvm.aarch64.neon.facge.v4i16.v4f16(<4 x half> %b, <4 x half> %a) +// CHECK: ret <4 x i16> [[ABS]] +uint16x4_t test_vcale_f16(float16x4_t a, float16x4_t b) { + return vcale_f16(a, b); +} + +// CHECK-LABEL: test_vcaleq_f16 +// CHECK: [[ABS:%.*]] = call <8 x i16> @llvm.aarch64.neon.facge.v8i16.v8f16(<8 x half> %b, <8 x half> %a) +// CHECK: ret <8 x i16> [[ABS]] +uint16x8_t test_vcaleq_f16(float16x8_t a, float16x8_t b) { + return vcaleq_f16(a, b); +} + +// CHECK-LABEL: test_vcalt_f16 +// CHECK: [[ABS:%.*]] = call <4 x i16> @llvm.aarch64.neon.facgt.v4i16.v4f16(<4 x half> %b, <4 x half> %a) +// CHECK: ret <4 x i16> [[ABS]] +uint16x4_t test_vcalt_f16(float16x4_t a, float16x4_t b) { + return vcalt_f16(a, b); +} + +// CHECK-LABEL: test_vcaltq_f16 +// CHECK: [[ABS:%.*]] = call <8 x i16> @llvm.aarch64.neon.facgt.v8i16.v8f16(<8 x half> %b, <8 x half> %a) +// CHECK: ret <8 x i16> [[ABS]] +uint16x8_t test_vcaltq_f16(float16x8_t a, float16x8_t b) { + return vcaltq_f16(a, b); +} + +// CHECK-LABEL: test_vceq_f16 +// CHECK: [[TMP1:%.*]] = fcmp oeq <4 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vceq_f16(float16x4_t a, float16x4_t b) { + return vceq_f16(a, b); +} + +// CHECK-LABEL: test_vceqq_f16 +// CHECK: [[TMP1:%.*]] = fcmp oeq <8 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vceqq_f16(float16x8_t a, float16x8_t b) { + return vceqq_f16(a, b); +} + +// CHECK-LABEL: test_vcge_f16 +// CHECK: [[TMP1:%.*]] = fcmp oge <4 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcge_f16(float16x4_t a, float16x4_t b) { + return vcge_f16(a, b); +} + +// CHECK-LABEL: test_vcgeq_f16 +// CHECK: [[TMP1:%.*]] = fcmp oge <8 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcgeq_f16(float16x8_t a, float16x8_t b) { + return vcgeq_f16(a, b); +} + +// CHECK-LABEL: test_vcgt_f16 +// CHECK: [[TMP1:%.*]] = fcmp ogt <4 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcgt_f16(float16x4_t a, float16x4_t b) { + return vcgt_f16(a, b); +} + +// CHECK-LABEL: test_vcgtq_f16 +// CHECK: [[TMP1:%.*]] = fcmp ogt <8 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcgtq_f16(float16x8_t a, float16x8_t b) { + return vcgtq_f16(a, b); +} + +// CHECK-LABEL: test_vcle_f16 +// CHECK: [[TMP1:%.*]] = fcmp ole <4 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vcle_f16(float16x4_t a, float16x4_t b) { + return vcle_f16(a, b); +} + +// CHECK-LABEL: test_vcleq_f16 +// CHECK: [[TMP1:%.*]] = fcmp ole <8 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcleq_f16(float16x8_t a, float16x8_t b) { + return vcleq_f16(a, b); +} + +// CHECK-LABEL: test_vclt_f16 +// CHECK: [[TMP1:%.*]] = fcmp olt <4 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i16> +// CHECK: ret <4 x i16> [[TMP2]] +uint16x4_t test_vclt_f16(float16x4_t a, float16x4_t b) { + return vclt_f16(a, b); +} + +// CHECK-LABEL: test_vcltq_f16 +// CHECK: [[TMP1:%.*]] = fcmp olt <8 x half> %a, %b +// CHECK: [[TMP2:%.*]] = sext <8 x i1> [[TMP1:%.*]] to <8 x i16> +// CHECK: ret <8 x i16> [[TMP2]] +uint16x8_t test_vcltq_f16(float16x8_t a, float16x8_t b) { + return vcltq_f16(a, b); +} + +// CHECK-LABEL: test_vcvt_n_f16_s16 +// CHECK: [[CVT:%.*]] = call <4 x half> @llvm.aarch64.neon.vcvtfxs2fp.v4f16.v4i16(<4 x i16> %vcvt_n, i32 2) +// CHECK: ret <4 x half> [[CVT]] +float16x4_t test_vcvt_n_f16_s16(int16x4_t a) { + return vcvt_n_f16_s16(a, 2); +} + +// CHECK-LABEL: test_vcvtq_n_f16_s16 +// CHECK: [[CVT:%.*]] = call <8 x half> @llvm.aarch64.neon.vcvtfxs2fp.v8f16.v8i16(<8 x i16> %vcvt_n, i32 2) +// CHECK: ret <8 x half> [[CVT]] +float16x8_t test_vcvtq_n_f16_s16(int16x8_t a) { + return vcvtq_n_f16_s16(a, 2); +} + +// CHECK-LABEL: test_vcvt_n_f16_u16 +// CHECK: [[CVT:%.*]] = call <4 x half> @llvm.aarch64.neon.vcvtfxu2fp.v4f16.v4i16(<4 x i16> %vcvt_n, i32 2) +// CHECK: ret <4 x half> [[CVT]] +float16x4_t test_vcvt_n_f16_u16(uint16x4_t a) { + return vcvt_n_f16_u16(a, 2); +} + +// CHECK-LABEL: test_vcvtq_n_f16_u16 +// CHECK: [[CVT:%.*]] = call <8 x half> @llvm.aarch64.neon.vcvtfxu2fp.v8f16.v8i16(<8 x i16> %vcvt_n, i32 2) +// CHECK: ret <8 x half> [[CVT]] +float16x8_t test_vcvtq_n_f16_u16(uint16x8_t a) { + return vcvtq_n_f16_u16(a, 2); +} + +// CHECK-LABEL: test_vcvt_n_s16_f16 +// CHECK: [[CVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.vcvtfp2fxs.v4i16.v4f16(<4 x half> %vcvt_n, i32 2) +// CHECK: ret <4 x i16> [[CVT]] +int16x4_t test_vcvt_n_s16_f16(float16x4_t a) { + return vcvt_n_s16_f16(a, 2); +} + +// CHECK-LABEL: test_vcvtq_n_s16_f16 +// CHECK: [[CVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.vcvtfp2fxs.v8i16.v8f16(<8 x half> %vcvt_n, i32 2) +// CHECK: ret <8 x i16> [[CVT]] +int16x8_t test_vcvtq_n_s16_f16(float16x8_t a) { + return vcvtq_n_s16_f16(a, 2); +} + +// CHECK-LABEL: test_vcvt_n_u16_f16 +// CHECK: [[CVT:%.*]] = call <4 x i16> @llvm.aarch64.neon.vcvtfp2fxu.v4i16.v4f16(<4 x half> %vcvt_n, i32 2) +// CHECK: ret <4 x i16> [[CVT]] +uint16x4_t test_vcvt_n_u16_f16(float16x4_t a) { + return vcvt_n_u16_f16(a, 2); +} + +// CHECK-LABEL: test_vcvtq_n_u16_f16 +// CHECK: [[CVT:%.*]] = call <8 x i16> @llvm.aarch64.neon.vcvtfp2fxu.v8i16.v8f16(<8 x half> %vcvt_n, i32 2) +// CHECK: ret <8 x i16> [[CVT]] +uint16x8_t test_vcvtq_n_u16_f16(float16x8_t a) { + return vcvtq_n_u16_f16(a, 2); +} + +// CHECK-LABEL: test_vdiv_f16 +// CHECK: [[DIV:%.*]] = fdiv <4 x half> %a, %b +// CHECK: ret <4 x half> [[DIV]] +float16x4_t test_vdiv_f16(float16x4_t a, float16x4_t b) { + return vdiv_f16(a, b); +} + +// CHECK-LABEL: test_vdivq_f16 +// CHECK: [[DIV:%.*]] = fdiv <8 x half> %a, %b +// CHECK: ret <8 x half> [[DIV]] +float16x8_t test_vdivq_f16(float16x8_t a, float16x8_t b) { + return vdivq_f16(a, b); +} + +// CHECK-LABEL: test_vmax_f16 +// CHECK: [[MAX:%.*]] = call <4 x half> @llvm.aarch64.neon.fmax.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MAX]] +float16x4_t test_vmax_f16(float16x4_t a, float16x4_t b) { + return vmax_f16(a, b); +} + +// CHECK-LABEL: test_vmaxq_f16 +// CHECK: [[MAX:%.*]] = call <8 x half> @llvm.aarch64.neon.fmax.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MAX]] +float16x8_t test_vmaxq_f16(float16x8_t a, float16x8_t b) { + return vmaxq_f16(a, b); +} + +// CHECK-LABEL: test_vmaxnm_f16 +// CHECK: [[MAX:%.*]] = call <4 x half> @llvm.aarch64.neon.fmaxnm.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MAX]] +float16x4_t test_vmaxnm_f16(float16x4_t a, float16x4_t b) { + return vmaxnm_f16(a, b); +} + +// CHECK-LABEL: test_vmaxnmq_f16 +// CHECK: [[MAX:%.*]] = call <8 x half> @llvm.aarch64.neon.fmaxnm.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MAX]] +float16x8_t test_vmaxnmq_f16(float16x8_t a, float16x8_t b) { + return vmaxnmq_f16(a, b); +} + +// CHECK-LABEL: test_vmin_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.fmin.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vmin_f16(float16x4_t a, float16x4_t b) { + return vmin_f16(a, b); +} + +// CHECK-LABEL: test_vminq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.fmin.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vminq_f16(float16x8_t a, float16x8_t b) { + return vminq_f16(a, b); +} + +// CHECK-LABEL: test_vminnm_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.fminnm.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vminnm_f16(float16x4_t a, float16x4_t b) { + return vminnm_f16(a, b); +} + +// CHECK-LABEL: test_vminnmq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.fminnm.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vminnmq_f16(float16x8_t a, float16x8_t b) { + return vminnmq_f16(a, b); +} + +// CHECK-LABEL: test_vmul_f16 +// CHECK: [[MUL:%.*]] = fmul <4 x half> %a, %b +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmul_f16(float16x4_t a, float16x4_t b) { + return vmul_f16(a, b); +} + +// CHECK-LABEL: test_vmulq_f16 +// CHECK: [[MUL:%.*]] = fmul <8 x half> %a, %b +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulq_f16(float16x8_t a, float16x8_t b) { + return vmulq_f16(a, b); +} + +// CHECK-LABEL: test_vmulx_f16 +// CHECK: [[MUL:%.*]] = call <4 x half> @llvm.aarch64.neon.fmulx.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmulx_f16(float16x4_t a, float16x4_t b) { + return vmulx_f16(a, b); +} + +// CHECK-LABEL: test_vmulxq_f16 +// CHECK: [[MUL:%.*]] = call <8 x half> @llvm.aarch64.neon.fmulx.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulxq_f16(float16x8_t a, float16x8_t b) { + return vmulxq_f16(a, b); +} + +// CHECK-LABEL: test_vpadd_f16 +// CHECK: [[ADD:%.*]] = call <4 x half> @llvm.aarch64.neon.addp.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[ADD]] +float16x4_t test_vpadd_f16(float16x4_t a, float16x4_t b) { + return vpadd_f16(a, b); +} + +// CHECK-LABEL: test_vpaddq_f16 +// CHECK: [[ADD:%.*]] = call <8 x half> @llvm.aarch64.neon.addp.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[ADD]] +float16x8_t test_vpaddq_f16(float16x8_t a, float16x8_t b) { + return vpaddq_f16(a, b); +} + +// CHECK-LABEL: test_vpmax_f16 +// CHECK: [[MAX:%.*]] = call <4 x half> @llvm.aarch64.neon.fmaxp.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MAX]] +float16x4_t test_vpmax_f16(float16x4_t a, float16x4_t b) { + return vpmax_f16(a, b); +} + +// CHECK-LABEL: test_vpmaxq_f16 +// CHECK: [[MAX:%.*]] = call <8 x half> @llvm.aarch64.neon.fmaxp.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MAX]] +float16x8_t test_vpmaxq_f16(float16x8_t a, float16x8_t b) { + return vpmaxq_f16(a, b); +} + +// CHECK-LABEL: test_vpmaxnm_f16 +// CHECK: [[MAX:%.*]] = call <4 x half> @llvm.aarch64.neon.fmaxnmp.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MAX]] +float16x4_t test_vpmaxnm_f16(float16x4_t a, float16x4_t b) { + return vpmaxnm_f16(a, b); +} + +// CHECK-LABEL: test_vpmaxnmq_f16 +// CHECK: [[MAX:%.*]] = call <8 x half> @llvm.aarch64.neon.fmaxnmp.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MAX]] +float16x8_t test_vpmaxnmq_f16(float16x8_t a, float16x8_t b) { + return vpmaxnmq_f16(a, b); +} + +// CHECK-LABEL: test_vpmin_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.fminp.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vpmin_f16(float16x4_t a, float16x4_t b) { + return vpmin_f16(a, b); +} + +// CHECK-LABEL: test_vpminq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.fminp.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vpminq_f16(float16x8_t a, float16x8_t b) { + return vpminq_f16(a, b); +} + +// CHECK-LABEL: test_vpminnm_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.fminnmp.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vpminnm_f16(float16x4_t a, float16x4_t b) { + return vpminnm_f16(a, b); +} + +// CHECK-LABEL: test_vpminnmq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.fminnmp.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vpminnmq_f16(float16x8_t a, float16x8_t b) { + return vpminnmq_f16(a, b); +} + +// CHECK-LABEL: test_vrecps_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.frecps.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vrecps_f16(float16x4_t a, float16x4_t b) { + return vrecps_f16(a, b); +} + +// CHECK-LABEL: test_vrecpsq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.frecps.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vrecpsq_f16(float16x8_t a, float16x8_t b) { + return vrecpsq_f16(a, b); +} + +// CHECK-LABEL: test_vrsqrts_f16 +// CHECK: [[MIN:%.*]] = call <4 x half> @llvm.aarch64.neon.frsqrts.v4f16(<4 x half> %a, <4 x half> %b) +// CHECK: ret <4 x half> [[MIN]] +float16x4_t test_vrsqrts_f16(float16x4_t a, float16x4_t b) { + return vrsqrts_f16(a, b); +} + +// CHECK-LABEL: test_vrsqrtsq_f16 +// CHECK: [[MIN:%.*]] = call <8 x half> @llvm.aarch64.neon.frsqrts.v8f16(<8 x half> %a, <8 x half> %b) +// CHECK: ret <8 x half> [[MIN]] +float16x8_t test_vrsqrtsq_f16(float16x8_t a, float16x8_t b) { + return vrsqrtsq_f16(a, b); +} + +// CHECK-LABEL: test_vsub_f16 +// CHECK: [[ADD:%.*]] = fsub <4 x half> %a, %b +// CHECK: ret <4 x half> [[ADD]] +float16x4_t test_vsub_f16(float16x4_t a, float16x4_t b) { + return vsub_f16(a, b); +} + +// CHECK-LABEL: test_vsubq_f16 +// CHECK: [[ADD:%.*]] = fsub <8 x half> %a, %b +// CHECK: ret <8 x half> [[ADD]] +float16x8_t test_vsubq_f16(float16x8_t a, float16x8_t b) { + return vsubq_f16(a, b); +} + +// CHECK-LABEL: test_vfma_f16 +// CHECK: [[ADD:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> %b, <4 x half> %c, <4 x half> %a) +// CHECK: ret <4 x half> [[ADD]] +float16x4_t test_vfma_f16(float16x4_t a, float16x4_t b, float16x4_t c) { + return vfma_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmaq_f16 +// CHECK: [[ADD:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> %b, <8 x half> %c, <8 x half> %a) +// CHECK: ret <8 x half> [[ADD]] +float16x8_t test_vfmaq_f16(float16x8_t a, float16x8_t b, float16x8_t c) { + return vfmaq_f16(a, b, c); +} + +// CHECK-LABEL: test_vfms_f16 +// CHECK: [[SUB:%.*]] = fsub <4 x half> , %b +// CHECK: [[ADD:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[SUB]], <4 x half> %c, <4 x half> %a) +// CHECK: ret <4 x half> [[ADD]] +float16x4_t test_vfms_f16(float16x4_t a, float16x4_t b, float16x4_t c) { + return vfms_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmsq_f16 +// CHECK: [[SUB:%.*]] = fsub <8 x half> , %b +// CHECK: [[ADD:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[SUB]], <8 x half> %c, <8 x half> %a) +// CHECK: ret <8 x half> [[ADD]] +float16x8_t test_vfmsq_f16(float16x8_t a, float16x8_t b, float16x8_t c) { + return vfmsq_f16(a, b, c); +} + +// CHECK-LABEL: test_vfma_lane_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x half> +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <4 x i32> +// CHECK: [[TMP4:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP5:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[FMLA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[TMP4]], <4 x half> [[LANE]], <4 x half> [[TMP5]]) +// CHECK: ret <4 x half> [[FMLA]] +float16x4_t test_vfma_lane_f16(float16x4_t a, float16x4_t b, float16x4_t c) { + return vfma_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfmaq_lane_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x half> +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <8 x i32> +// CHECK: [[TMP4:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[FMLA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[TMP4]], <8 x half> [[LANE]], <8 x half> [[TMP5]]) +// CHECK: ret <8 x half> [[FMLA]] +float16x8_t test_vfmaq_lane_f16(float16x8_t a, float16x8_t b, float16x4_t c) { + return vfmaq_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfma_laneq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[TMP4:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x half> +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP5]], <8 x half> [[TMP5]], <4 x i32> +// CHECK: [[FMLA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[LANE]], <4 x half> [[TMP4]], <4 x half> [[TMP3]]) +// CHECK: ret <4 x half> [[FMLA]] +float16x4_t test_vfma_laneq_f16(float16x4_t a, float16x4_t b, float16x8_t c) { + return vfma_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vfmaq_laneq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[TMP4:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x half> +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP5]], <8 x half> [[TMP5]], <8 x i32> +// CHECK: [[FMLA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[LANE]], <8 x half> [[TMP4]], <8 x half> [[TMP3]]) +// CHECK: ret <8 x half> [[FMLA]] +float16x8_t test_vfmaq_laneq_f16(float16x8_t a, float16x8_t b, float16x8_t c) { + return vfmaq_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vfma_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %c, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %c, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %c, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %c, i32 3 +// CHECK: [[FMA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> %b, <4 x half> [[TMP3]], <4 x half> %a) +// CHECK: ret <4 x half> [[FMA]] +float16x4_t test_vfma_n_f16(float16x4_t a, float16x4_t b, float16_t c) { + return vfma_n_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmaq_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %c, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %c, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %c, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %c, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %c, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %c, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %c, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %c, i32 7 +// CHECK: [[FMA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> %b, <8 x half> [[TMP7]], <8 x half> %a) +// CHECK: ret <8 x half> [[FMA]] +float16x8_t test_vfmaq_n_f16(float16x8_t a, float16x8_t b, float16_t c) { + return vfmaq_n_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmah_lane_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[EXTR:%.*]] = extractelement <4 x half> [[TMP1]], i32 3 +// CHECK: [[FMA:%.*]] = call half @llvm.fma.f16(half %b, half [[EXTR]], half %a) +// CHECK: ret half [[FMA]] +float16_t test_vfmah_lane_f16(float16_t a, float16_t b, float16x4_t c) { + return vfmah_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfmah_laneq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[EXTR:%.*]] = extractelement <8 x half> [[TMP1]], i32 7 +// CHECK: [[FMA:%.*]] = call half @llvm.fma.f16(half %b, half [[EXTR]], half %a) +// CHECK: ret half [[FMA]] +float16_t test_vfmah_laneq_f16(float16_t a, float16_t b, float16x8_t c) { + return vfmah_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vfms_lane_f16 +// CHECK: [[SUB:%.*]] = fsub <4 x half> , %b +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> [[SUB]] to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x half> +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <4 x i32> +// CHECK: [[TMP4:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP5:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[FMA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[TMP4]], <4 x half> [[LANE]], <4 x half> [[TMP5]]) +// CHECK: ret <4 x half> [[FMA]] +float16x4_t test_vfms_lane_f16(float16x4_t a, float16x4_t b, float16x4_t c) { + return vfms_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfmsq_lane_f16 +// CHECK: [[SUB:%.*]] = fsub <8 x half> , %b +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> [[SUB]] to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x half> +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <8 x i32> +// CHECK: [[TMP4:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[FMLA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[TMP4]], <8 x half> [[LANE]], <8 x half> [[TMP5]]) +// CHECK: ret <8 x half> [[FMLA]] +float16x8_t test_vfmsq_lane_f16(float16x8_t a, float16x8_t b, float16x4_t c) { + return vfmsq_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfms_laneq_f16 +// CHECK: [[SUB:%.*]] = fsub <4 x half> , %b +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> [[SUB]] to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[TMP4:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x half> +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP5]], <8 x half> [[TMP5]], <4 x i32> +// CHECK: [[FMLA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[LANE]], <4 x half> [[TMP4]], <4 x half> [[TMP3]]) +// CHECK: ret <4 x half> [[FMLA]] +float16x4_t test_vfms_laneq_f16(float16x4_t a, float16x4_t b, float16x8_t c) { + return vfms_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vfmsq_laneq_f16 +// CHECK: [[SUB:%.*]] = fsub <8 x half> , %b +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> [[SUB]] to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[TMP4:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP5:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x half> +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP5]], <8 x half> [[TMP5]], <8 x i32> +// CHECK: [[FMLA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[LANE]], <8 x half> [[TMP4]], <8 x half> [[TMP3]]) +// CHECK: ret <8 x half> [[FMLA]] +float16x8_t test_vfmsq_laneq_f16(float16x8_t a, float16x8_t b, float16x8_t c) { + return vfmsq_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vfms_n_f16 +// CHECK: [[SUB:%.*]] = fsub <4 x half> , %b +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %c, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %c, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %c, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %c, i32 3 +// CHECK: [[FMA:%.*]] = call <4 x half> @llvm.fma.v4f16(<4 x half> [[SUB]], <4 x half> [[TMP3]], <4 x half> %a) +// CHECK: ret <4 x half> [[FMA]] +float16x4_t test_vfms_n_f16(float16x4_t a, float16x4_t b, float16_t c) { + return vfms_n_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmsq_n_f16 +// CHECK: [[SUB:%.*]] = fsub <8 x half> , %b +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %c, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %c, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %c, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %c, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %c, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %c, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %c, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %c, i32 7 +// CHECK: [[FMA:%.*]] = call <8 x half> @llvm.fma.v8f16(<8 x half> [[SUB]], <8 x half> [[TMP7]], <8 x half> %a) +// CHECK: ret <8 x half> [[FMA]] +float16x8_t test_vfmsq_n_f16(float16x8_t a, float16x8_t b, float16_t c) { + return vfmsq_n_f16(a, b, c); +} + +// CHECK-LABEL: test_vfmsh_lane_f16 +// CHECK: [[TMP0:%.*]] = fpext half %b to float +// CHECK: [[TMP1:%.*]] = fsub float -0.000000e+00, [[TMP0]] +// CHECK: [[SUB:%.*]] = fptrunc float [[TMP1]] to half +// CHECK: [[TMP2:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x half> +// CHECK: [[EXTR:%.*]] = extractelement <4 x half> [[TMP3]], i32 3 +// CHECK: [[FMA:%.*]] = call half @llvm.fma.f16(half [[SUB]], half [[EXTR]], half %a) +// CHECK: ret half [[FMA]] +float16_t test_vfmsh_lane_f16(float16_t a, float16_t b, float16x4_t c) { + return vfmsh_lane_f16(a, b, c, 3); +} + +// CHECK-LABEL: test_vfmsh_laneq_f16 +// CHECK: [[TMP0:%.*]] = fpext half %b to float +// CHECK: [[TMP1:%.*]] = fsub float -0.000000e+00, [[TMP0]] +// CHECK: [[SUB:%.*]] = fptrunc float [[TMP1]] to half +// CHECK: [[TMP2:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x half> +// CHECK: [[EXTR:%.*]] = extractelement <8 x half> [[TMP3]], i32 7 +// CHECK: [[FMA:%.*]] = call half @llvm.fma.f16(half [[SUB]], half [[EXTR]], half %a) +// CHECK: ret half [[FMA]] +float16_t test_vfmsh_laneq_f16(float16_t a, float16_t b, float16x8_t c) { + return vfmsh_laneq_f16(a, b, c, 7); +} + +// CHECK-LABEL: test_vmul_lane_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <4 x half> %b, <4 x half> %b, <4 x i32> +// CHECK: [[MUL:%.*]] = fmul <4 x half> %a, [[TMP0]] +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmul_lane_f16(float16x4_t a, float16x4_t b) { + return vmul_lane_f16(a, b, 3); +} + +// CHECK-LABEL: test_vmulq_lane_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <4 x half> %b, <4 x half> %b, <8 x i32> +// CHECK: [[MUL:%.*]] = fmul <8 x half> %a, [[TMP0]] +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulq_lane_f16(float16x8_t a, float16x4_t b) { + return vmulq_lane_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmul_laneq_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <8 x half> %b, <8 x half> %b, <4 x i32> +// CHECK: [[MUL:%.*]] = fmul <4 x half> %a, [[TMP0]] +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmul_laneq_f16(float16x4_t a, float16x8_t b) { + return vmul_laneq_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmulq_laneq_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <8 x half> %b, <8 x half> %b, <8 x i32> +// CHECK: [[MUL:%.*]] = fmul <8 x half> %a, [[TMP0]] +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulq_laneq_f16(float16x8_t a, float16x8_t b) { + return vmulq_laneq_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmul_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %b, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %b, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %b, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %b, i32 3 +// CHECK: [[MUL:%.*]] = fmul <4 x half> %a, [[TMP3]] +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmul_n_f16(float16x4_t a, float16_t b) { + return vmul_n_f16(a, b); +} + +// CHECK-LABEL: test_vmulq_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %b, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %b, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %b, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %b, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %b, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %b, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %b, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %b, i32 7 +// CHECK: [[MUL:%.*]] = fmul <8 x half> %a, [[TMP7]] +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulq_n_f16(float16x8_t a, float16_t b) { + return vmulq_n_f16(a, b); +} + +// FIXME: Fix it when fp16 non-storage-only type becomes available. +// CHECK-LABEL: test_vmulh_lane_f16 +// CHECK: [[CONV0:%.*]] = fpext half %a to float +// CHECK: [[CONV1:%.*]] = fpext half %{{.*}} to float +// CHECK: [[MUL:%.*]] = fmul float [[CONV0:%.*]], [[CONV0:%.*]] +// CHECK: [[CONV3:%.*]] = fptrunc float %mul to half +// CHECK: ret half [[CONV3:%.*]] +float16_t test_vmulh_lane_f16(float16_t a, float16x4_t b) { + return vmulh_lane_f16(a, b, 3); +} + +// CHECK-LABEL: test_vmulh_laneq_f16 +// CHECK: [[CONV0:%.*]] = fpext half %a to float +// CHECK: [[CONV1:%.*]] = fpext half %{{.*}} to float +// CHECK: [[MUL:%.*]] = fmul float [[CONV0:%.*]], [[CONV0:%.*]] +// CHECK: [[CONV3:%.*]] = fptrunc float %mul to half +// CHECK: ret half [[CONV3:%.*]] +float16_t test_vmulh_laneq_f16(float16_t a, float16x8_t b) { + return vmulh_laneq_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmulx_lane_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <4 x half> %b, <4 x half> %b, <4 x i32> +// CHECK: [[MUL:%.*]] = call <4 x half> @llvm.aarch64.neon.fmulx.v4f16(<4 x half> %a, <4 x half> [[TMP0]]) +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmulx_lane_f16(float16x4_t a, float16x4_t b) { + return vmulx_lane_f16(a, b, 3); +} + +// CHECK-LABEL: test_vmulxq_lane_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <4 x half> %b, <4 x half> %b, <8 x i32> +// CHECK: [[MUL:%.*]] = call <8 x half> @llvm.aarch64.neon.fmulx.v8f16(<8 x half> %a, <8 x half> [[TMP0]]) +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulxq_lane_f16(float16x8_t a, float16x4_t b) { + return vmulxq_lane_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmulx_laneq_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <8 x half> %b, <8 x half> %b, <4 x i32> +// CHECK: [[MUL:%.*]] = call <4 x half> @llvm.aarch64.neon.fmulx.v4f16(<4 x half> %a, <4 x half> [[TMP0]]) +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmulx_laneq_f16(float16x4_t a, float16x8_t b) { + return vmulx_laneq_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmulxq_laneq_f16 +// CHECK: [[TMP0:%.*]] = shufflevector <8 x half> %b, <8 x half> %b, <8 x i32> +// CHECK: [[MUL:%.*]] = call <8 x half> @llvm.aarch64.neon.fmulx.v8f16(<8 x half> %a, <8 x half> [[TMP0]]) +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulxq_laneq_f16(float16x8_t a, float16x8_t b) { + return vmulxq_laneq_f16(a, b, 7); +} + +// CHECK-LABEL: test_vmulx_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %b, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %b, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %b, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %b, i32 3 +// CHECK: [[MUL:%.*]] = call <4 x half> @llvm.aarch64.neon.fmulx.v4f16(<4 x half> %a, <4 x half> [[TMP3]]) +// CHECK: ret <4 x half> [[MUL]] +float16x4_t test_vmulx_n_f16(float16x4_t a, float16_t b) { + return vmulx_n_f16(a, b); +} + +// CHECK-LABEL: test_vmulxq_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %b, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %b, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %b, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %b, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %b, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %b, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %b, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %b, i32 7 +// CHECK: [[MUL:%.*]] = call <8 x half> @llvm.aarch64.neon.fmulx.v8f16(<8 x half> %a, <8 x half> [[TMP7]]) +// CHECK: ret <8 x half> [[MUL]] +float16x8_t test_vmulxq_n_f16(float16x8_t a, float16_t b) { + return vmulxq_n_f16(a, b); +} + +/* TODO: Not implemented yet (needs scalar intrinsic from arm_fp16.h) +// CCHECK-LABEL: test_vmulxh_lane_f16 +// CCHECK: [[CONV0:%.*]] = fpext half %a to float +// CCHECK: [[CONV1:%.*]] = fpext half %{{.*}} to float +// CCHECK: [[MUL:%.*]] = fmul float [[CONV0:%.*]], [[CONV0:%.*]] +// CCHECK: [[CONV3:%.*]] = fptrunc float %mul to half +// CCHECK: ret half [[CONV3:%.*]] +float16_t test_vmulxh_lane_f16(float16_t a, float16x4_t b) { + return vmulxh_lane_f16(a, b, 3); +} + +// CCHECK-LABEL: test_vmulxh_laneq_f16 +// CCHECK: [[CONV0:%.*]] = fpext half %a to float +// CCHECK: [[CONV1:%.*]] = fpext half %{{.*}} to float +// CCHECK: [[MUL:%.*]] = fmul float [[CONV0:%.*]], [[CONV0:%.*]] +// CCHECK: [[CONV3:%.*]] = fptrunc float %mul to half +// CCHECK: ret half [[CONV3:%.*]] +float16_t test_vmulxh_laneq_f16(float16_t a, float16x8_t b) { + return vmulxh_laneq_f16(a, b, 7); +} +*/ + +// CHECK-LABEL: test_vmaxv_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fmaxv.f16.v4f16(<4 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vmaxv_f16(float16x4_t a) { + return vmaxv_f16(a); +} + +// CHECK-LABEL: test_vmaxvq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fmaxv.f16.v8f16(<8 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vmaxvq_f16(float16x8_t a) { + return vmaxvq_f16(a); +} + +// CHECK-LABEL: test_vminv_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fminv.f16.v4f16(<4 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vminv_f16(float16x4_t a) { + return vminv_f16(a); +} + +// CHECK-LABEL: test_vminvq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fminv.f16.v8f16(<8 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vminvq_f16(float16x8_t a) { + return vminvq_f16(a); +} + +// CHECK-LABEL: test_vmaxnmv_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fmaxnmv.f16.v4f16(<4 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vmaxnmv_f16(float16x4_t a) { + return vmaxnmv_f16(a); +} + +// CHECK-LABEL: test_vmaxnmvq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fmaxnmv.f16.v8f16(<8 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vmaxnmvq_f16(float16x8_t a) { + return vmaxnmvq_f16(a); +} + +// CHECK-LABEL: test_vminnmv_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fminnmv.f16.v4f16(<4 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vminnmv_f16(float16x4_t a) { + return vminnmv_f16(a); +} + +// CHECK-LABEL: test_vminnmvq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[MAX:%.*]] = call half @llvm.aarch64.neon.fminnmv.f16.v8f16(<8 x half> [[TMP1]]) +// CHECK: ret half [[MAX]] +float16_t test_vminnmvq_f16(float16x8_t a) { + return vminnmvq_f16(a); +} + +// CHECK-LABEL: test_vbsl_f16 +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %b to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> %c to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x i16> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> +// CHECK: [[TMP4:%.*]] = and <4 x i16> %a, [[TMP2]] +// CHECK: [[TMP5:%.*]] = xor <4 x i16> %a, +// CHECK: [[TMP6:%.*]] = and <4 x i16> [[TMP5]], [[TMP3]] +// CHECK: [[TMP7:%.*]] = or <4 x i16> [[TMP4]], [[TMP6]] +// CHECK: [[TMP8:%.*]] = bitcast <4 x i16> [[TMP7]] to <4 x half> +// CHECK: ret <4 x half> [[TMP8]] +float16x4_t test_vbsl_f16(uint16x4_t a, float16x4_t b, float16x4_t c) { + return vbsl_f16(a, b, c); +} + +// CHECK-LABEL: test_vbslq_f16 +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %b to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> %c to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x i16> +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> +// CHECK: [[TMP4:%.*]] = and <8 x i16> %a, [[TMP2]] +// CHECK: [[TMP5:%.*]] = xor <8 x i16> %a, +// CHECK: [[TMP6:%.*]] = and <8 x i16> [[TMP5]], [[TMP3]] +// CHECK: [[TMP7:%.*]] = or <8 x i16> [[TMP4]], [[TMP6]] +// CHECK: [[TMP8:%.*]] = bitcast <8 x i16> [[TMP7]] to <8 x half> +// CHECK: ret <8 x half> [[TMP8]] +float16x8_t test_vbslq_f16(uint16x8_t a, float16x8_t b, float16x8_t c) { + return vbslq_f16(a, b, c); +} + +// CHECK-LABEL: test_vzip_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP0_I]], <4 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <4 x half>, <4 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP1_I]], <4 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 16, i32 8, i1 false) +float16x4x2_t test_vzip_f16(float16x4_t a, float16x4_t b) { + return vzip_f16(a, b); +} + +// CHECK-LABEL: test_vzipq_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP0_I]], <8 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <8 x half>, <8 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP1_I]], <8 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 32, i32 16, i1 false) +float16x8x2_t test_vzipq_f16(float16x8_t a, float16x8_t b) { + return vzipq_f16(a, b); +} + +// CHECK-LABEL: test_vuzp_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP0_I]], <4 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <4 x half>, <4 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP1_I]], <4 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 16, i32 8, i1 false) +float16x4x2_t test_vuzp_f16(float16x4_t a, float16x4_t b) { + return vuzp_f16(a, b); +} + +// CHECK-LABEL: test_vuzpq_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP0_I]], <8 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <8 x half>, <8 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP1_I]], <8 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 32, i32 16, i1 false) +float16x8x2_t test_vuzpq_f16(float16x8_t a, float16x8_t b) { + return vuzpq_f16(a, b); +} + +// CHECK-LABEL: test_vtrn_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x4x2_t, align 8 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP0_I]], <4 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <4 x half>, <4 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: store <4 x half> [[VZIP1_I]], <4 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x4x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x4x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 16, i32 8, i1 false) +float16x4x2_t test_vtrn_f16(float16x4_t a, float16x4_t b) { + return vtrn_f16(a, b); +} + +// CHECK-LABEL: test_vtrnq_f16 +// CHECK: [[RETVAL:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[__RET_I:%.*]] = alloca %struct.float16x8x2_t, align 16 +// CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <8 x half>* +// CHECK: [[VZIP0_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP0_I]], <8 x half>* [[TMP1]] +// CHECK: [[TMP2:%.*]] = getelementptr inbounds <8 x half>, <8 x half>* [[TMP1]], i32 1 +// CHECK: [[VZIP1_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: store <8 x half> [[VZIP1_I]], <8 x half>* [[TMP2]] +// CHECK: [[TMP5:%.*]] = bitcast %struct.float16x8x2_t* [[RETVAL]] to i8* +// CHECK: [[TMP6:%.*]] = bitcast %struct.float16x8x2_t* [[__RET_I]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[TMP5]], i8* [[TMP6]], i64 32, i32 16, i1 false) +float16x8x2_t test_vtrnq_f16(float16x8_t a, float16x8_t b) { + return vtrnq_f16(a, b); +} + +// CHECK-LABEL: test_vmov_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %a, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %a, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %a, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %a, i32 3 +// CHECK: ret <4 x half> [[TMP3]] +float16x4_t test_vmov_n_f16(float16_t a) { + return vmov_n_f16(a); +} + +// CHECK-LABEL: test_vmovq_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %a, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %a, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %a, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %a, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %a, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %a, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %a, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %a, i32 7 +// CHECK: ret <8 x half> [[TMP7]] +float16x8_t test_vmovq_n_f16(float16_t a) { + return vmovq_n_f16(a); +} + +// CHECK-LABEL: test_vdup_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <4 x half> undef, half %a, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <4 x half> [[TMP0]], half %a, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <4 x half> [[TMP1]], half %a, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> [[TMP2]], half %a, i32 3 +// CHECK: ret <4 x half> [[TMP3]] +float16x4_t test_vdup_n_f16(float16_t a) { + return vdup_n_f16(a); +} + +// CHECK-LABEL: test_vdupq_n_f16 +// CHECK: [[TMP0:%.*]] = insertelement <8 x half> undef, half %a, i32 0 +// CHECK: [[TMP1:%.*]] = insertelement <8 x half> [[TMP0]], half %a, i32 1 +// CHECK: [[TMP2:%.*]] = insertelement <8 x half> [[TMP1]], half %a, i32 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> [[TMP2]], half %a, i32 3 +// CHECK: [[TMP4:%.*]] = insertelement <8 x half> [[TMP3]], half %a, i32 4 +// CHECK: [[TMP5:%.*]] = insertelement <8 x half> [[TMP4]], half %a, i32 5 +// CHECK: [[TMP6:%.*]] = insertelement <8 x half> [[TMP5]], half %a, i32 6 +// CHECK: [[TMP7:%.*]] = insertelement <8 x half> [[TMP6]], half %a, i32 7 +// CHECK: ret <8 x half> [[TMP7]] +float16x8_t test_vdupq_n_f16(float16_t a) { + return vdupq_n_f16(a); +} + +// CHECK-LABEL: test_vdup_lane_f16 +// CHECK: [[SHFL:%.*]] = shufflevector <4 x half> %a, <4 x half> %a, <4 x i32> +// CHECK: ret <4 x half> [[SHFL]] +float16x4_t test_vdup_lane_f16(float16x4_t a) { + return vdup_lane_f16(a, 3); +} + +// CHECK-LABEL: test_vdupq_lane_f16 +// CHECK: [[SHFL:%.*]] = shufflevector <4 x half> %a, <4 x half> %a, <8 x i32> +// CHECK: ret <8 x half> [[SHFL]] +float16x8_t test_vdupq_lane_f16(float16x4_t a) { + return vdupq_lane_f16(a, 7); +} + +// CHECK-LABEL: @test_vext_f16( +// CHECK: [[TMP0:%.*]] = bitcast <4 x half> %a to <8 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP0]] to <4 x half> +// CHECK: [[TMP3:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[VEXT:%.*]] = shufflevector <4 x half> [[TMP2]], <4 x half> [[TMP3]], <4 x i32> +// CHECK: ret <4 x half> [[VEXT]] +float16x4_t test_vext_f16(float16x4_t a, float16x4_t b) { + return vext_f16(a, b, 2); +} + +// CHECK-LABEL: @test_vextq_f16( +// CHECK: [[TMP0:%.*]] = bitcast <8 x half> %a to <16 x i8> +// CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP0]] to <8 x half> +// CHECK: [[TMP3:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[VEXT:%.*]] = shufflevector <8 x half> [[TMP2]], <8 x half> [[TMP3]], <8 x i32> +// CHECK: ret <8 x half> [[VEXT]] +float16x8_t test_vextq_f16(float16x8_t a, float16x8_t b) { + return vextq_f16(a, b, 5); +} + +// CHECK-LABEL: @test_vrev64_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <4 x half> %a, <4 x half> %a, <4 x i32> +// CHECK: ret <4 x half> [[SHFL]] +float16x4_t test_vrev64_f16(float16x4_t a) { + return vrev64_f16(a); +} + +// CHECK-LABEL: @test_vrev64q_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <8 x half> %a, <8 x half> %a, <8 x i32> +// CHECK: ret <8 x half> [[SHFL]] +float16x8_t test_vrev64q_f16(float16x8_t a) { + return vrev64q_f16(a); +} + +// CHECK-LABEL: @test_vzip1_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHFL]] +float16x4_t test_vzip1_f16(float16x4_t a, float16x4_t b) { + return vzip1_f16(a, b); +} + +// CHECK-LABEL: @test_vzip1q_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHFL]] +float16x8_t test_vzip1q_f16(float16x8_t a, float16x8_t b) { + return vzip1q_f16(a, b); +} + +// CHECK-LABEL: @test_vzip2_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHFL]] +float16x4_t test_vzip2_f16(float16x4_t a, float16x4_t b) { + return vzip2_f16(a, b); +} + +// CHECK-LABEL: @test_vzip2q_f16( +// CHECK: [[SHFL:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHFL]] +float16x8_t test_vzip2q_f16(float16x8_t a, float16x8_t b) { + return vzip2q_f16(a, b); +} + +// CHECK-LABEL: @test_vuzp1_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHUFFLE_I]] +float16x4_t test_vuzp1_f16(float16x4_t a, float16x4_t b) { + return vuzp1_f16(a, b); +} + +// CHECK-LABEL: @test_vuzp1q_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHUFFLE_I]] +float16x8_t test_vuzp1q_f16(float16x8_t a, float16x8_t b) { + return vuzp1q_f16(a, b); +} + +// CHECK-LABEL: @test_vuzp2_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHUFFLE_I]] +float16x4_t test_vuzp2_f16(float16x4_t a, float16x4_t b) { + return vuzp2_f16(a, b); +} + +// CHECK-LABEL: @test_vuzp2q_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHUFFLE_I]] +float16x8_t test_vuzp2q_f16(float16x8_t a, float16x8_t b) { + return vuzp2q_f16(a, b); +} + +// CHECK-LABEL: @test_vtrn1_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHUFFLE_I]] +float16x4_t test_vtrn1_f16(float16x4_t a, float16x4_t b) { + return vtrn1_f16(a, b); +} + +// CHECK-LABEL: @test_vtrn1q_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHUFFLE_I]] +float16x8_t test_vtrn1q_f16(float16x8_t a, float16x8_t b) { + return vtrn1q_f16(a, b); +} + +// CHECK-LABEL: @test_vtrn2_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <4 x half> %a, <4 x half> %b, <4 x i32> +// CHECK: ret <4 x half> [[SHUFFLE_I]] +float16x4_t test_vtrn2_f16(float16x4_t a, float16x4_t b) { + return vtrn2_f16(a, b); +} + +// CHECK-LABEL: @test_vtrn2q_f16( +// CHECK: [[SHUFFLE_I:%.*]] = shufflevector <8 x half> %a, <8 x half> %b, <8 x i32> +// CHECK: ret <8 x half> [[SHUFFLE_I]] +float16x8_t test_vtrn2q_f16(float16x8_t a, float16x8_t b) { + return vtrn2q_f16(a, b); +} + diff --git a/test/CodeGen/arm_neon_intrinsics.c b/test/CodeGen/arm_neon_intrinsics.c index 62888dd73339..b01c90c03a96 100644 --- a/test/CodeGen/arm_neon_intrinsics.c +++ b/test/CodeGen/arm_neon_intrinsics.c @@ -3896,9 +3896,8 @@ int64x2_t test_vld1q_s64(int64_t const * a) { // CHECK-LABEL: @test_vld1q_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD1:%.*]] = call <8 x i16> @llvm.arm.neon.vld1.v8i16.p0i8(i8* [[TMP0]], i32 2) -// CHECK: [[TMP1:%.*]] = bitcast <8 x i16> [[VLD1]] to <8 x half> -// CHECK: ret <8 x half> [[TMP1]] +// CHECK: [[VLD1:%.*]] = call <8 x half> @llvm.arm.neon.vld1.v8f16.p0i8(i8* [[TMP0]], i32 2) +// CHECK: ret <8 x half> [[VLD1]] float16x8_t test_vld1q_f16(float16_t const * a) { return vld1q_f16(a); } @@ -3990,9 +3989,8 @@ int64x1_t test_vld1_s64(int64_t const * a) { // CHECK-LABEL: @test_vld1_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD1:%.*]] = call <4 x i16> @llvm.arm.neon.vld1.v4i16.p0i8(i8* [[TMP0]], i32 2) -// CHECK: [[TMP1:%.*]] = bitcast <4 x i16> [[VLD1]] to <4 x half> -// CHECK: ret <4 x half> [[TMP1]] +// CHECK: [[VLD1:%.*]] = call <4 x half> @llvm.arm.neon.vld1.v4f16.p0i8(i8* [[TMP0]], i32 2) +// CHECK: ret <4 x half> [[VLD1]] float16x4_t test_vld1_f16(float16_t const * a) { return vld1_f16(a); } @@ -4106,12 +4104,11 @@ int64x2_t test_vld1q_dup_s64(int64_t const * a) { // CHECK-LABEL: @test_vld1q_dup_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP2:%.*]] = load i16, i16* [[TMP1]], align 2 -// CHECK: [[TMP3:%.*]] = insertelement <8 x i16> undef, i16 [[TMP2]], i32 0 -// CHECK: [[LANE:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> [[TMP3]], <8 x i32> zeroinitializer -// CHECK: [[TMP4:%.*]] = bitcast <8 x i16> [[LANE]] to <8 x half> -// CHECK: ret <8 x half> [[TMP4]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP2:%.*]] = load half, half* [[TMP1]], align 2 +// CHECK: [[TMP3:%.*]] = insertelement <8 x half> undef, half [[TMP2]], i32 0 +// CHECK: [[LANE:%.*]] = shufflevector <8 x half> [[TMP3]], <8 x half> [[TMP3]], <8 x i32> zeroinitializer +// CHECK: ret <8 x half> [[LANE]] float16x8_t test_vld1q_dup_f16(float16_t const * a) { return vld1q_dup_f16(a); } @@ -4233,12 +4230,11 @@ int64x1_t test_vld1_dup_s64(int64_t const * a) { // CHECK-LABEL: @test_vld1_dup_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* -// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP2:%.*]] = load i16, i16* [[TMP1]], align 2 -// CHECK: [[TMP3:%.*]] = insertelement <4 x i16> undef, i16 [[TMP2]], i32 0 -// CHECK: [[LANE:%.*]] = shufflevector <4 x i16> [[TMP3]], <4 x i16> [[TMP3]], <4 x i32> zeroinitializer -// CHECK: [[TMP4:%.*]] = bitcast <4 x i16> [[LANE]] to <4 x half> -// CHECK: ret <4 x half> [[TMP4]] +// CHECK: [[TMP1:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP2:%.*]] = load half, half* [[TMP1]], align 2 +// CHECK: [[TMP3:%.*]] = insertelement <4 x half> undef, half [[TMP2]], i32 0 +// CHECK: [[LANE:%.*]] = shufflevector <4 x half> [[TMP3]], <4 x half> [[TMP3]], <4 x i32> zeroinitializer +// CHECK: ret <4 x half> [[LANE]] float16x4_t test_vld1_dup_f16(float16_t const * a) { return vld1_dup_f16(a); } @@ -4365,12 +4361,11 @@ int64x2_t test_vld1q_lane_s64(int64_t const * a, int64x2_t b) { // CHECK-LABEL: @test_vld1q_lane_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP4:%.*]] = load i16, i16* [[TMP3]], align 2 -// CHECK: [[VLD1_LANE:%.*]] = insertelement <8 x i16> [[TMP2]], i16 [[TMP4]], i32 7 -// CHECK: [[TMP5:%.*]] = bitcast <8 x i16> [[VLD1_LANE]] to <8 x half> -// CHECK: ret <8 x half> [[TMP5]] +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP4:%.*]] = load half, half* [[TMP3]], align 2 +// CHECK: [[VLD1_LANE:%.*]] = insertelement <8 x half> [[TMP2]], half [[TMP4]], i32 7 +// CHECK: ret <8 x half> [[VLD1_LANE]] float16x8_t test_vld1q_lane_f16(float16_t const * a, float16x8_t b) { return vld1q_lane_f16(a, b, 7); } @@ -4498,12 +4493,11 @@ int64x1_t test_vld1_lane_s64(int64_t const * a, int64x1_t b) { // CHECK-LABEL: @test_vld1_lane_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: [[TMP4:%.*]] = load i16, i16* [[TMP3]], align 2 -// CHECK: [[VLD1_LANE:%.*]] = insertelement <4 x i16> [[TMP2]], i16 [[TMP4]], i32 3 -// CHECK: [[TMP5:%.*]] = bitcast <4 x i16> [[VLD1_LANE]] to <4 x half> -// CHECK: ret <4 x half> [[TMP5]] +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP3:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: [[TMP4:%.*]] = load half, half* [[TMP3]], align 2 +// CHECK: [[VLD1_LANE:%.*]] = insertelement <4 x half> [[TMP2]], half [[TMP4]], i32 3 +// CHECK: ret <4 x half> [[VLD1_LANE]] float16x4_t test_vld1_lane_f16(float16_t const * a, float16x4_t b) { return vld1_lane_f16(a, b, 3); } @@ -4596,7 +4590,7 @@ int32x4x2_t test_vld2q_s32(int32_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x2_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD2Q_V:%.*]] = call { <8 x i16>, <8 x i16> +// CHECK: [[VLD2Q_V:%.*]] = call { <8 x half>, <8 x half> float16x8x2_t test_vld2q_f16(float16_t const * a) { return vld2q_f16(a); } @@ -4701,7 +4695,7 @@ int64x1x2_t test_vld2_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x2_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD2_V:%.*]] = call { <4 x i16>, <4 x i16> +// CHECK: [[VLD2_V:%.*]] = call { <4 x half>, <4 x half> float16x4x2_t test_vld2_f16(float16_t const * a) { return vld2_f16(a); } @@ -4806,7 +4800,7 @@ int64x1x2_t test_vld2_dup_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x2_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x2_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD_DUP:%.*]] = call { <4 x i16>, <4 x i16> +// CHECK: [[VLD_DUP:%.*]] = call { <4 x half>, <4 x half> float16x4x2_t test_vld2_dup_f16(float16_t const * a) { return vld2_dup_f16(a); } @@ -4965,9 +4959,9 @@ int32x4x2_t test_vld2q_lane_s32(int32_t const * a, int32x4x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP7:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP8:%.*]] = bitcast <8 x half> [[TMP7]] to <16 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[VLD2Q_LANE_V:%.*]] = call { <8 x i16>, <8 x i16> +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[VLD2Q_LANE_V:%.*]] = call { <8 x half>, <8 x half> float16x8x2_t test_vld2q_lane_f16(float16_t const * a, float16x8x2_t b) { return vld2q_lane_f16(a, b, 7); } @@ -5198,9 +5192,9 @@ int32x2x2_t test_vld2_lane_s32(int32_t const * a, int32x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP7:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP8:%.*]] = bitcast <4 x half> [[TMP7]] to <8 x i8> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[VLD2_LANE_V:%.*]] = call { <4 x i16>, <4 x i16> +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[VLD2_LANE_V:%.*]] = call { <4 x half>, <4 x half> float16x4x2_t test_vld2_lane_f16(float16_t const * a, float16x4x2_t b) { return vld2_lane_f16(a, b, 3); } @@ -5337,7 +5331,7 @@ int32x4x3_t test_vld3q_s32(int32_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x3_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD3Q_V:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> +// CHECK: [[VLD3Q_V:%.*]] = call { <8 x half>, <8 x half>, <8 x half> float16x8x3_t test_vld3q_f16(float16_t const * a) { return vld3q_f16(a); } @@ -5442,7 +5436,7 @@ int64x1x3_t test_vld3_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x3_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD3_V:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[VLD3_V:%.*]] = call { <4 x half>, <4 x half>, <4 x half> float16x4x3_t test_vld3_f16(float16_t const * a) { return vld3_f16(a); } @@ -5547,7 +5541,7 @@ int64x1x3_t test_vld3_dup_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x3_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x3_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD_DUP:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[VLD_DUP:%.*]] = call { <4 x half>, <4 x half>, <4 x half> float16x4x3_t test_vld3_dup_f16(float16_t const * a) { return vld3_dup_f16(a); } @@ -5730,10 +5724,10 @@ int32x4x3_t test_vld3q_lane_s32(int32_t const * a, int32x4x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP9:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP10:%.*]] = bitcast <8 x half> [[TMP9]] to <16 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x i16> -// CHECK: [[VLD3Q_LANE_V:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x half> +// CHECK: [[VLD3Q_LANE_V:%.*]] = call { <8 x half>, <8 x half>, <8 x half> float16x8x3_t test_vld3q_lane_f16(float16_t const * a, float16x8x3_t b) { return vld3q_lane_f16(a, b, 7); } @@ -6004,10 +5998,10 @@ int32x2x3_t test_vld3_lane_s32(int32_t const * a, int32x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP9:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP10:%.*]] = bitcast <4 x half> [[TMP9]] to <8 x i8> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x i16> -// CHECK: [[VLD3_LANE_V:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x half> +// CHECK: [[VLD3_LANE_V:%.*]] = call { <4 x half>, <4 x half>, <4 x half> float16x4x3_t test_vld3_lane_f16(float16_t const * a, float16x4x3_t b) { return vld3_lane_f16(a, b, 3); } @@ -6157,7 +6151,7 @@ int32x4x4_t test_vld4q_s32(int32_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x8x4_t, align 16 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x8x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD4Q_V:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> +// CHECK: [[VLD4Q_V:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> float16x8x4_t test_vld4q_f16(float16_t const * a) { return vld4q_f16(a); } @@ -6262,7 +6256,7 @@ int64x1x4_t test_vld4_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x4_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD4_V:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[VLD4_V:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> float16x4x4_t test_vld4_f16(float16_t const * a) { return vld4_f16(a); } @@ -6367,7 +6361,7 @@ int64x1x4_t test_vld4_dup_s64(int64_t const * a) { // CHECK: [[__RET:%.*]] = alloca %struct.float16x4x4_t, align 8 // CHECK: [[TMP0:%.*]] = bitcast %struct.float16x4x4_t* [[__RET]] to i8* // CHECK: [[TMP1:%.*]] = bitcast half* %a to i8* -// CHECK: [[VLD_DUP:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[VLD_DUP:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> float16x4x4_t test_vld4_dup_f16(float16_t const * a) { return vld4_dup_f16(a); } @@ -6574,11 +6568,11 @@ int32x4x4_t test_vld4q_lane_s32(int32_t const * a, int32x4x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP11:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP12:%.*]] = bitcast <8 x half> [[TMP11]] to <16 x i8> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x i16> -// CHECK: [[TMP16:%.*]] = bitcast <16 x i8> [[TMP12]] to <8 x i16> -// CHECK: [[VLD4Q_LANE_V:%.*]] = call { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP6]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP8]] to <8 x half> +// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP10]] to <8 x half> +// CHECK: [[TMP16:%.*]] = bitcast <16 x i8> [[TMP12]] to <8 x half> +// CHECK: [[VLD4Q_LANE_V:%.*]] = call { <8 x half>, <8 x half>, <8 x half>, <8 x half> float16x8x4_t test_vld4q_lane_f16(float16_t const * a, float16x8x4_t b) { return vld4q_lane_f16(a, b, 7); } @@ -6889,11 +6883,11 @@ int32x2x4_t test_vld4_lane_s32(int32_t const * a, int32x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP11:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP12:%.*]] = bitcast <4 x half> [[TMP11]] to <8 x i8> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x i16> -// CHECK: [[TMP16:%.*]] = bitcast <8 x i8> [[TMP12]] to <4 x i16> -// CHECK: [[VLD4_LANE_V:%.*]] = call { <4 x i16>, <4 x i16>, <4 x i16>, <4 x i16> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP6]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP8]] to <4 x half> +// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP10]] to <4 x half> +// CHECK: [[TMP16:%.*]] = bitcast <8 x i8> [[TMP12]] to <4 x half> +// CHECK: [[VLD4_LANE_V:%.*]] = call { <4 x half>, <4 x half>, <4 x half>, <4 x half> float16x4x4_t test_vld4_lane_f16(float16_t const * a, float16x4x4_t b) { return vld4_lane_f16(a, b, 3); } @@ -15784,8 +15778,8 @@ void test_vst1q_s64(int64_t * a, int64x2_t b) { // CHECK-LABEL: @test_vst1q_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst1.p0i8.v8i16(i8* [[TMP0]], <8 x i16> [[TMP2]], i32 2) +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst1.p0i8.v8f16(i8* [[TMP0]], <8 x half> [[TMP2]], i32 2) // CHECK: ret void void test_vst1q_f16(float16_t * a, float16x8_t b) { vst1q_f16(a, b); @@ -15895,8 +15889,8 @@ void test_vst1_s64(int64_t * a, int64x1_t b) { // CHECK-LABEL: @test_vst1_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst1.p0i8.v4i16(i8* [[TMP0]], <4 x i16> [[TMP2]], i32 2) +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst1.p0i8.v4f16(i8* [[TMP0]], <4 x half> [[TMP2]], i32 2) // CHECK: ret void void test_vst1_f16(float16_t * a, float16x4_t b) { vst1_f16(a, b); @@ -16018,10 +16012,10 @@ void test_vst1q_lane_s64(int64_t * a, int64x2_t b) { // CHECK-LABEL: @test_vst1q_lane_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <8 x half> %b to <16 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x i16> -// CHECK: [[TMP3:%.*]] = extractelement <8 x i16> [[TMP2]], i32 7 -// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: store i16 [[TMP3]], i16* [[TMP4]], align 2 +// CHECK: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <8 x half> +// CHECK: [[TMP3:%.*]] = extractelement <8 x half> [[TMP2]], i32 7 +// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: store half [[TMP3]], half* [[TMP4]], align 2 // CHECK: ret void void test_vst1q_lane_f16(float16_t * a, float16x8_t b) { vst1q_lane_f16(a, b, 7); @@ -16150,10 +16144,10 @@ void test_vst1_lane_s64(int64_t * a, int64x1_t b) { // CHECK-LABEL: @test_vst1_lane_f16( // CHECK: [[TMP0:%.*]] = bitcast half* %a to i8* // CHECK: [[TMP1:%.*]] = bitcast <4 x half> %b to <8 x i8> -// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x i16> -// CHECK: [[TMP3:%.*]] = extractelement <4 x i16> [[TMP2]], i32 3 -// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to i16* -// CHECK: store i16 [[TMP3]], i16* [[TMP4]], align 2 +// CHECK: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half> +// CHECK: [[TMP3:%.*]] = extractelement <4 x half> [[TMP2]], i32 3 +// CHECK: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to half* +// CHECK: store half [[TMP3]], half* [[TMP4]], align 2 // CHECK: ret void void test_vst1_lane_f16(float16_t * a, float16x4_t b) { vst1_lane_f16(a, b, 3); @@ -16355,9 +16349,9 @@ void test_vst2q_s32(int32_t * a, int32x4x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP6:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP7:%.*]] = bitcast <8 x half> [[TMP6]] to <16 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst2.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP8]], <8 x i16> [[TMP9]], i32 2) +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst2.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP8]], <8 x half> [[TMP9]], i32 2) // CHECK: ret void void test_vst2q_f16(float16_t * a, float16x8x2_t b) { vst2q_f16(a, b); @@ -16652,9 +16646,9 @@ void test_vst2_s64(int64_t * a, int64x1x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP6:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP7:%.*]] = bitcast <4 x half> [[TMP6]] to <8 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst2.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP8]], <4 x i16> [[TMP9]], i32 2) +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst2.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP8]], <4 x half> [[TMP9]], i32 2) // CHECK: ret void void test_vst2_f16(float16_t * a, float16x4x2_t b) { vst2_f16(a, b); @@ -16855,9 +16849,9 @@ void test_vst2q_lane_s32(int32_t * a, int32x4x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <8 x half>], [2 x <8 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP6:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX2]], align 16 // CHECK: [[TMP7:%.*]] = bitcast <8 x half> [[TMP6]] to <16 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst2lane.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP8]], <8 x i16> [[TMP9]], i32 7, i32 2) +// CHECK: [[TMP8:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP9:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst2lane.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP8]], <8 x half> [[TMP9]], i32 7, i32 2) // CHECK: ret void void test_vst2q_lane_f16(float16_t * a, float16x8x2_t b) { vst2q_lane_f16(a, b, 7); @@ -17079,9 +17073,9 @@ void test_vst2_lane_s32(int32_t * a, int32x2x2_t b) { // CHECK: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x <4 x half>], [2 x <4 x half>]* [[VAL1]], i32 0, i32 1 // CHECK: [[TMP6:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX2]], align 8 // CHECK: [[TMP7:%.*]] = bitcast <4 x half> [[TMP6]] to <8 x i8> -// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst2lane.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP8]], <4 x i16> [[TMP9]], i32 3, i32 2) +// CHECK: [[TMP8:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP9:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst2lane.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP8]], <4 x half> [[TMP9]], i32 3, i32 2) // CHECK: ret void void test_vst2_lane_f16(float16_t * a, float16x4x2_t b) { vst2_lane_f16(a, b, 3); @@ -17354,10 +17348,10 @@ void test_vst3q_s32(int32_t * a, int32x4x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP8:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP9:%.*]] = bitcast <8 x half> [[TMP8]] to <16 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst3.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP10]], <8 x i16> [[TMP11]], <8 x i16> [[TMP12]], i32 2) +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst3.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP10]], <8 x half> [[TMP11]], <8 x half> [[TMP12]], i32 2) // CHECK: ret void void test_vst3q_f16(float16_t * a, float16x8x3_t b) { vst3q_f16(a, b); @@ -17705,10 +17699,10 @@ void test_vst3_s64(int64_t * a, int64x1x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP8:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP9:%.*]] = bitcast <4 x half> [[TMP8]] to <8 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst3.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP10]], <4 x i16> [[TMP11]], <4 x i16> [[TMP12]], i32 2) +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst3.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP10]], <4 x half> [[TMP11]], <4 x half> [[TMP12]], i32 2) // CHECK: ret void void test_vst3_f16(float16_t * a, float16x4x3_t b) { vst3_f16(a, b); @@ -17946,10 +17940,10 @@ void test_vst3q_lane_s32(int32_t * a, int32x4x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <8 x half>], [3 x <8 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP8:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX4]], align 16 // CHECK: [[TMP9:%.*]] = bitcast <8 x half> [[TMP8]] to <16 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst3lane.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP10]], <8 x i16> [[TMP11]], <8 x i16> [[TMP12]], i32 7, i32 2) +// CHECK: [[TMP10:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP11:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst3lane.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP10]], <8 x half> [[TMP11]], <8 x half> [[TMP12]], i32 7, i32 2) // CHECK: ret void void test_vst3q_lane_f16(float16_t * a, float16x8x3_t b) { vst3q_lane_f16(a, b, 7); @@ -18211,10 +18205,10 @@ void test_vst3_lane_s32(int32_t * a, int32x2x3_t b) { // CHECK: [[ARRAYIDX4:%.*]] = getelementptr inbounds [3 x <4 x half>], [3 x <4 x half>]* [[VAL3]], i32 0, i32 2 // CHECK: [[TMP8:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX4]], align 8 // CHECK: [[TMP9:%.*]] = bitcast <4 x half> [[TMP8]] to <8 x i8> -// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst3lane.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP10]], <4 x i16> [[TMP11]], <4 x i16> [[TMP12]], i32 3, i32 2) +// CHECK: [[TMP10:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP11:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst3lane.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP10]], <4 x half> [[TMP11]], <4 x half> [[TMP12]], i32 3, i32 2) // CHECK: ret void void test_vst3_lane_f16(float16_t * a, float16x4x3_t b) { vst3_lane_f16(a, b, 3); @@ -18530,11 +18524,11 @@ void test_vst4q_s32(int32_t * a, int32x4x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP10:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP11:%.*]] = bitcast <8 x half> [[TMP10]] to <16 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst4.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], <8 x i16> [[TMP15]], i32 2) +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst4.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], <8 x half> [[TMP15]], i32 2) // CHECK: ret void void test_vst4q_f16(float16_t * a, float16x8x4_t b) { vst4q_f16(a, b); @@ -18935,11 +18929,11 @@ void test_vst4_s64(int64_t * a, int64x1x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP10:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP11:%.*]] = bitcast <4 x half> [[TMP10]] to <8 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst4.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], <4 x i16> [[TMP15]], i32 2) +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst4.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], <4 x half> [[TMP15]], i32 2) // CHECK: ret void void test_vst4_f16(float16_t * a, float16x4x4_t b) { vst4_f16(a, b); @@ -19214,11 +19208,11 @@ void test_vst4q_lane_s32(int32_t * a, int32x4x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <8 x half>], [4 x <8 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP10:%.*]] = load <8 x half>, <8 x half>* [[ARRAYIDX6]], align 16 // CHECK: [[TMP11:%.*]] = bitcast <8 x half> [[TMP10]] to <16 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x i16> -// CHECK: call void @llvm.arm.neon.vst4lane.p0i8.v8i16(i8* [[TMP3]], <8 x i16> [[TMP12]], <8 x i16> [[TMP13]], <8 x i16> [[TMP14]], <8 x i16> [[TMP15]], i32 7, i32 2) +// CHECK: [[TMP12:%.*]] = bitcast <16 x i8> [[TMP5]] to <8 x half> +// CHECK: [[TMP13:%.*]] = bitcast <16 x i8> [[TMP7]] to <8 x half> +// CHECK: [[TMP14:%.*]] = bitcast <16 x i8> [[TMP9]] to <8 x half> +// CHECK: [[TMP15:%.*]] = bitcast <16 x i8> [[TMP11]] to <8 x half> +// CHECK: call void @llvm.arm.neon.vst4lane.p0i8.v8f16(i8* [[TMP3]], <8 x half> [[TMP12]], <8 x half> [[TMP13]], <8 x half> [[TMP14]], <8 x half> [[TMP15]], i32 7, i32 2) // CHECK: ret void void test_vst4q_lane_f16(float16_t * a, float16x8x4_t b) { vst4q_lane_f16(a, b, 7); @@ -19520,11 +19514,11 @@ void test_vst4_lane_s32(int32_t * a, int32x2x4_t b) { // CHECK: [[ARRAYIDX6:%.*]] = getelementptr inbounds [4 x <4 x half>], [4 x <4 x half>]* [[VAL5]], i32 0, i32 3 // CHECK: [[TMP10:%.*]] = load <4 x half>, <4 x half>* [[ARRAYIDX6]], align 8 // CHECK: [[TMP11:%.*]] = bitcast <4 x half> [[TMP10]] to <8 x i8> -// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x i16> -// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x i16> -// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x i16> -// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x i16> -// CHECK: call void @llvm.arm.neon.vst4lane.p0i8.v4i16(i8* [[TMP3]], <4 x i16> [[TMP12]], <4 x i16> [[TMP13]], <4 x i16> [[TMP14]], <4 x i16> [[TMP15]], i32 3, i32 2) +// CHECK: [[TMP12:%.*]] = bitcast <8 x i8> [[TMP5]] to <4 x half> +// CHECK: [[TMP13:%.*]] = bitcast <8 x i8> [[TMP7]] to <4 x half> +// CHECK: [[TMP14:%.*]] = bitcast <8 x i8> [[TMP9]] to <4 x half> +// CHECK: [[TMP15:%.*]] = bitcast <8 x i8> [[TMP11]] to <4 x half> +// CHECK: call void @llvm.arm.neon.vst4lane.p0i8.v4f16(i8* [[TMP3]], <4 x half> [[TMP12]], <4 x half> [[TMP13]], <4 x half> [[TMP14]], <4 x half> [[TMP15]], i32 3, i32 2) // CHECK: ret void void test_vst4_lane_f16(float16_t * a, float16x4x4_t b) { vst4_lane_f16(a, b, 3); diff --git a/utils/TableGen/NeonEmitter.cpp b/utils/TableGen/NeonEmitter.cpp index 49c1edce3220..62fcccbacb55 100644 --- a/utils/TableGen/NeonEmitter.cpp +++ b/utils/TableGen/NeonEmitter.cpp @@ -860,6 +860,10 @@ void Type::applyModifier(char Mod) { Float = true; ElementBitwidth = 64; break; + case 'H': + Float = true; + ElementBitwidth = 16; + break; case 'g': if (AppliedQuad) Bitwidth /= 2; @@ -1006,7 +1010,7 @@ std::string Intrinsic::getInstTypeCode(Type T, ClassKind CK) const { } static bool isFloatingPointProtoModifier(char Mod) { - return Mod == 'F' || Mod == 'f'; + return Mod == 'F' || Mod == 'f' || Mod == 'H'; } std::string Intrinsic::getBuiltinTypeStr() { From d0f47eb94f60fa5fbe4fa1a7a7cc24405a98d4c2 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Tue, 20 Jun 2017 20:46:58 +0000 Subject: [PATCH 010/214] [clang] Fix format specifiers fixits for nested macros ExpansionLoc was previously calculated incorrectly in the case of nested macros expansions. In this diff we build the stack of expansions where the last one is the actual expansion which should be used for grouping together the edits. The definition of MacroArgUse is adjusted accordingly. Test plan: make check-all Differential revision: https://reviews.llvm.org/D34268 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305845 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Edit/EditedSource.h | 19 +++++++++++++++---- lib/Edit/EditedSource.cpp | 27 ++++++++++++++++----------- test/FixIt/fixit-format-darwin.m | 17 +++++++++++++++++ 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/include/clang/Edit/EditedSource.h b/include/clang/Edit/EditedSource.h index 970791420734..d95a0c2be805 100644 --- a/include/clang/Edit/EditedSource.h +++ b/include/clang/Edit/EditedSource.h @@ -17,6 +17,7 @@ #include "llvm/ADT/TinyPtrVector.h" #include "llvm/Support/Allocator.h" #include +#include namespace clang { class LangOptions; @@ -41,10 +42,20 @@ class EditedSource { typedef std::map FileEditsTy; FileEditsTy FileEdits; - // Location of argument use inside the macro body - typedef std::pair MacroArgUse; - llvm::DenseMap> - ExpansionToArgMap; + struct MacroArgUse { + IdentifierInfo *Identifier; + SourceLocation ImmediateExpansionLoc; + // Location of argument use inside the top-level macro + SourceLocation UseLoc; + + bool operator==(const MacroArgUse &Other) const { + return std::tie(Identifier, ImmediateExpansionLoc, UseLoc) == + std::tie(Other.Identifier, Other.ImmediateExpansionLoc, + Other.UseLoc); + } + }; + + llvm::DenseMap> ExpansionToArgMap; SmallVector, 2> CurrCommitMacroArgExps; diff --git a/lib/Edit/EditedSource.cpp b/lib/Edit/EditedSource.cpp index 03d45cf185c9..444d0393cccd 100644 --- a/lib/Edit/EditedSource.cpp +++ b/lib/Edit/EditedSource.cpp @@ -28,13 +28,18 @@ void EditedSource::deconstructMacroArgLoc(SourceLocation Loc, MacroArgUse &ArgUse) { assert(SourceMgr.isMacroArgExpansion(Loc)); SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first; - ExpansionLoc = SourceMgr.getImmediateExpansionRange(DefArgLoc).first; + SourceLocation ImmediateExpansionLoc = + SourceMgr.getImmediateExpansionRange(DefArgLoc).first; + ExpansionLoc = ImmediateExpansionLoc; + while (SourceMgr.isMacroBodyExpansion(ExpansionLoc)) + ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first; SmallString<20> Buf; StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc), Buf, SourceMgr, LangOpts); - ArgUse = {nullptr, SourceLocation()}; + ArgUse = MacroArgUse{nullptr, SourceLocation(), SourceLocation()}; if (!ArgName.empty()) - ArgUse = {&IdentTable.get(ArgName), SourceMgr.getSpellingLoc(DefArgLoc)}; + ArgUse = {&IdentTable.get(ArgName), ImmediateExpansionLoc, + SourceMgr.getSpellingLoc(DefArgLoc)}; } void EditedSource::startingCommit() {} @@ -69,10 +74,11 @@ bool EditedSource::canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs) { deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse); auto I = ExpansionToArgMap.find(ExpLoc.getRawEncoding()); if (I != ExpansionToArgMap.end() && - std::find_if( - I->second.begin(), I->second.end(), [&](const MacroArgUse &U) { - return ArgUse.first == U.first && ArgUse.second != U.second; - }) != I->second.end()) { + find_if(I->second, [&](const MacroArgUse &U) { + return ArgUse.Identifier == U.Identifier && + std::tie(ArgUse.ImmediateExpansionLoc, ArgUse.UseLoc) != + std::tie(U.ImmediateExpansionLoc, U.UseLoc); + }) != I->second.end()) { // Trying to write in a macro argument input that has already been // written by a previous commit for another expansion of the same macro // argument name. For example: @@ -89,7 +95,6 @@ bool EditedSource::canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs) { return false; } } - return true; } @@ -102,13 +107,13 @@ bool EditedSource::commitInsert(SourceLocation OrigLoc, return true; if (SourceMgr.isMacroArgExpansion(OrigLoc)) { - SourceLocation ExpLoc; MacroArgUse ArgUse; + SourceLocation ExpLoc; deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse); - if (ArgUse.first) + if (ArgUse.Identifier) CurrCommitMacroArgExps.emplace_back(ExpLoc, ArgUse); } - + FileEdit &FA = FileEdits[Offs]; if (FA.Text.empty()) { FA.Text = copyString(text); diff --git a/test/FixIt/fixit-format-darwin.m b/test/FixIt/fixit-format-darwin.m index bfc71291a5c3..077cc0cf21bc 100644 --- a/test/FixIt/fixit-format-darwin.m +++ b/test/FixIt/fixit-format-darwin.m @@ -57,3 +57,20 @@ void test() { Log3("test 7: %s", getNSInteger(), getNSUInteger()); // CHECK: Log3("test 7: %ld", (long)getNSInteger(), (unsigned long)getNSUInteger()); } + +#define Outer1(...) \ +do { \ + printf(__VA_ARGS__); \ +} while (0) + +#define Outer2(...) \ +do { \ + Outer1(__VA_ARGS__); Outer1(__VA_ARGS__); \ +} while (0) + +void bug33447() { + Outer2("test 8: %s", getNSInteger()); + // CHECK: Outer2("test 8: %ld", (long)getNSInteger()); + Outer2("test 9: %s %s", getNSInteger(), getNSInteger()); + // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); +} From 0ab73ca5bc2cdc40824782bb3ed19a11b5ca7d51 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 20 Jun 2017 21:06:00 +0000 Subject: [PATCH 011/214] Preserve CXX method overrides in ASTImporter Summary: The ASTImporter should import CXX method overrides from the source context when it imports a method decl. Reviewers: spyffe, rsmith, doug.gregor Reviewed By: spyffe Differential Revision: https://reviews.llvm.org/D34371 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305850 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDumper.cpp | 22 +++++++++++++ lib/AST/ASTImporter.cpp | 14 ++++++++ tools/clang-import-test/clang-import-test.cpp | 32 +++++++++++++------ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index d89be0d9e6fa..95a02deb33eb 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { I != E; ++I) dumpCXXCtorInitializer(*I); + if (const CXXMethodDecl *MD = dyn_cast(D)) + if (MD->size_overridden_methods() != 0) { + auto dumpOverride = + [=](const CXXMethodDecl *D) { + SplitQualType T_split = D->getType().split(); + OS << D << " " << D->getParent()->getName() << "::" + << D->getName() << " '" + << QualType::getAsString(T_split) << "'"; + }; + + dumpChild([=] { + auto FirstOverrideItr = MD->begin_overridden_methods(); + OS << "Overrides: [ "; + dumpOverride(*FirstOverrideItr); + for (const auto *Override : + llvm::make_range(FirstOverrideItr + 1, + MD->end_overridden_methods())) + dumpOverride(Override); + OS << " ]"; + }); + } + if (D->doesThisDeclarationHaveABody()) dumpStmt(D->getBody()); } diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 493cb6df8b83..6e33b98d2f18 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -319,6 +319,9 @@ namespace clang { bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); } + + // Importing overrides. + void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); }; } @@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { // Add this function to the lexical context. LexicalDC->addDeclInternal(ToFunction); + if (auto *FromCXXMethod = dyn_cast(D)) + ImportOverrides(cast(ToFunction), FromCXXMethod); + return ToFunction; } @@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( Replacement); } +void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, + CXXMethodDecl *FromMethod) { + for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) + ToMethod->addOverriddenMethod( + cast(Importer.Import(const_cast( + FromOverriddenMethod)))); +} + ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport) diff --git a/tools/clang-import-test/clang-import-test.cpp b/tools/clang-import-test/clang-import-test.cpp index 567a4bb4f0a2..db4dc76eded5 100644 --- a/tools/clang-import-test/clang-import-test.cpp +++ b/tools/clang-import-test/clang-import-test.cpp @@ -17,7 +17,9 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" @@ -51,6 +53,10 @@ static llvm::cl::list llvm::cl::desc("Argument to pass to the CompilerInvocation"), llvm::cl::CommaSeparated); +static llvm::cl::opt +DumpAST("dump-ast", llvm::cl::init(false), + llvm::cl::desc("Dump combined AST")); + namespace init_convenience { class TestDiagnosticConsumer : public DiagnosticConsumer { private: @@ -233,7 +239,7 @@ std::unique_ptr BuildIndirect(std::unique_ptr> Parse(const std::string &Path, - llvm::ArrayRef> Imports) { + llvm::ArrayRef> Imports, + bool ShouldDumpAST) { std::vector ClangArgv(ClangArgs.size()); std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), [](const std::string &s) -> const char * { return s.data(); }); @@ -261,14 +268,20 @@ Parse(const std::string &Path, if (Imports.size()) AddExternalSource(*CI, Imports); + std::vector> ASTConsumers; + auto LLVMCtx = llvm::make_unique(); - std::unique_ptr CG = - init_convenience::BuildCodeGen(*CI, *LLVMCtx); - CG->Initialize(CI->getASTContext()); + ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx)); + + if (ShouldDumpAST) + ASTConsumers.push_back(CreateASTDumper("", true, false, false)); CI->getDiagnosticClient().BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor()); - if (llvm::Error PE = ParseSource(Path, *CI, *CG)) { + MultiplexConsumer Consumers(std::move(ASTConsumers)); + Consumers.Initialize(CI->getASTContext()); + + if (llvm::Error PE = ParseSource(Path, *CI, Consumers)) { return std::move(PE); } CI->getDiagnosticClient().EndSourceFile(); @@ -288,7 +301,8 @@ int main(int argc, const char **argv) { llvm::cl::ParseCommandLineOptions(argc, argv); std::vector> ImportCIs; for (auto I : Imports) { - llvm::Expected> ImportCI = Parse(I, {}); + llvm::Expected> ImportCI = + Parse(I, {}, false); if (auto E = ImportCI.takeError()) { llvm::errs() << llvm::toString(std::move(E)); exit(-1); @@ -310,7 +324,7 @@ int main(int argc, const char **argv) { } } llvm::Expected> ExpressionCI = - Parse(Expression, Direct ? ImportCIs : IndirectCIs); + Parse(Expression, Direct ? ImportCIs : IndirectCIs, DumpAST); if (auto E = ExpressionCI.takeError()) { llvm::errs() << llvm::toString(std::move(E)); exit(-1); From ef25b54038b3f1b9cc9153c1a9d331ff160b5f5c Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 20 Jun 2017 21:30:43 +0000 Subject: [PATCH 012/214] Special-case handling of destructors in override lists when dumping ASTs. Fixes a bug in r305850: CXXDestructors don't have names, so we need to handle printing of them separately. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305860 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDumper.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 95a02deb33eb..4758109fbcf7 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -1189,9 +1189,12 @@ void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { auto dumpOverride = [=](const CXXMethodDecl *D) { SplitQualType T_split = D->getType().split(); - OS << D << " " << D->getParent()->getName() << "::" - << D->getName() << " '" - << QualType::getAsString(T_split) << "'"; + OS << D << " " << D->getParent()->getName() << "::"; + if (isa(D)) + OS << "~" << D->getParent()->getName(); + else + OS << D->getName(); + OS << " '" << QualType::getAsString(T_split) << "'"; }; dumpChild([=] { From 5fe13167ad3f78e00849faebda2a29bfd901c617 Mon Sep 17 00:00:00 2001 From: Sunil Srivastava Date: Tue, 20 Jun 2017 22:08:44 +0000 Subject: [PATCH 013/214] Prevent devirtualization of calls to un-instantiated functions. PR 27895 Differential Revision: https://reviews.llvm.org/D22057 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305862 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 11 +++++ lib/CodeGen/CGClass.cpp | 13 +++++- lib/Sema/Sema.cpp | 3 ++ lib/Sema/SemaExpr.cpp | 1 + lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 ++ test/CodeGen/no-devirt.cpp | 59 ++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/no-devirt.cpp diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 9d49bac26a86..b15c9d3f1ee8 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1656,6 +1656,7 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, unsigned HasImplicitReturnZero : 1; unsigned IsLateTemplateParsed : 1; unsigned IsConstexpr : 1; + unsigned InstantiationIsPending:1; /// \brief Indicates if the function uses __try. unsigned UsesSEHTry : 1; @@ -1751,6 +1752,7 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, IsDeleted(false), IsTrivial(false), IsDefaulted(false), IsExplicitlyDefaulted(false), HasImplicitReturnZero(false), IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified), + InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false), EndRangeLoc(NameInfo.getEndLoc()), TemplateOrSpecialization(), DNLoc(NameInfo.getInfo()) {} @@ -1943,6 +1945,15 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, bool isConstexpr() const { return IsConstexpr; } void setConstexpr(bool IC) { IsConstexpr = IC; } + /// \brief Whether the instantiation of this function is pending. + /// This bit is set when the decision to instantiate this function is made + /// and unset if and when the function body is created. That leaves out + /// cases where instantiation did not happen because the template definition + /// was not seen in this TU. This bit remains set in those cases, under the + /// assumption that the instantiation will happen in some other TU. + bool instantiationIsPending() const { return InstantiationIsPending; } + void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; } + /// \brief Indicates the function uses __try. bool usesSEHTry() const { return UsesSEHTry; } void setUsesSEHTry(bool UST) { UsesSEHTry = UST; } diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 5b4dc5ff0ab3..127d7df348ee 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -2770,10 +2770,19 @@ CodeGenFunction::CanDevirtualizeMemberFunctionCall(const Expr *Base, // We can devirtualize calls on an object accessed by a class member access // expression, since by C++11 [basic.life]p6 we know that it can't refer to - // a derived class object constructed in the same location. + // a derived class object constructed in the same location. However, we avoid + // devirtualizing a call to a template function that we could instantiate + // implicitly, but have not decided to do so. This is needed because if this + // function does not get instantiated, the devirtualization will create a + // direct call to a function whose body may not exist. In contrast, calls to + // template functions that are not defined in this TU are allowed to be + // devirtualized under assumption that it is user responsibility to + // instantiate them in some other TU. if (const MemberExpr *ME = dyn_cast(Base)) if (const ValueDecl *VD = dyn_cast(ME->getMemberDecl())) - return VD->getType()->isRecordType(); + return VD->getType()->isRecordType() && + (MD->instantiationIsPending() || MD->isDefined() || + !MD->isImplicitlyInstantiable()); // Likewise for calls on an object accessed by a (non-reference) pointer to // member access. diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index e7b0914641ff..007a5e483e6c 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -740,6 +740,9 @@ void Sema::ActOnEndOfTranslationUnit() { // Load pending instantiations from the external source. SmallVector Pending; ExternalSource->ReadPendingInstantiations(Pending); + for (auto PII : Pending) + if (auto Func = dyn_cast(PII.first)) + Func->setInstantiationIsPending(true); PendingInstantiations.insert(PendingInstantiations.begin(), Pending.begin(), Pending.end()); } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 75a6903392ea..f49df6b3216d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -13732,6 +13732,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, // call to such a function. InstantiateFunctionDefinition(PointOfInstantiation, Func); else { + Func->setInstantiationIsPending(true); PendingInstantiations.push_back(std::make_pair(Func, PointOfInstantiation)); // Notify the consumer that a function was implicitly instantiated. diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 148ce24293a0..c58122cd271b 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3782,6 +3782,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Try again at the end of the translation unit (at which point a // definition will be required). assert(!Recursive); + Function->setInstantiationIsPending(true); PendingInstantiations.push_back( std::make_pair(Function, PointOfInstantiation)); } else if (TSK == TSK_ImplicitInstantiation) { @@ -3801,6 +3802,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Postpone late parsed template instantiations. if (PatternDecl->isLateTemplateParsed() && !LateTemplateParser) { + Function->setInstantiationIsPending(true); PendingInstantiations.push_back( std::make_pair(Function, PointOfInstantiation)); return; @@ -5146,6 +5148,8 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) { TSK_ExplicitInstantiationDefinition; InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true, DefinitionRequired, true); + if (Function->isDefined()) + Function->setInstantiationIsPending(false); continue; } diff --git a/test/CodeGen/no-devirt.cpp b/test/CodeGen/no-devirt.cpp new file mode 100644 index 000000000000..4333b7cde7c6 --- /dev/null +++ b/test/CodeGen/no-devirt.cpp @@ -0,0 +1,59 @@ +// RUN: %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s + +// Test with decls and template defs in pch, and just use in .cpp +// RUN: %clang_cc1 %s -DTMPL_DEF_IN_HEADER -triple %itanium_abi_triple -emit-pch -o %t +// RUN: %clang_cc1 %s -DTMPL_DEF_IN_HEADER -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s + +// Test with A in pch, and B and C in main +// Test with just decls in pch, and template defs and use in .cpp +// RUN: %clang_cc1 %s -triple %itanium_abi_triple -emit-pch -o %t +// RUN: %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s + +#ifndef HEADER +#define HEADER +template < typename T, int N = 0 > class TmplWithArray { +public: + virtual T& operator [] (int idx); + virtual T& func1 (int idx); + virtual T& func2 (int idx); + T ar[N+1]; +}; +struct Wrapper { + TmplWithArray data; + bool indexIt(int a) { + if (a > 6) return data[a] ; // Should not devirtualize + if (a > 4) return data.func1(a); // Should devirtualize + return data.func2(a); // Should devirtualize + } +}; + +#ifdef TMPL_DEF_IN_HEADER +template T& TmplWithArray::operator[](int idx) { + return ar[idx]; +} +template T& TmplWithArray::func1(int idx) { + return ar[idx]; +} +#endif // TMPL_DEF_IN_HEADER +#endif // HEADER + +#ifdef USEIT +#ifndef TMPL_DEF_IN_HEADER +template T& TmplWithArray::operator[](int idx) { + return ar[idx]; +} +template T& TmplWithArray::func1(int idx) { + return ar[idx]; +} +#endif // !TMPL_DEF_IN_HEADER +extern Wrapper ew; +bool stuff(int p) +{ + return ew.indexIt(p); +} +#endif + +// CHECK-NOT: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func1Ei +// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func2Ei + From 2738ea8d9122685b83694033e6c8c26fade29bfe Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 21 Jun 2017 01:43:13 +0000 Subject: [PATCH 014/214] [ODRHash] Supply more information when generic error message is emitted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305872 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSerializationKinds.td | 5 +++++ lib/Serialization/ASTReader.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/clang/Basic/DiagnosticSerializationKinds.td b/include/clang/Basic/DiagnosticSerializationKinds.td index 0a59a633232c..3c64ebb9c7f4 100644 --- a/include/clang/Basic/DiagnosticSerializationKinds.td +++ b/include/clang/Basic/DiagnosticSerializationKinds.td @@ -112,8 +112,13 @@ def note_module_odr_violation_possible_decl : Note< def err_module_odr_violation_different_definitions : Error< "%q0 has different definitions in different modules; " "%select{definition in module '%2' is here|defined here}1">; +def note_first_module_difference : Note< + "in first definition, possible difference is here">; def note_module_odr_violation_different_definitions : Note< "definition in module '%0' is here">; +def note_second_module_difference : Note< + "in second definition, possible difference is here">; + def err_module_odr_violation_different_instantiations : Error< "instantiation of %q0 is different in different modules">; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index eeb0132c1690..d033a9b32c0f 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -9324,9 +9324,20 @@ void ASTReader::diagnoseOdrViolations() { diag::err_module_odr_violation_different_definitions) << FirstRecord << FirstModule.empty() << FirstModule; + if (FirstDecl) { + Diag(FirstDecl->getLocation(), diag::note_first_module_difference) + << FirstRecord << FirstDecl->getSourceRange(); + } + Diag(SecondRecord->getLocation(), diag::note_module_odr_violation_different_definitions) << SecondModule; + + if (SecondDecl) { + Diag(SecondDecl->getLocation(), diag::note_second_module_difference) + << SecondDecl->getSourceRange(); + } + Diagnosed = true; break; } From 508d7a39264c27fde8c49b86479104d42c7f5492 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Wed, 21 Jun 2017 02:20:40 +0000 Subject: [PATCH 015/214] Run dos2unix on ms-intrinsics-rotations.c test. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305874 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/ms-intrinsics-rotations.c | 342 ++++++++++++------------- 1 file changed, 171 insertions(+), 171 deletions(-) diff --git a/test/CodeGen/ms-intrinsics-rotations.c b/test/CodeGen/ms-intrinsics-rotations.c index 65d25cbe85eb..cf9f9be7c9eb 100644 --- a/test/CodeGen/ms-intrinsics-rotations.c +++ b/test/CodeGen/ms-intrinsics-rotations.c @@ -1,181 +1,181 @@ // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple i686--windows -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple thumbv7--windows -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple x86_64--windows -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple i686--linux -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple x86_64--linux -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG - -// rotate left - -unsigned char test_rotl8(unsigned char value, unsigned char shift) { - return _rotl8(value, shift); -} -// CHECK: i8 @test_rotl8 -// CHECK: [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]] -// CHECK: ret i8 [[RESULT]] -// CHECK } - -unsigned short test_rotl16(unsigned short value, unsigned char shift) { - return _rotl16(value, shift); -} -// CHECK: i16 @test_rotl16 -// CHECK: [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]] -// CHECK: ret i16 [[RESULT]] -// CHECK } - -unsigned int test_rotl(unsigned int value, int shift) { - return _rotl(value, shift); -} -// CHECK: i32 @test_rotl -// CHECK: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] -// CHECK: ret i32 [[RESULT]] -// CHECK } - -unsigned long test_lrotl(unsigned long value, int shift) { - return _lrotl(value, shift); -} -// CHECK-32BIT-LONG: i32 @test_lrotl -// CHECK-32BIT-LONG: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 -// CHECK-32BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] -// CHECK-32BIT-LONG: [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-32BIT-LONG: [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]] -// CHECK-32BIT-LONG: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] -// CHECK-32BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 -// CHECK-32BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] -// CHECK-32BIT-LONG: ret i32 [[RESULT]] -// CHECK-32BIT-LONG } - -// CHECK-64BIT-LONG: i64 @test_lrotl -// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]] -// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK-64BIT-LONG: ret i64 [[RESULT]] -// CHECK-64BIT-LONG } - -unsigned __int64 test_rotl64(unsigned __int64 value, int shift) { - return _rotl64(value, shift); -} -// CHECK: i64 @test_rotl64 -// CHECK: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK: ret i64 [[RESULT]] -// CHECK } - -// rotate right - -unsigned char test_rotr8(unsigned char value, unsigned char shift) { - return _rotr8(value, shift); -} -// CHECK: i8 @test_rotr8 -// CHECK: [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i8 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i8 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]] -// CHECK: ret i8 [[RESULT]] -// CHECK } - -unsigned short test_rotr16(unsigned short value, unsigned char shift) { - return _rotr16(value, shift); -} -// CHECK: i16 @test_rotr16 -// CHECK: [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i16 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i16 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]] -// CHECK: ret i16 [[RESULT]] -// CHECK } - -unsigned int test_rotr(unsigned int value, int shift) { - return _rotr(value, shift); -} -// CHECK: i32 @test_rotr -// CHECK: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i32 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i32 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] -// CHECK: ret i32 [[RESULT]] -// CHECK } - -unsigned long test_lrotr(unsigned long value, int shift) { - return _lrotr(value, shift); -} -// CHECK-32BIT-LONG: i32 @test_lrotr -// CHECK-32BIT-LONG: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 -// CHECK-32BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] -// CHECK-32BIT-LONG: [[LOW:%[0-9]+]] = lshr i32 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-32BIT-LONG: [[HIGH:%[0-9]+]] = shl i32 [[VALUE]], [[NEGSHIFT]] -// CHECK-32BIT-LONG: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] -// CHECK-32BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 -// CHECK-32BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] -// CHECK-32BIT-LONG: ret i32 [[RESULT]] -// CHECK-32BIT-LONG } - -// CHECK-64BIT-LONG: i64 @test_lrotr -// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]] -// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK-64BIT-LONG: ret i64 [[RESULT]] -// CHECK-64BIT-LONG } - -unsigned __int64 test_rotr64(unsigned __int64 value, int shift) { - return _rotr64(value, shift); -} -// CHECK: i64 @test_rotr64 -// CHECK: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK: [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK: [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]] -// CHECK: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK: ret i64 [[RESULT]] -// CHECK } +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG + +// rotate left + +unsigned char test_rotl8(unsigned char value, unsigned char shift) { + return _rotl8(value, shift); +} +// CHECK: i8 @test_rotl8 +// CHECK: [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]] +// CHECK: ret i8 [[RESULT]] +// CHECK } + +unsigned short test_rotl16(unsigned short value, unsigned char shift) { + return _rotl16(value, shift); +} +// CHECK: i16 @test_rotl16 +// CHECK: [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]] +// CHECK: ret i16 [[RESULT]] +// CHECK } + +unsigned int test_rotl(unsigned int value, int shift) { + return _rotl(value, shift); +} +// CHECK: i32 @test_rotl +// CHECK: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] +// CHECK: ret i32 [[RESULT]] +// CHECK } + +unsigned long test_lrotl(unsigned long value, int shift) { + return _lrotl(value, shift); +} +// CHECK-32BIT-LONG: i32 @test_lrotl +// CHECK-32BIT-LONG: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 +// CHECK-32BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] +// CHECK-32BIT-LONG: [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK-32BIT-LONG: [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]] +// CHECK-32BIT-LONG: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] +// CHECK-32BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 +// CHECK-32BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] +// CHECK-32BIT-LONG: ret i32 [[RESULT]] +// CHECK-32BIT-LONG } + +// CHECK-64BIT-LONG: i64 @test_lrotl +// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 +// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] +// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]] +// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] +// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 +// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] +// CHECK-64BIT-LONG: ret i64 [[RESULT]] +// CHECK-64BIT-LONG } + +unsigned __int64 test_rotl64(unsigned __int64 value, int shift) { + return _rotl64(value, shift); +} +// CHECK: i64 @test_rotl64 +// CHECK: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] +// CHECK: ret i64 [[RESULT]] +// CHECK } + +// rotate right + +unsigned char test_rotr8(unsigned char value, unsigned char shift) { + return _rotr8(value, shift); +} +// CHECK: i8 @test_rotr8 +// CHECK: [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i8 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i8 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]] +// CHECK: ret i8 [[RESULT]] +// CHECK } + +unsigned short test_rotr16(unsigned short value, unsigned char shift) { + return _rotr16(value, shift); +} +// CHECK: i16 @test_rotr16 +// CHECK: [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i16 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i16 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]] +// CHECK: ret i16 [[RESULT]] +// CHECK } + +unsigned int test_rotr(unsigned int value, int shift) { + return _rotr(value, shift); +} +// CHECK: i32 @test_rotr +// CHECK: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i32 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i32 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] +// CHECK: ret i32 [[RESULT]] +// CHECK } + +unsigned long test_lrotr(unsigned long value, int shift) { + return _lrotr(value, shift); +} +// CHECK-32BIT-LONG: i32 @test_lrotr +// CHECK-32BIT-LONG: [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31 +// CHECK-32BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]] +// CHECK-32BIT-LONG: [[LOW:%[0-9]+]] = lshr i32 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK-32BIT-LONG: [[HIGH:%[0-9]+]] = shl i32 [[VALUE]], [[NEGSHIFT]] +// CHECK-32BIT-LONG: [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]] +// CHECK-32BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0 +// CHECK-32BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]] +// CHECK-32BIT-LONG: ret i32 [[RESULT]] +// CHECK-32BIT-LONG } + +// CHECK-64BIT-LONG: i64 @test_lrotr +// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 +// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] +// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]] +// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] +// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 +// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] +// CHECK-64BIT-LONG: ret i64 [[RESULT]] +// CHECK-64BIT-LONG } + +unsigned __int64 test_rotr64(unsigned __int64 value, int shift) { + return _rotr64(value, shift); +} +// CHECK: i64 @test_rotr64 +// CHECK: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 +// CHECK: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] +// CHECK: [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]] +// CHECK: [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]] +// CHECK: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] +// CHECK: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 +// CHECK: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] +// CHECK: ret i64 [[RESULT]] +// CHECK } From 480d0489f42b284040788a71146d71a9f52d9c83 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Wed, 21 Jun 2017 02:20:46 +0000 Subject: [PATCH 016/214] Support MS builtins using 'long' on LP64 platforms This allows for -fms-extensions to work the same on LP64. For example, _BitScanReverse is expected to be 32-bit, matching Windows/LLP64, even though long is 64-bit on x86_64 Darwin or Linux (LP64). Implement this by adding a new character code 'N', which is 'int' if the target is LP64 and the same 'L' otherwise Differential Revision: https://reviews.llvm.org/D34377 rdar://problem/32599746 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305875 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Builtins.def | 31 ++--- include/clang/Basic/BuiltinsARM.def | 8 +- include/clang/Basic/BuiltinsX86.def | 20 +-- include/clang/Basic/BuiltinsX86_64.def | 4 +- lib/AST/ASTContext.cpp | 14 ++- test/CodeGen/ms-intrinsics-other.c | 161 +++++++++++++++++++++++++ test/CodeGen/ms-intrinsics-rotations.c | 38 ++---- test/CodeGen/pr27892.c | 23 ---- 8 files changed, 219 insertions(+), 80 deletions(-) create mode 100644 test/CodeGen/ms-intrinsics-other.c delete mode 100644 test/CodeGen/pr27892.c diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index a9ec172422ab..75781dc7491d 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -52,6 +52,7 @@ // LL -> long long // LLL -> __int128_t (e.g. LLLi) // W -> int64_t +// N -> 'int' size if target is LP64, 'L' otherwise. // S -> signed // U -> unsigned // I -> Required to constant fold to an integer constant expression. @@ -718,11 +719,11 @@ BUILTIN(__builtin_rindex, "c*cC*i", "Fn") LANGBUILTIN(_alloca, "v*z", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__assume, "vb", "n", ALL_MS_LANGUAGES) LIBBUILTIN(_byteswap_ushort, "UsUs", "fnc", "stdlib.h", ALL_MS_LANGUAGES) -LIBBUILTIN(_byteswap_ulong, "ULiULi", "fnc", "stdlib.h", ALL_MS_LANGUAGES) +LIBBUILTIN(_byteswap_ulong, "UNiUNi", "fnc", "stdlib.h", ALL_MS_LANGUAGES) LIBBUILTIN(_byteswap_uint64, "ULLiULLi", "fnc", "stdlib.h", ALL_MS_LANGUAGES) LANGBUILTIN(__debugbreak, "v", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(__exception_code, "ULi", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_exception_code, "ULi", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(__exception_code, "UNi", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_exception_code, "UNi", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__exception_info, "v*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_exception_info, "v*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__abnormal_termination, "i", "n", ALL_MS_LANGUAGES) @@ -730,33 +731,33 @@ LANGBUILTIN(_abnormal_termination, "i", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__GetExceptionInfo, "v*.", "ntu", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedAnd8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedAnd16, "ssD*s", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedAnd, "LiLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedAnd, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedCompareExchange8, "ccD*cc", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedCompareExchange16, "ssD*ss", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedCompareExchange, "LiLiD*LiLi", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedCompareExchange, "NiNiD*NiNi", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedCompareExchange64, "LLiLLiD*LLiLLi", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedDecrement16, "ssD*", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedDecrement, "LiLiD*", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedExchange, "LiLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedDecrement, "NiNiD*", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedExchange, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchange8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchange16, "ssD*s", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchangeAdd8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchangeAdd16, "ssD*s", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedExchangeAdd, "LiLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedExchangeAdd, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchangePointer, "v*v*D*v*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchangeSub8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedExchangeSub16, "ssD*s", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedExchangeSub, "LiLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedExchangeSub, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedIncrement16, "ssD*", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedIncrement, "LiLiD*", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedIncrement, "NiNiD*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedOr8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedOr16, "ssD*s", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedOr, "LiLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedOr, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedXor8, "ccD*c", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_InterlockedXor16, "ssD*s", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_InterlockedXor, "LiLiD*Li", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_interlockedbittestandset, "UcLiD*Li", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_InterlockedXor, "NiNiD*Ni", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_interlockedbittestandset, "UcNiD*Ni", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__noop, "i.", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES) LANGBUILTIN(__popcnt, "UiUi", "nc", ALL_MS_LANGUAGES) @@ -765,12 +766,12 @@ LANGBUILTIN(_ReturnAddress, "v*", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotl8, "UcUcUc", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotl16, "UsUsUc", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotl, "UiUii", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_lrotl, "ULiULii", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_lrotl, "UNiUNii", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotl64, "ULLiULLii", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotr8, "UcUcUc", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotr16, "UsUsUc", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotr, "UiUii", "n", ALL_MS_LANGUAGES) -LANGBUILTIN(_lrotr, "ULiULii", "n", ALL_MS_LANGUAGES) +LANGBUILTIN(_lrotr, "UNiUNii", "n", ALL_MS_LANGUAGES) LANGBUILTIN(_rotr64, "ULLiULLii", "n", ALL_MS_LANGUAGES) LANGBUILTIN(__va_start, "vc**.", "nt", ALL_MS_LANGUAGES) LANGBUILTIN(__fastfail, "vUi", "nr", ALL_MS_LANGUAGES) diff --git a/include/clang/Basic/BuiltinsARM.def b/include/clang/Basic/BuiltinsARM.def index e8db347d4be5..4e277f8a5a6b 100644 --- a/include/clang/Basic/BuiltinsARM.def +++ b/include/clang/Basic/BuiltinsARM.def @@ -215,10 +215,10 @@ LANGBUILTIN(_MoveFromCoprocessor2, "UiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES) LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES) LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES) -TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_InterlockedAnd64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_InterlockedDecrement64, "LLiLLiD*", "nh", "intrin.h", ALL_MS_LANGUAGES, "") diff --git a/include/clang/Basic/BuiltinsX86.def b/include/clang/Basic/BuiltinsX86.def index a98c8f0a53db..4cd3f1d46473 100644 --- a/include/clang/Basic/BuiltinsX86.def +++ b/include/clang/Basic/BuiltinsX86.def @@ -1822,8 +1822,8 @@ TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx") TARGET_BUILTIN(__builtin_ia32_clzero, "vv*", "", "clzero") // MSVC -TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_ReadBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "") @@ -1838,15 +1838,15 @@ TARGET_HEADER_BUILTIN(__stosb, "vUc*Ucz", "nh", "intrin.h", ALL_MS_LANGUAGES, "" TARGET_HEADER_BUILTIN(__int2c, "v", "nr", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(__ud2, "v", "nr", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readfsbyte, "UcULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readfsword, "UsULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readfsdword, "ULiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readfsqword, "ULLiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readfsbyte, "UcUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readfsword, "UsUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readfsdword, "UNiUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readfsqword, "ULLiUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readgsbyte, "UcULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readgsword, "UsULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readgsdword, "ULiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(__readgsqword, "ULLiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readgsbyte, "UcUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readgsword, "UsUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readgsdword, "UNiUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(__readgsqword, "ULLiUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") #undef BUILTIN #undef TARGET_BUILTIN diff --git a/include/clang/Basic/BuiltinsX86_64.def b/include/clang/Basic/BuiltinsX86_64.def index 2851184c2c84..4cde153d8372 100644 --- a/include/clang/Basic/BuiltinsX86_64.def +++ b/include/clang/Basic/BuiltinsX86_64.def @@ -22,8 +22,8 @@ # define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS) #endif -TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") -TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(__mulh, "LLiLLiLLi", "nch", "intrin.h", ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nch", "intrin.h", ALL_MS_LANGUAGES, "") diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 2300801c1a9c..69767e068cb3 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -8513,7 +8513,7 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, RequiresICE = false; // Read the prefixed modifiers first. - bool Done = false; + bool Done = false, IsSpecialLong = false; while (!Done) { switch (*Str++) { default: Done = true; --Str; break; @@ -8531,12 +8531,24 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, Unsigned = true; break; case 'L': + assert(!IsSpecialLong && "Can't use 'L' with 'W' or 'N' modifiers"); assert(HowLong <= 2 && "Can't have LLLL modifier"); ++HowLong; break; + case 'N': { + // 'N' behaves like 'L' for all non LP64 targets and 'int' otherwise. + assert(!IsSpecialLong && "Can't use two 'N' or 'W' modifiers!"); + assert(HowLong == 0 && "Can't use both 'L' and 'N' modifiers!"); + IsSpecialLong = true; + if (Context.getTargetInfo().getLongWidth() == 32) + ++HowLong; + break; + } case 'W': // This modifier represents int64 type. + assert(!IsSpecialLong && "Can't use two 'N' or 'W' modifiers!"); assert(HowLong == 0 && "Can't use both 'L' and 'W' modifiers!"); + IsSpecialLong = true; switch (Context.getTargetInfo().getInt64Type()) { default: llvm_unreachable("Unexpected integer type"); diff --git a/test/CodeGen/ms-intrinsics-other.c b/test/CodeGen/ms-intrinsics-other.c new file mode 100644 index 000000000000..d23bc7301801 --- /dev/null +++ b/test/CodeGen/ms-intrinsics-other.c @@ -0,0 +1,161 @@ +// RUN: %clang_cc1 -ffreestanding -fms-extensions \ +// RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o - \ +// RUN: | FileCheck %s +// RUN: %clang_cc1 -ffreestanding -fms-extensions \ +// RUN: -triple x86_64--linux -Oz -emit-llvm %s -o - \ +// RUN: | FileCheck %s + +// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions) +#ifdef __LP64__ +#define LONG int +#else +#define LONG long +#endif + +unsigned char test_BitScanForward(unsigned LONG *Index, unsigned LONG Mask) { + return _BitScanForward(Index, Mask); +} +// CHECK: define{{.*}}i8 @test_BitScanForward(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{ +// CHECK: [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i32 %Mask, 0 +// CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]] +// CHECK: [[END_LABEL]]: +// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ] +// CHECK: ret i8 [[RESULT]] +// CHECK: [[ISNOTZERO_LABEL]]: +// CHECK: [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true) +// CHECK: store i32 [[INDEX]], i32* %Index, align 4 +// CHECK: br label %[[END_LABEL]] + +unsigned char test_BitScanReverse(unsigned LONG *Index, unsigned LONG Mask) { + return _BitScanReverse(Index, Mask); +} +// CHECK: define{{.*}}i8 @test_BitScanReverse(i32* {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{ +// CHECK: [[ISNOTZERO:%[0-9]+]] = icmp eq i32 %Mask, 0 +// CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]] +// CHECK: [[END_LABEL]]: +// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ] +// CHECK: ret i8 [[RESULT]] +// CHECK: [[ISNOTZERO_LABEL]]: +// CHECK: [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true) +// CHECK: [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31 +// CHECK: store i32 [[INDEX]], i32* %Index, align 4 +// CHECK: br label %[[END_LABEL]] + +#if defined(__x86_64__) +unsigned char test_BitScanForward64(unsigned LONG *Index, unsigned __int64 Mask) { + return _BitScanForward64(Index, Mask); +} +// CHECK: define{{.*}}i8 @test_BitScanForward64(i32* {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{ +// CHECK: [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i64 %Mask, 0 +// CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]] +// CHECK: [[END_LABEL]]: +// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ] +// CHECK: ret i8 [[RESULT]] +// CHECK: [[ISNOTZERO_LABEL]]: +// CHECK: [[INDEX:%[0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %Mask, i1 true) +// CHECK: [[TRUNC_INDEX:%[0-9]+]] = trunc i64 [[INDEX]] to i32 +// CHECK: store i32 [[TRUNC_INDEX]], i32* %Index, align 4 +// CHECK: br label %[[END_LABEL]] + +unsigned char test_BitScanReverse64(unsigned LONG *Index, unsigned __int64 Mask) { + return _BitScanReverse64(Index, Mask); +} +// CHECK: define{{.*}}i8 @test_BitScanReverse64(i32* {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{ +// CHECK: [[ISNOTZERO:%[0-9]+]] = icmp eq i64 %Mask, 0 +// CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]] +// CHECK: [[END_LABEL]]: +// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ] +// CHECK: ret i8 [[RESULT]] +// CHECK: [[ISNOTZERO_LABEL]]: +// CHECK: [[REVINDEX:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %Mask, i1 true) +// CHECK: [[TRUNC_REVINDEX:%[0-9]+]] = trunc i64 [[REVINDEX]] to i32 +// CHECK: [[INDEX:%[0-9]+]] = xor i32 [[TRUNC_REVINDEX]], 63 +// CHECK: store i32 [[INDEX]], i32* %Index, align 4 +// CHECK: br label %[[END_LABEL]] +#endif + +LONG test_InterlockedExchange(LONG volatile *value, LONG mask) { + return _InterlockedExchange(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedExchange(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw xchg i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedExchangeAdd(LONG volatile *value, LONG mask) { + return _InterlockedExchangeAdd(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedExchangeAdd(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw add i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedExchangeSub(LONG volatile *value, LONG mask) { + return _InterlockedExchangeSub(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedExchangeSub(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw sub i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedOr(LONG volatile *value, LONG mask) { + return _InterlockedOr(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedOr(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw or i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedXor(LONG volatile *value, LONG mask) { + return _InterlockedXor(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedXor(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw xor i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedAnd(LONG volatile *value, LONG mask) { + return _InterlockedAnd(value, mask); +} +// CHECK: define{{.*}}i32 @test_InterlockedAnd(i32*{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{ +// CHECK: [[RESULT:%[0-9]+]] = atomicrmw and i32* %value, i32 %mask seq_cst +// CHECK: ret i32 [[RESULT:%[0-9]+]] +// CHECK: } + +LONG test_InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG Comperand) { + return _InterlockedCompareExchange(Destination, Exchange, Comperand); +} +// CHECK: define{{.*}}i32 @test_InterlockedCompareExchange(i32*{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{ +// CHECK: [[TMP:%[0-9]+]] = cmpxchg volatile i32* %Destination, i32 %Comperand, i32 %Exchange seq_cst seq_cst +// CHECK: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0 +// CHECK: ret i32 [[RESULT]] +// CHECK: } + +LONG test_InterlockedIncrement(LONG volatile *Addend) { + return _InterlockedIncrement(Addend); +} +// CHECK: define{{.*}}i32 @test_InterlockedIncrement(i32*{{[a-z_ ]*}}%Addend){{.*}}{ +// CHECK: [[TMP:%[0-9]+]] = atomicrmw add i32* %Addend, i32 1 seq_cst +// CHECK: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1 +// CHECK: ret i32 [[RESULT]] +// CHECK: } + +LONG test_InterlockedDecrement(LONG volatile *Addend) { + return _InterlockedDecrement(Addend); +} +// CHECK: define{{.*}}i32 @test_InterlockedDecrement(i32*{{[a-z_ ]*}}%Addend){{.*}}{ +// CHECK: [[TMP:%[0-9]+]] = atomicrmw sub i32* %Addend, i32 1 seq_cst +// CHECK: [[RESULT:%[0-9]+]] = add i32 [[TMP]], -1 +// CHECK: ret i32 [[RESULT]] +// CHECK: } + +unsigned char test_interlockedbittestandset(volatile LONG *ptr, LONG bit) { + return _interlockedbittestandset(ptr, bit); +} +// CHECK-LABEL: define{{.*}} i8 @test_interlockedbittestandset +// CHECK: [[MASKBIT:%[0-9]+]] = shl i32 1, %bit +// CHECK: [[OLD:%[0-9]+]] = atomicrmw or i32* %ptr, i32 [[MASKBIT]] seq_cst +// CHECK: [[SHIFT:%[0-9]+]] = lshr i32 [[OLD]], %bit +// CHECK: [[TRUNC:%[0-9]+]] = trunc i32 [[SHIFT]] to i8 +// CHECK: [[AND:%[0-9]+]] = and i8 [[TRUNC]], 1 +// CHECK: ret i8 [[AND]] diff --git a/test/CodeGen/ms-intrinsics-rotations.c b/test/CodeGen/ms-intrinsics-rotations.c index cf9f9be7c9eb..9533e6c3c6a2 100644 --- a/test/CodeGen/ms-intrinsics-rotations.c +++ b/test/CodeGen/ms-intrinsics-rotations.c @@ -12,7 +12,17 @@ // RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ // RUN: -triple x86_64--linux -emit-llvm %s -o - \ -// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -ffreestanding -fms-extensions \ +// RUN: -triple x86_64--darwin -emit-llvm %s -o - \ +// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG + +// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions) +#ifdef __LP64__ +#define LONG int +#else +#define LONG long +#endif // rotate left @@ -58,7 +68,7 @@ unsigned int test_rotl(unsigned int value, int shift) { // CHECK: ret i32 [[RESULT]] // CHECK } -unsigned long test_lrotl(unsigned long value, int shift) { +unsigned LONG test_lrotl(unsigned LONG value, int shift) { return _lrotl(value, shift); } // CHECK-32BIT-LONG: i32 @test_lrotl @@ -72,17 +82,6 @@ unsigned long test_lrotl(unsigned long value, int shift) { // CHECK-32BIT-LONG: ret i32 [[RESULT]] // CHECK-32BIT-LONG } -// CHECK-64BIT-LONG: i64 @test_lrotl -// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]] -// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK-64BIT-LONG: ret i64 [[RESULT]] -// CHECK-64BIT-LONG } - unsigned __int64 test_rotl64(unsigned __int64 value, int shift) { return _rotl64(value, shift); } @@ -141,7 +140,7 @@ unsigned int test_rotr(unsigned int value, int shift) { // CHECK: ret i32 [[RESULT]] // CHECK } -unsigned long test_lrotr(unsigned long value, int shift) { +unsigned LONG test_lrotr(unsigned LONG value, int shift) { return _lrotr(value, shift); } // CHECK-32BIT-LONG: i32 @test_lrotr @@ -155,17 +154,6 @@ unsigned long test_lrotr(unsigned long value, int shift) { // CHECK-32BIT-LONG: ret i32 [[RESULT]] // CHECK-32BIT-LONG } -// CHECK-64BIT-LONG: i64 @test_lrotr -// CHECK-64BIT-LONG: [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63 -// CHECK-64BIT-LONG: [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]] -// CHECK-64BIT-LONG: [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]] -// CHECK-64BIT-LONG: [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]] -// CHECK-64BIT-LONG: [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]] -// CHECK-64BIT-LONG: [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0 -// CHECK-64BIT-LONG: [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]] -// CHECK-64BIT-LONG: ret i64 [[RESULT]] -// CHECK-64BIT-LONG } - unsigned __int64 test_rotr64(unsigned __int64 value, int shift) { return _rotr64(value, shift); } diff --git a/test/CodeGen/pr27892.c b/test/CodeGen/pr27892.c deleted file mode 100644 index 57722c4671ab..000000000000 --- a/test/CodeGen/pr27892.c +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-linux-gnu -fms-extensions %s -emit-llvm -o - | FileCheck %s - -long test1(long *p) { - return _InterlockedIncrement(p); -} -// CHECK-DAG: define i64 @test1( -// CHECK: %[[p_addr:.*]] = alloca i64*, align 8 -// CHECK: store i64* %p, i64** %[[p_addr]], align 8 -// CHECK: %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8 -// CHECK: %[[atomic_add:.*]] = atomicrmw add i64* %[[p_load]], i64 1 seq_cst -// CHECK: %[[res:.*]] = add i64 %[[atomic_add]], 1 -// CHECK: ret i64 %[[res]] - -long test2(long *p) { - return _InterlockedDecrement(p); -} -// CHECK-DAG: define i64 @test2( -// CHECK: %[[p_addr:.*]] = alloca i64*, align 8 -// CHECK: store i64* %p, i64** %[[p_addr]], align 8 -// CHECK: %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8 -// CHECK: %[[atomic_sub:.*]] = atomicrmw sub i64* %[[p_load]], i64 1 seq_cst -// CHECK: %[[res:.*]] = sub i64 %[[atomic_sub]], 1 -// CHECK: ret i64 %[[res]] From 03143a6b2cf3147ab92eb7836cd132fcb07947e6 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Wed, 21 Jun 2017 05:41:39 +0000 Subject: [PATCH 017/214] Changed wording in comment git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305878 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CloneDetection.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Analysis/CloneDetection.cpp b/lib/Analysis/CloneDetection.cpp index e86293a1dd0b..ee848ac711d6 100644 --- a/lib/Analysis/CloneDetection.cpp +++ b/lib/Analysis/CloneDetection.cpp @@ -635,8 +635,7 @@ void CloneConstraint::splitCloneGroups( if (Indexes[j]) continue; - // If a following StmtSequence belongs to our CloneGroup, we add it to - // it. + // If a following StmtSequence belongs to our CloneGroup, we add it. const StmtSequence &Candidate = HashGroup[j]; if (!Compare(Prototype, Candidate)) From 864bf1d491d904c009254e31be643a3af8122ef7 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Wed, 21 Jun 2017 10:24:58 +0000 Subject: [PATCH 018/214] Moved code hanlding precompiled preamble out of the ASTUnit. Reviewers: bkramer, krasimir, arphaman, akyrtzi, klimek Reviewed By: klimek Subscribers: mgorny, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34287 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305890 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 114 +-- include/clang/Frontend/PrecompiledPreamble.h | 248 ++++++ lib/Frontend/ASTUnit.cpp | 806 +++++-------------- lib/Frontend/CMakeLists.txt | 1 + lib/Frontend/PrecompiledPreamble.cpp | 561 +++++++++++++ 5 files changed, 1030 insertions(+), 700 deletions(-) create mode 100644 include/clang/Frontend/PrecompiledPreamble.h create mode 100644 lib/Frontend/PrecompiledPreamble.cpp diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index ae54d4151415..2950c31c2d3d 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -25,6 +25,7 @@ #include "clang/Lex/PreprocessingRecord.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Serialization/ASTBitCodes.h" +#include "clang/Frontend/PrecompiledPreamble.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -199,103 +200,15 @@ class ASTUnit { /// of that loading. It must be cleared when preamble is recreated. llvm::StringMap PreambleSrcLocCache; -public: - class PreambleData { - const FileEntry *File; - std::vector Buffer; - mutable unsigned NumLines; - - public: - PreambleData() : File(nullptr), NumLines(0) { } - - void assign(const FileEntry *F, const char *begin, const char *end) { - File = F; - Buffer.assign(begin, end); - NumLines = 0; - } - - void clear() { Buffer.clear(); File = nullptr; NumLines = 0; } - - size_t size() const { return Buffer.size(); } - bool empty() const { return Buffer.empty(); } - - const char *getBufferStart() const { return &Buffer[0]; } - - unsigned getNumLines() const { - if (NumLines) - return NumLines; - countLines(); - return NumLines; - } - - SourceRange getSourceRange(const SourceManager &SM) const { - SourceLocation FileLoc = SM.getLocForStartOfFile(SM.getPreambleFileID()); - return SourceRange(FileLoc, FileLoc.getLocWithOffset(size()-1)); - } - - private: - void countLines() const; - }; - - const PreambleData &getPreambleData() const { - return Preamble; - } - - /// Data used to determine if a file used in the preamble has been changed. - struct PreambleFileHash { - /// All files have size set. - off_t Size; - - /// Modification time is set for files that are on disk. For memory - /// buffers it is zero. - time_t ModTime; - - /// Memory buffers have MD5 instead of modification time. We don't - /// compute MD5 for on-disk files because we hope that modification time is - /// enough to tell if the file was changed. - llvm::MD5::MD5Result MD5; - - static PreambleFileHash createForFile(off_t Size, time_t ModTime); - static PreambleFileHash - createForMemoryBuffer(const llvm::MemoryBuffer *Buffer); - - friend bool operator==(const PreambleFileHash &LHS, - const PreambleFileHash &RHS); - - friend bool operator!=(const PreambleFileHash &LHS, - const PreambleFileHash &RHS) { - return !(LHS == RHS); - } - }; - private: - /// \brief The contents of the preamble that has been precompiled to - /// \c PreambleFile. - PreambleData Preamble; - - /// \brief Whether the preamble ends at the start of a new line. - /// - /// Used to inform the lexer as to whether it's starting at the beginning of - /// a line after skipping the preamble. - bool PreambleEndsAtStartOfLine; - - /// \brief Keeps track of the files that were used when computing the - /// preamble, with both their buffer size and their modification time. - /// - /// If any of the files have changed from one compile to the next, - /// the preamble must be thrown away. - llvm::StringMap FilesInPreamble; + /// The contents of the preamble. + llvm::Optional Preamble; /// \brief When non-NULL, this is the buffer used to store the contents of /// the main file when it has been padded for use with the precompiled /// preamble. std::unique_ptr SavedMainFileBuffer; - /// \brief When non-NULL, this is the buffer used to store the - /// contents of the preamble when it has been padded to build the - /// precompiled preamble. - std::unique_ptr PreambleBuffer; - /// \brief The number of warnings that occurred while parsing the preamble. /// /// This value will be used to restore the state of the \c DiagnosticsEngine @@ -438,21 +351,6 @@ class ASTUnit { std::unique_ptr OverrideMainBuffer, IntrusiveRefCntPtr VFS); - struct ComputedPreamble { - llvm::MemoryBuffer *Buffer; - std::unique_ptr Owner; - unsigned Size; - bool PreambleEndsAtStartOfLine; - ComputedPreamble(llvm::MemoryBuffer *Buffer, - std::unique_ptr Owner, unsigned Size, - bool PreambleEndsAtStartOfLine) - : Buffer(Buffer), Owner(std::move(Owner)), Size(Size), - PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} - }; - ComputedPreamble ComputePreamble(CompilerInvocation &Invocation, - unsigned MaxLines, - IntrusiveRefCntPtr VFS); - std::unique_ptr getMainBufferWithPrecompiledPreamble( std::shared_ptr PCHContainerOps, const CompilerInvocation &PreambleInvocationIn, @@ -607,12 +505,6 @@ class ASTUnit { void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl &Decls); - /// \brief Add a new top-level declaration, identified by its ID in - /// the precompiled preamble. - void addTopLevelDeclFromPreamble(serialization::DeclID D) { - TopLevelDeclsInPreamble.push_back(D); - } - /// \brief Retrieve a reference to the current top-level name hash value. /// /// Note: This is used internally by the top-level tracking action diff --git a/include/clang/Frontend/PrecompiledPreamble.h b/include/clang/Frontend/PrecompiledPreamble.h new file mode 100644 index 000000000000..8307392e7feb --- /dev/null +++ b/include/clang/Frontend/PrecompiledPreamble.h @@ -0,0 +1,248 @@ +//===--- PrecompiledPreamble.h - Build precompiled preambles ----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Helper class to build precompiled preamble. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H +#define LLVM_CLANG_FRONTEND_PRECOMPILED_PREAMBLE_H + +#include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/Support/MD5.h" +#include +#include +#include + +namespace llvm { +class MemoryBuffer; +} + +namespace clang { +namespace vfs { +class FileSystem; +} + +class CompilerInstance; +class CompilerInvocation; +class DeclGroupRef; +class PCHContainerOperations; + +/// A size of the preamble and a flag required by +/// PreprocessorOptions::PrecompiledPreambleBytes. +struct PreambleBounds { + PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine) + : Size(Size), PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} + + /// \brief Size of the preamble in bytes. + unsigned Size; + /// \brief Whether the preamble ends at the start of a new line. + /// + /// Used to inform the lexer as to whether it's starting at the beginning of + /// a line after skipping the preamble. + bool PreambleEndsAtStartOfLine; +}; + +/// \brief Runs lexer to compute suggested preamble bounds. +PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, + llvm::MemoryBuffer *Buffer, + unsigned MaxLines); + +class PreambleCallbacks; + +/// A class holding a PCH and all information to check whether it is valid to +/// reuse the PCH for the subsequent runs. Use BuildPreamble to create PCH and +/// CanReusePreamble + AddImplicitPreamble to make use of it. +class PrecompiledPreamble { + class TempPCHFile; + struct PreambleFileHash; + +public: + /// \brief Try to build PrecompiledPreamble for \p Invocation. See + /// BuildPreambleError for possible error codes. + /// + /// \param Invocation Original CompilerInvocation with options to compile the + /// file. + /// + /// \param MainFileBuffer Buffer with the contents of the main file. + /// + /// \param Bounds Bounds of the preamble, result of calling + /// ComputePreambleBounds. + /// + /// \param Diagnostics Diagnostics engine to be used while building the + /// preamble. + /// + /// \param VFS An instance of vfs::FileSystem to be used for file + /// accesses. + /// + /// \param PCHContainerOps An instance of PCHContainerOperations. + /// + /// \param Callbacks A set of callbacks to be executed when building + /// the preamble. + static llvm::ErrorOr + Build(const CompilerInvocation &Invocation, + const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, + DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS, + std::shared_ptr PCHContainerOps, + PreambleCallbacks &Callbacks); + + PrecompiledPreamble(PrecompiledPreamble &&) = default; + PrecompiledPreamble &operator=(PrecompiledPreamble &&) = default; + + /// PreambleBounds used to build the preamble + PreambleBounds getBounds() const; + + /// Check whether PrecompiledPreamble can be reused for the new contents(\p + /// MainFileBuffer) of the main file. + bool CanReuse(const CompilerInvocation &Invocation, + const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, + vfs::FileSystem *VFS) const; + + /// Changes options inside \p CI to use PCH from this preamble. Also remaps + /// main file to \p MainFileBuffer. + void AddImplicitPreamble(CompilerInvocation &CI, + llvm::MemoryBuffer *MainFileBuffer) const; + +private: + PrecompiledPreamble(TempPCHFile PCHFile, std::vector PreambleBytes, + bool PreambleEndsAtStartOfLine, + llvm::StringMap FilesInPreamble); + + /// A temp file that would be deleted on destructor call. If destructor is not + /// called for any reason, the file will be deleted at static objects' + /// destruction. + /// An assertion will fire if two TempPCHFiles are created with the same name, + /// so it's not intended to be used outside preamble-handling. + class TempPCHFile { + public: + // A main method used to construct TempPCHFile. + static llvm::ErrorOr CreateNewPreamblePCHFile(); + + /// Call llvm::sys::fs::createTemporaryFile to create a new temporary file. + static llvm::ErrorOr createInSystemTempDir(const Twine &Prefix, + StringRef Suffix); + /// Create a new instance of TemporaryFile for file at \p Path. Use with + /// extreme caution, there's an assertion checking that there's only a + /// single instance of TempPCHFile alive for each path. + static llvm::ErrorOr createFromCustomPath(const Twine &Path); + + private: + TempPCHFile(std::string FilePath); + + public: + TempPCHFile(TempPCHFile &&Other); + TempPCHFile &operator=(TempPCHFile &&Other); + + TempPCHFile(const TempPCHFile &) = delete; + ~TempPCHFile(); + + /// A path where temporary file is stored. + llvm::StringRef getFilePath() const; + + private: + void RemoveFileIfPresent(); + + private: + llvm::Optional FilePath; + }; + + /// Data used to determine if a file used in the preamble has been changed. + struct PreambleFileHash { + /// All files have size set. + off_t Size = 0; + + /// Modification time is set for files that are on disk. For memory + /// buffers it is zero. + time_t ModTime = 0; + + /// Memory buffers have MD5 instead of modification time. We don't + /// compute MD5 for on-disk files because we hope that modification time is + /// enough to tell if the file was changed. + llvm::MD5::MD5Result MD5 = {}; + + static PreambleFileHash createForFile(off_t Size, time_t ModTime); + static PreambleFileHash + createForMemoryBuffer(const llvm::MemoryBuffer *Buffer); + + friend bool operator==(const PreambleFileHash &LHS, + const PreambleFileHash &RHS) { + return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime && + LHS.MD5 == RHS.MD5; + } + friend bool operator!=(const PreambleFileHash &LHS, + const PreambleFileHash &RHS) { + return !(LHS == RHS); + } + }; + + /// Manages the lifetime of temporary file that stores a PCH. + TempPCHFile PCHFile; + /// Keeps track of the files that were used when computing the + /// preamble, with both their buffer size and their modification time. + /// + /// If any of the files have changed from one compile to the next, + /// the preamble must be thrown away. + llvm::StringMap FilesInPreamble; + /// The contents of the file that was used to precompile the preamble. Only + /// contains first PreambleBounds::Size bytes. Used to compare if the relevant + /// part of the file has not changed, so that preamble can be reused. + std::vector PreambleBytes; + /// See PreambleBounds::PreambleEndsAtStartOfLine + bool PreambleEndsAtStartOfLine; +}; + +/// A set of callbacks to gather useful information while building a preamble. +class PreambleCallbacks { +public: + virtual ~PreambleCallbacks() = default; + + /// Called after FrontendAction::Execute(), but before + /// FrontendAction::EndSourceFile(). Can be used to transfer ownership of + /// various CompilerInstance fields before they are destroyed. + virtual void AfterExecute(CompilerInstance &CI); + /// Called after PCH has been emitted. \p Writer may be used to retrieve + /// information about AST, serialized in PCH. + virtual void AfterPCHEmitted(ASTWriter &Writer); + /// Called for each TopLevelDecl. + /// NOTE: To allow more flexibility a custom ASTConsumer could probably be + /// used instead, but having only this method allows a simpler API. + virtual void HandleTopLevelDecl(DeclGroupRef DG); + /// Called for each macro defined in the Preamble. + /// NOTE: To allow more flexibility a custom PPCallbacks could probably be + /// used instead, but having only this method allows a simpler API. + virtual void HandleMacroDefined(const Token &MacroNameTok, + const MacroDirective *MD); +}; + +enum class BuildPreambleError { + PreambleIsEmpty = 1, + CouldntCreateTempFile, + CouldntCreateTargetInfo, + CouldntCreateVFSOverlay, + BeginSourceFileFailed, + CouldntEmitPCH +}; + +class BuildPreambleErrorCategory final : public std::error_category { +public: + const char *name() const noexcept override; + std::string message(int condition) const override; +}; + +std::error_code make_error_code(BuildPreambleError Error); +} // namespace clang + +namespace std { +template <> +struct is_error_code_enum : std::true_type {}; +} // namespace std + +#endif diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 8d139f2c0a6d..238ac3393130 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -79,17 +79,6 @@ namespace { } } }; - - struct OnDiskData { - /// \brief The file in which the precompiled preamble is stored. - std::string PreambleFile; - - /// \brief Erase the preamble file. - void CleanPreambleFile(); - - /// \brief Erase temporary files and the preamble file. - void Cleanup(); - }; template std::unique_ptr valueOrNull(llvm::ErrorOr> Val) { @@ -105,81 +94,68 @@ namespace { Output = std::move(*Val); return true; } -} -static llvm::sys::SmartMutex &getOnDiskMutex() { - static llvm::sys::SmartMutex M(/* recursive = */ true); - return M; -} +/// \brief Get a source buffer for \p MainFilePath, handling all file-to-file +/// and file-to-buffer remappings inside \p Invocation. +static std::unique_ptr +getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, + vfs::FileSystem *VFS, + StringRef FilePath) { + const auto &PreprocessorOpts = Invocation.getPreprocessorOpts(); -static void cleanupOnDiskMapAtExit(); + // Try to determine if the main file has been remapped, either from the + // command line (to another file) or directly through the compiler + // invocation (to a memory buffer). + llvm::MemoryBuffer *Buffer = nullptr; + std::unique_ptr BufferOwner; + auto FileStatus = VFS->status(FilePath); + if (FileStatus) { + llvm::sys::fs::UniqueID MainFileID = FileStatus->getUniqueID(); -typedef llvm::DenseMap> OnDiskDataMap; -static OnDiskDataMap &getOnDiskDataMap() { - static OnDiskDataMap M; - static bool hasRegisteredAtExit = false; - if (!hasRegisteredAtExit) { - hasRegisteredAtExit = true; - atexit(cleanupOnDiskMapAtExit); - } - return M; -} + // Check whether there is a file-file remapping of the main file + for (const auto &RF : PreprocessorOpts.RemappedFiles) { + std::string MPath(RF.first); + auto MPathStatus = VFS->status(MPath); + if (MPathStatus) { + llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID(); + if (MainFileID == MID) { + // We found a remapping. Try to load the resulting, remapped source. + BufferOwner = valueOrNull(VFS->getBufferForFile(RF.second)); + if (!BufferOwner) + return nullptr; + } + } + } -static void cleanupOnDiskMapAtExit() { - // Use the mutex because there can be an alive thread destroying an ASTUnit. - llvm::MutexGuard Guard(getOnDiskMutex()); - for (const auto &I : getOnDiskDataMap()) { - // We don't worry about freeing the memory associated with OnDiskDataMap. - // All we care about is erasing stale files. - I.second->Cleanup(); + // Check whether there is a file-buffer remapping. It supercedes the + // file-file remapping. + for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { + std::string MPath(RB.first); + auto MPathStatus = VFS->status(MPath); + if (MPathStatus) { + llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID(); + if (MainFileID == MID) { + // We found a remapping. + BufferOwner.reset(); + Buffer = const_cast(RB.second); + } + } + } } -} - -static OnDiskData &getOnDiskData(const ASTUnit *AU) { - // We require the mutex since we are modifying the structure of the - // DenseMap. - llvm::MutexGuard Guard(getOnDiskMutex()); - OnDiskDataMap &M = getOnDiskDataMap(); - auto &D = M[AU]; - if (!D) - D = llvm::make_unique(); - return *D; -} - -static void erasePreambleFile(const ASTUnit *AU) { - getOnDiskData(AU).CleanPreambleFile(); -} -static void removeOnDiskEntry(const ASTUnit *AU) { - // We require the mutex since we are modifying the structure of the - // DenseMap. - llvm::MutexGuard Guard(getOnDiskMutex()); - OnDiskDataMap &M = getOnDiskDataMap(); - OnDiskDataMap::iterator I = M.find(AU); - if (I != M.end()) { - I->second->Cleanup(); - M.erase(I); + // If the main source file was not remapped, load it now. + if (!Buffer && !BufferOwner) { + BufferOwner = valueOrNull(VFS->getBufferForFile(FilePath)); + if (!BufferOwner) + return nullptr; } -} - -static void setPreambleFile(const ASTUnit *AU, StringRef preambleFile) { - getOnDiskData(AU).PreambleFile = preambleFile; -} -static const std::string &getPreambleFile(const ASTUnit *AU) { - return getOnDiskData(AU).PreambleFile; + if (BufferOwner) + return BufferOwner; + if (!Buffer) + return nullptr; + return llvm::MemoryBuffer::getMemBufferCopy(Buffer->getBuffer(), FilePath); } - -void OnDiskData::CleanPreambleFile() { - if (!PreambleFile.empty()) { - llvm::sys::fs::remove(PreambleFile); - PreambleFile.clear(); - } -} - -void OnDiskData::Cleanup() { - CleanPreambleFile(); } struct ASTUnit::ASTWriterData { @@ -233,9 +209,6 @@ ASTUnit::~ASTUnit() { clearFileLevelDecls(); - // Clean up the temporary files and the preamble file. - removeOnDiskEntry(this); - // Free the buffers associated with remapped files. We are required to // perform this operation here because we explicitly request that the // compiler instance *not* free these buffers for each invocation of the @@ -575,16 +548,24 @@ class ASTInfoCollector : public ASTReaderListener { /// \brief Diagnostic consumer that saves each diagnostic it is given. class StoredDiagnosticConsumer : public DiagnosticConsumer { - SmallVectorImpl &StoredDiags; + SmallVectorImpl *StoredDiags; + SmallVectorImpl *StandaloneDiags; + const LangOptions *LangOpts; SourceManager *SourceMgr; public: - explicit StoredDiagnosticConsumer( - SmallVectorImpl &StoredDiags) - : StoredDiags(StoredDiags), SourceMgr(nullptr) {} + StoredDiagnosticConsumer( + SmallVectorImpl *StoredDiags, + SmallVectorImpl *StandaloneDiags) + : StoredDiags(StoredDiags), StandaloneDiags(StandaloneDiags), + LangOpts(nullptr), SourceMgr(nullptr) { + assert((StoredDiags || StandaloneDiags) && + "No output collections were passed to StoredDiagnosticConsumer."); + } void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP = nullptr) override { + this->LangOpts = &LangOpts; if (PP) SourceMgr = &PP->getSourceManager(); } @@ -603,8 +584,9 @@ class CaptureDroppedDiagnostics { public: CaptureDroppedDiagnostics(bool RequestCapture, DiagnosticsEngine &Diags, - SmallVectorImpl &StoredDiags) - : Diags(Diags), Client(StoredDiags), PreviousClient(nullptr) + SmallVectorImpl *StoredDiags, + SmallVectorImpl *StandaloneDiags) + : Diags(Diags), Client(StoredDiags, StandaloneDiags), PreviousClient(nullptr) { if (RequestCapture || Diags.getClient() == nullptr) { OwningPreviousClient = Diags.takeClient(); @@ -621,16 +603,35 @@ class CaptureDroppedDiagnostics { } // anonymous namespace +static ASTUnit::StandaloneDiagnostic +makeStandaloneDiagnostic(const LangOptions &LangOpts, + const StoredDiagnostic &InDiag); + void StoredDiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level Level, - const Diagnostic &Info) { + const Diagnostic &Info) { // Default implementation (Warnings/errors count). DiagnosticConsumer::HandleDiagnostic(Level, Info); // Only record the diagnostic if it's part of the source manager we know // about. This effectively drops diagnostics from modules we're building. // FIXME: In the long run, ee don't want to drop source managers from modules. - if (!Info.hasSourceManager() || &Info.getSourceManager() == SourceMgr) - StoredDiags.emplace_back(Level, Info); + if (!Info.hasSourceManager() || &Info.getSourceManager() == SourceMgr) { + StoredDiagnostic *ResultDiag = nullptr; + if (StoredDiags) { + StoredDiags->emplace_back(Level, Info); + ResultDiag = &StoredDiags->back(); + } + + if (StandaloneDiags) { + llvm::Optional StoredDiag = llvm::None; + if (!ResultDiag) { + StoredDiag.emplace(Level, Info); + ResultDiag = StoredDiag.getPointer(); + } + StandaloneDiags->push_back( + makeStandaloneDiagnostic(*LangOpts, *ResultDiag)); + } + } } IntrusiveRefCntPtr ASTUnit::getASTReader() const { @@ -665,7 +666,7 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr Diags, ASTUnit &AST, bool CaptureDiagnostics) { assert(Diags.get() && "no DiagnosticsEngine was provided"); if (CaptureDiagnostics) - Diags->setClient(new StoredDiagnosticConsumer(AST.StoredDiagnostics)); + Diags->setClient(new StoredDiagnosticConsumer(&AST.StoredDiagnostics, nullptr)); } std::unique_ptr ASTUnit::LoadFromASTFile( @@ -780,6 +781,11 @@ std::unique_ptr ASTUnit::LoadFromASTFile( namespace { +/// \brief Add the given macro to the hash of all top-level entities. +void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) { + Hash = llvm::HashString(MacroNameTok.getIdentifierInfo()->getName(), Hash); +} + /// \brief Preprocessor callback class that updates a hash value with the names /// of all macros that have been defined by the translation unit. class MacroDefinitionTrackerPPCallbacks : public PPCallbacks { @@ -790,7 +796,7 @@ class MacroDefinitionTrackerPPCallbacks : public PPCallbacks { void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override { - Hash = llvm::HashString(MacroNameTok.getIdentifierInfo()->getName(), Hash); + AddDefinedMacroToHash(MacroNameTok, Hash); } }; @@ -916,45 +922,30 @@ class TopLevelDeclTrackerAction : public ASTFrontendAction { } }; -class PrecompilePreambleAction : public ASTFrontendAction { - ASTUnit &Unit; - bool HasEmittedPreamblePCH; - +class ASTUnitPreambleCallbacks : public PreambleCallbacks { public: - explicit PrecompilePreambleAction(ASTUnit &Unit) - : Unit(Unit), HasEmittedPreamblePCH(false) {} + ASTUnitPreambleCallbacks(llvm::SmallVectorImpl &StoredDiags) + : StoredDiags(StoredDiags) {} - std::unique_ptr CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; - bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; } - void setHasEmittedPreamblePCH() { HasEmittedPreamblePCH = true; } - bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); } + unsigned getHash() const { return Hash; } - bool hasCodeCompletionSupport() const override { return false; } - bool hasASTFileSupport() const override { return false; } - TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; } -}; + std::vector takeTopLevelDecls() { return std::move(TopLevelDecls); } -class PrecompilePreambleConsumer : public PCHGenerator { - ASTUnit &Unit; - unsigned &Hash; - std::vector TopLevelDecls; - PrecompilePreambleAction *Action; - std::unique_ptr Out; + std::vector takeTopLevelDeclIDs() { + return std::move(TopLevelDeclIDs); + } -public: - PrecompilePreambleConsumer(ASTUnit &Unit, PrecompilePreambleAction *Action, - const Preprocessor &PP, StringRef isysroot, - std::unique_ptr Out) - : PCHGenerator(PP, "", isysroot, std::make_shared(), - ArrayRef>(), - /*AllowASTWithErrors=*/true), - Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action), - Out(std::move(Out)) { - Hash = 0; + void AfterPCHEmitted(ASTWriter &Writer) override { + TopLevelDeclIDs.reserve(TopLevelDecls.size()); + for (Decl *D : TopLevelDecls) { + // Invalid top-level decls may not have been serialized. + if (D->isInvalidDecl()) + continue; + TopLevelDeclIDs.push_back(Writer.getDeclID(D)); + } } - bool HandleTopLevelDecl(DeclGroupRef DG) override { + void HandleTopLevelDecl(DeclGroupRef DG) override { for (Decl *D : DG) { // FIXME: Currently ObjC method declarations are incorrectly being // reported as top-level declarations, even though their DeclContext @@ -965,59 +956,23 @@ class PrecompilePreambleConsumer : public PCHGenerator { AddTopLevelDeclarationToHash(D, Hash); TopLevelDecls.push_back(D); } - return true; } - void HandleTranslationUnit(ASTContext &Ctx) override { - PCHGenerator::HandleTranslationUnit(Ctx); - if (hasEmittedPCH()) { - // Write the generated bitstream to "Out". - *Out << getPCH(); - // Make sure it hits disk now. - Out->flush(); - // Free the buffer. - llvm::SmallVector Empty; - getPCH() = std::move(Empty); - - // Translate the top-level declarations we captured during - // parsing into declaration IDs in the precompiled - // preamble. This will allow us to deserialize those top-level - // declarations when requested. - for (Decl *D : TopLevelDecls) { - // Invalid top-level decls may not have been serialized. - if (D->isInvalidDecl()) - continue; - Unit.addTopLevelDeclFromPreamble(getWriter().getDeclID(D)); - } - - Action->setHasEmittedPreamblePCH(); - } + void HandleMacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) override { + AddDefinedMacroToHash(MacroNameTok, Hash); } + +private: + llvm::SmallVectorImpl &StoredDiags; + unsigned Hash = 0; + std::vector TopLevelDecls; + std::vector TopLevelDeclIDs; + llvm::SmallVector PreambleDiags; }; } // anonymous namespace -std::unique_ptr -PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - std::string Sysroot; - std::string OutputFile; - std::unique_ptr OS = - GeneratePCHAction::ComputeASTConsumerArguments(CI, InFile, Sysroot, - OutputFile); - if (!OS) - return nullptr; - - if (!CI.getFrontendOpts().RelocatablePCH) - Sysroot.clear(); - - CI.getPreprocessor().addPPCallbacks( - llvm::make_unique( - Unit.getCurrentTopLevelHashValue())); - return llvm::make_unique( - Unit, this, CI.getPreprocessor(), Sysroot, std::move(OS)); -} - static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag) { return StoredDiag.getLocation().isValid(); } @@ -1125,15 +1080,9 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, // If the main file has been overridden due to the use of a preamble, // make that override happen and introduce the preamble. - PreprocessorOptions &PreprocessorOpts = Clang->getPreprocessorOpts(); if (OverrideMainBuffer) { - PreprocessorOpts.addRemappedFile(OriginalSourceFile, - OverrideMainBuffer.get()); - PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size(); - PreprocessorOpts.PrecompiledPreambleBytes.second - = PreambleEndsAtStartOfLine; - PreprocessorOpts.ImplicitPCHInclude = getPreambleFile(this); - PreprocessorOpts.DisablePCHValidation = true; + assert(Preamble && "No preamble was built, but OverrideMainBuffer is not null"); + Preamble->AddImplicitPreamble(Clang->getInvocation(), OverrideMainBuffer.get()); // The stored diagnostic has the old source manager in it; update // the locations to refer into the new source manager. Since we've @@ -1186,116 +1135,6 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, return true; } -/// \brief Simple function to retrieve a path for a preamble precompiled header. -static std::string GetPreamblePCHPath() { - // FIXME: This is a hack so that we can override the preamble file during - // crash-recovery testing, which is the only case where the preamble files - // are not necessarily cleaned up. - const char *TmpFile = ::getenv("CINDEXTEST_PREAMBLE_FILE"); - if (TmpFile) - return TmpFile; - - SmallString<128> Path; - llvm::sys::fs::createTemporaryFile("preamble", "pch", Path); - - return Path.str(); -} - -/// \brief Compute the preamble for the main file, providing the source buffer -/// that corresponds to the main file along with a pair (bytes, start-of-line) -/// that describes the preamble. -ASTUnit::ComputedPreamble -ASTUnit::ComputePreamble(CompilerInvocation &Invocation, unsigned MaxLines, - IntrusiveRefCntPtr VFS) { - FrontendOptions &FrontendOpts = Invocation.getFrontendOpts(); - PreprocessorOptions &PreprocessorOpts = Invocation.getPreprocessorOpts(); - - // Try to determine if the main file has been remapped, either from the - // command line (to another file) or directly through the compiler invocation - // (to a memory buffer). - llvm::MemoryBuffer *Buffer = nullptr; - std::unique_ptr BufferOwner; - std::string MainFilePath(FrontendOpts.Inputs[0].getFile()); - auto MainFileStatus = VFS->status(MainFilePath); - if (MainFileStatus) { - llvm::sys::fs::UniqueID MainFileID = MainFileStatus->getUniqueID(); - - // Check whether there is a file-file remapping of the main file - for (const auto &RF : PreprocessorOpts.RemappedFiles) { - std::string MPath(RF.first); - auto MPathStatus = VFS->status(MPath); - if (MPathStatus) { - llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID(); - if (MainFileID == MID) { - // We found a remapping. Try to load the resulting, remapped source. - BufferOwner = valueOrNull(VFS->getBufferForFile(RF.second)); - if (!BufferOwner) - return ComputedPreamble(nullptr, nullptr, 0, true); - } - } - } - - // Check whether there is a file-buffer remapping. It supercedes the - // file-file remapping. - for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { - std::string MPath(RB.first); - auto MPathStatus = VFS->status(MPath); - if (MPathStatus) { - llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID(); - if (MainFileID == MID) { - // We found a remapping. - BufferOwner.reset(); - Buffer = const_cast(RB.second); - } - } - } - } - - // If the main source file was not remapped, load it now. - if (!Buffer && !BufferOwner) { - BufferOwner = valueOrNull(VFS->getBufferForFile(FrontendOpts.Inputs[0].getFile())); - if (!BufferOwner) - return ComputedPreamble(nullptr, nullptr, 0, true); - } - - if (!Buffer) - Buffer = BufferOwner.get(); - auto Pre = Lexer::ComputePreamble(Buffer->getBuffer(), - *Invocation.getLangOpts(), MaxLines); - return ComputedPreamble(Buffer, std::move(BufferOwner), Pre.first, - Pre.second); -} - -ASTUnit::PreambleFileHash -ASTUnit::PreambleFileHash::createForFile(off_t Size, time_t ModTime) { - PreambleFileHash Result; - Result.Size = Size; - Result.ModTime = ModTime; - Result.MD5 = {}; - return Result; -} - -ASTUnit::PreambleFileHash ASTUnit::PreambleFileHash::createForMemoryBuffer( - const llvm::MemoryBuffer *Buffer) { - PreambleFileHash Result; - Result.Size = Buffer->getBufferSize(); - Result.ModTime = 0; - - llvm::MD5 MD5Ctx; - MD5Ctx.update(Buffer->getBuffer().data()); - MD5Ctx.final(Result.MD5); - - return Result; -} - -namespace clang { -bool operator==(const ASTUnit::PreambleFileHash &LHS, - const ASTUnit::PreambleFileHash &RHS) { - return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime && - LHS.MD5 == RHS.MD5; -} -} // namespace clang - static std::pair makeStandaloneRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts) { @@ -1367,135 +1206,41 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( const CompilerInvocation &PreambleInvocationIn, IntrusiveRefCntPtr VFS, bool AllowRebuild, unsigned MaxLines) { - assert(VFS && "VFS is null"); - - auto PreambleInvocation = - std::make_shared(PreambleInvocationIn); - FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts(); - PreprocessorOptions &PreprocessorOpts - = PreambleInvocation->getPreprocessorOpts(); - - ComputedPreamble NewPreamble = - ComputePreamble(*PreambleInvocation, MaxLines, VFS); - - if (!NewPreamble.Size) { - // We couldn't find a preamble in the main source. Clear out the current - // preamble, if we have one. It's obviously no good any more. - Preamble.clear(); - erasePreambleFile(this); - // The next time we actually see a preamble, precompile it. - PreambleRebuildCounter = 1; + auto MainFilePath = + PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile(); + std::unique_ptr MainFileBuffer = + getBufferForFileHandlingRemapping(PreambleInvocationIn, VFS.get(), + MainFilePath); + if (!MainFileBuffer) return nullptr; - } - - if (!Preamble.empty()) { - // We've previously computed a preamble. Check whether we have the same - // preamble now that we did before, and that there's enough space in - // the main-file buffer within the precompiled preamble to fit the - // new main file. - if (Preamble.size() == NewPreamble.Size && - PreambleEndsAtStartOfLine == NewPreamble.PreambleEndsAtStartOfLine && - memcmp(Preamble.getBufferStart(), NewPreamble.Buffer->getBufferStart(), - NewPreamble.Size) == 0) { - // The preamble has not changed. We may be able to re-use the precompiled - // preamble. - - // Check that none of the files used by the preamble have changed. - bool AnyFileChanged = false; - - // First, make a record of those files that have been overridden via - // remapping or unsaved_files. - std::map OverriddenFiles; - for (const auto &R : PreprocessorOpts.RemappedFiles) { - if (AnyFileChanged) - break; - - vfs::Status Status; - if (!moveOnNoError(VFS->status(R.second), Status)) { - // If we can't stat the file we're remapping to, assume that something - // horrible happened. - AnyFileChanged = true; - break; - } - - OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile( - Status.getSize(), - llvm::sys::toTimeT(Status.getLastModificationTime())); - } - for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { - if (AnyFileChanged) - break; + PreambleBounds Bounds = + ComputePreambleBounds(*PreambleInvocationIn.getLangOpts(), + MainFileBuffer.get(), MaxLines); + if (!Bounds.Size) + return nullptr; - vfs::Status Status; - if (!moveOnNoError(VFS->status(RB.first), Status)) { - AnyFileChanged = true; - break; - } + if (Preamble) { + if (Preamble->CanReuse(PreambleInvocationIn, MainFileBuffer.get(), Bounds, + VFS.get())) { + // Okay! We can re-use the precompiled preamble. - OverriddenFiles[Status.getUniqueID()] = - PreambleFileHash::createForMemoryBuffer(RB.second); - } - - // Check whether anything has changed. - for (llvm::StringMap::iterator - F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end(); - !AnyFileChanged && F != FEnd; - ++F) { - vfs::Status Status; - if (!moveOnNoError(VFS->status(F->first()), Status)) { - // If we can't stat the file, assume that something horrible happened. - AnyFileChanged = true; - break; - } + // Set the state of the diagnostic object to mimic its state + // after parsing the preamble. + getDiagnostics().Reset(); + ProcessWarningOptions(getDiagnostics(), + PreambleInvocationIn.getDiagnosticOpts()); + getDiagnostics().setNumWarnings(NumWarningsInPreamble); - std::map::iterator Overridden - = OverriddenFiles.find(Status.getUniqueID()); - if (Overridden != OverriddenFiles.end()) { - // This file was remapped; check whether the newly-mapped file - // matches up with the previous mapping. - if (Overridden->second != F->second) - AnyFileChanged = true; - continue; - } - - // The file was not remapped; check whether it has changed on disk. - if (Status.getSize() != uint64_t(F->second.Size) || - llvm::sys::toTimeT(Status.getLastModificationTime()) != - F->second.ModTime) - AnyFileChanged = true; - } - - if (!AnyFileChanged) { - // Okay! We can re-use the precompiled preamble. - - // Set the state of the diagnostic object to mimic its state - // after parsing the preamble. - getDiagnostics().Reset(); - ProcessWarningOptions(getDiagnostics(), - PreambleInvocation->getDiagnosticOpts()); - getDiagnostics().setNumWarnings(NumWarningsInPreamble); - - return llvm::MemoryBuffer::getMemBufferCopy( - NewPreamble.Buffer->getBuffer(), FrontendOpts.Inputs[0].getFile()); - } + PreambleRebuildCounter = 1; + return MainFileBuffer; + } else { + Preamble.reset(); + PreambleDiagnostics.clear(); + TopLevelDeclsInPreamble.clear(); + PreambleRebuildCounter = 1; } - - // If we aren't allowed to rebuild the precompiled preamble, just - // return now. - if (!AllowRebuild) - return nullptr; - - // We can't reuse the previously-computed preamble. Build a new one. - Preamble.clear(); - PreambleDiagnostics.clear(); - erasePreambleFile(this); - PreambleRebuildCounter = 1; - } else if (!AllowRebuild) { - // We aren't allowed to rebuild the precompiled preamble; just - // return now. - return nullptr; } // If the preamble rebuild counter > 1, it's because we previously @@ -1506,164 +1251,63 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( return nullptr; } - // Create a temporary file for the precompiled preamble. In rare - // circumstances, this can fail. - std::string PreamblePCHPath = GetPreamblePCHPath(); - if (PreamblePCHPath.empty()) { - // Try again next time. - PreambleRebuildCounter = 1; + assert(!Preamble && "No Preamble should be stored at that point"); + // If we aren't allowed to rebuild the precompiled preamble, just + // return now. + if (!AllowRebuild) return nullptr; - } - - // We did not previously compute a preamble, or it can't be reused anyway. - SimpleTimer PreambleTimer(WantTiming); - PreambleTimer.setOutput("Precompiling preamble"); - - // Save the preamble text for later; we'll need to compare against it for - // subsequent reparses. - StringRef MainFilename = FrontendOpts.Inputs[0].getFile(); - Preamble.assign(FileMgr->getFile(MainFilename), - NewPreamble.Buffer->getBufferStart(), - NewPreamble.Buffer->getBufferStart() + NewPreamble.Size); - PreambleEndsAtStartOfLine = NewPreamble.PreambleEndsAtStartOfLine; - - PreambleBuffer = llvm::MemoryBuffer::getMemBufferCopy( - NewPreamble.Buffer->getBuffer().slice(0, Preamble.size()), MainFilename); - - // Remap the main source file to the preamble buffer. - StringRef MainFilePath = FrontendOpts.Inputs[0].getFile(); - PreprocessorOpts.addRemappedFile(MainFilePath, PreambleBuffer.get()); - - // Tell the compiler invocation to generate a temporary precompiled header. - FrontendOpts.ProgramAction = frontend::GeneratePCH; - // FIXME: Generate the precompiled header into memory? - FrontendOpts.OutputFile = PreamblePCHPath; - PreprocessorOpts.PrecompiledPreambleBytes.first = 0; - PreprocessorOpts.PrecompiledPreambleBytes.second = false; - - // Create the compiler instance to use for building the precompiled preamble. - std::unique_ptr Clang( - new CompilerInstance(std::move(PCHContainerOps))); - // Recover resources if we crash before exiting this method. - llvm::CrashRecoveryContextCleanupRegistrar - CICleanup(Clang.get()); - - Clang->setInvocation(std::move(PreambleInvocation)); - OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile(); - - // Set up diagnostics, capturing all of the diagnostics produced. - Clang->setDiagnostics(&getDiagnostics()); - - // Create the target instance. - Clang->setTarget(TargetInfo::CreateTargetInfo( - Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); - if (!Clang->hasTarget()) { - llvm::sys::fs::remove(FrontendOpts.OutputFile); - Preamble.clear(); - PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.RemappedFileBuffers.pop_back(); - return nullptr; - } - - // Inform the target of the language options. - // - // FIXME: We shouldn't need to do this, the target should be immutable once - // created. This complexity should be lifted elsewhere. - Clang->getTarget().adjust(Clang->getLangOpts()); - - assert(Clang->getFrontendOpts().Inputs.size() == 1 && - "Invocation must have exactly one source file!"); - assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() == - InputKind::Source && - "FIXME: AST inputs not yet supported here!"); - assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != - InputKind::LLVM_IR && - "IR inputs not support here!"); - - // Clear out old caches and data. - getDiagnostics().Reset(); - ProcessWarningOptions(getDiagnostics(), Clang->getDiagnosticOpts()); - checkAndRemoveNonDriverDiags(StoredDiagnostics); - TopLevelDecls.clear(); - TopLevelDeclsInPreamble.clear(); - PreambleDiagnostics.clear(); - - VFS = createVFSFromCompilerInvocation(Clang->getInvocation(), - getDiagnostics(), VFS); - if (!VFS) - return nullptr; - - // Create a file manager object to provide access to and cache the filesystem. - Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); - - // Create the source manager. - Clang->setSourceManager(new SourceManager(getDiagnostics(), - Clang->getFileManager())); - - auto PreambleDepCollector = std::make_shared(); - Clang->addDependencyCollector(PreambleDepCollector); - - std::unique_ptr Act; - Act.reset(new PrecompilePreambleAction(*this)); - if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) { - llvm::sys::fs::remove(FrontendOpts.OutputFile); - Preamble.clear(); - PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.RemappedFileBuffers.pop_back(); - return nullptr; + SmallVector NewPreambleDiagsStandalone; + SmallVector NewPreambleDiags; + ASTUnitPreambleCallbacks Callbacks(NewPreambleDiags); + { + llvm::Optional Capture; + if (CaptureDiagnostics) + Capture.emplace(/*RequestCapture=*/true, *Diagnostics, &NewPreambleDiags, + &NewPreambleDiagsStandalone); + + // We did not previously compute a preamble, or it can't be reused anyway. + SimpleTimer PreambleTimer(WantTiming); + PreambleTimer.setOutput("Precompiling preamble"); + + llvm::ErrorOr NewPreamble = PrecompiledPreamble::Build( + PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS, + PCHContainerOps, Callbacks); + if (NewPreamble) { + Preamble = std::move(*NewPreamble); + PreambleRebuildCounter = 1; + } else { + switch (static_cast(NewPreamble.getError().value())) { + case BuildPreambleError::CouldntCreateTempFile: + case BuildPreambleError::PreambleIsEmpty: + // Try again next time. + PreambleRebuildCounter = 1; + break; + case BuildPreambleError::CouldntCreateTargetInfo: + case BuildPreambleError::BeginSourceFileFailed: + case BuildPreambleError::CouldntEmitPCH: + case BuildPreambleError::CouldntCreateVFSOverlay: + // These erros are more likely to repeat, retry after some period. + PreambleRebuildCounter = DefaultPreambleRebuildInterval; + break; + default: + llvm_unreachable("unexpected BuildPreambleError"); + } + return nullptr; + } } - - Act->Execute(); - // Transfer any diagnostics generated when parsing the preamble into the set - // of preamble diagnostics. - for (stored_diag_iterator I = stored_diag_afterDriver_begin(), - E = stored_diag_end(); - I != E; ++I) - PreambleDiagnostics.push_back( - makeStandaloneDiagnostic(Clang->getLangOpts(), *I)); + assert(Preamble && "Preamble wasn't built"); - Act->EndSourceFile(); - - checkAndRemoveNonDriverDiags(StoredDiagnostics); + TopLevelDecls.clear(); + TopLevelDeclsInPreamble = Callbacks.takeTopLevelDeclIDs(); + PreambleTopLevelHashValue = Callbacks.getHash(); - if (!Act->hasEmittedPreamblePCH()) { - // The preamble PCH failed (e.g. there was a module loading fatal error), - // so no precompiled header was generated. Forget that we even tried. - // FIXME: Should we leave a note for ourselves to try again? - llvm::sys::fs::remove(FrontendOpts.OutputFile); - Preamble.clear(); - TopLevelDeclsInPreamble.clear(); - PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.RemappedFileBuffers.pop_back(); - return nullptr; - } - - // Keep track of the preamble we precompiled. - setPreambleFile(this, FrontendOpts.OutputFile); NumWarningsInPreamble = getDiagnostics().getNumWarnings(); - - // Keep track of all of the files that the source manager knows about, - // so we can verify whether they have changed or not. - FilesInPreamble.clear(); - SourceManager &SourceMgr = Clang->getSourceManager(); - for (auto &Filename : PreambleDepCollector->getDependencies()) { - const FileEntry *File = Clang->getFileManager().getFile(Filename); - if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())) - continue; - if (time_t ModTime = File->getModificationTime()) { - FilesInPreamble[File->getName()] = PreambleFileHash::createForFile( - File->getSize(), ModTime); - } else { - llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); - FilesInPreamble[File->getName()] = - PreambleFileHash::createForMemoryBuffer(Buffer); - } - } - PreambleRebuildCounter = 1; - PreprocessorOpts.RemappedFileBuffers.pop_back(); + checkAndRemoveNonDriverDiags(NewPreambleDiags); + StoredDiagnostics = std::move(NewPreambleDiags); + PreambleDiagnostics = std::move(NewPreambleDiagsStandalone); // If the hash of top-level entities differs from the hash of the top-level // entities the last time we rebuilt the preamble, clear out the completion @@ -1673,11 +1317,12 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( PreambleTopLevelHashValue = CurrentTopLevelHashValue; } - return llvm::MemoryBuffer::getMemBufferCopy(NewPreamble.Buffer->getBuffer(), - MainFilename); + return MainFileBuffer; } void ASTUnit::RealizeTopLevelDeclsFromPreamble() { + assert(Preamble && "Should only be called when preamble was built"); + std::vector Resolved; Resolved.reserve(TopLevelDeclsInPreamble.size()); ExternalASTSource &Source = *getASTContext().getExternalSource(); @@ -1995,8 +1640,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine( { - CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags, - StoredDiagnostics); + CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags, + &StoredDiagnostics, nullptr); CI = clang::createInvocationFromCommandLine( llvm::makeArrayRef(ArgBegin, ArgEnd), Diags); @@ -2101,7 +1746,7 @@ bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps, // If we have a preamble file lying around, or if we might try to // build a precompiled preamble, do so now. std::unique_ptr OverrideMainBuffer; - if (!getPreambleFile(this).empty() || PreambleRebuildCounter > 0) + if (Preamble || PreambleRebuildCounter > 0) OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS); @@ -2435,7 +2080,7 @@ void ASTUnit::CodeComplete( Clang->setDiagnostics(&Diag); CaptureDroppedDiagnostics Capture(true, Clang->getDiagnostics(), - StoredDiagnostics); + &StoredDiagnostics, nullptr); ProcessWarningOptions(Diag, Inv.getDiagnosticOpts()); // Create the target instance. @@ -2484,7 +2129,7 @@ void ASTUnit::CodeComplete( // point is within the main file, after the end of the precompiled // preamble. std::unique_ptr OverrideMainBuffer; - if (!getPreambleFile(this).empty()) { + if (Preamble) { std::string CompleteFilePath(File); auto VFS = FileMgr.getVirtualFileSystem(); @@ -2506,14 +2151,8 @@ void ASTUnit::CodeComplete( // If the main file has been overridden due to the use of a preamble, // make that override happen and introduce the preamble. if (OverrideMainBuffer) { - PreprocessorOpts.addRemappedFile(OriginalSourceFile, - OverrideMainBuffer.get()); - PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size(); - PreprocessorOpts.PrecompiledPreambleBytes.second - = PreambleEndsAtStartOfLine; - PreprocessorOpts.ImplicitPCHInclude = getPreambleFile(this); - PreprocessorOpts.DisablePCHValidation = true; - + assert(Preamble && "No preamble was built, but OverrideMainBuffer is not null"); + Preamble->AddImplicitPreamble(Clang->getInvocation(), OverrideMainBuffer.get()); OwnedBuffers.push_back(OverrideMainBuffer.release()); } else { PreprocessorOpts.PrecompiledPreambleBytes.first = 0; @@ -2760,11 +2399,11 @@ SourceLocation ASTUnit::mapLocationFromPreamble(SourceLocation Loc) { if (SourceMgr) PreambleID = SourceMgr->getPreambleFileID(); - if (Loc.isInvalid() || Preamble.empty() || PreambleID.isInvalid()) + if (Loc.isInvalid() || !Preamble || PreambleID.isInvalid()) return Loc; unsigned Offs; - if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble.size()) { + if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble->getBounds().Size) { SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID()); return FileLoc.getLocWithOffset(Offs); @@ -2781,12 +2420,12 @@ SourceLocation ASTUnit::mapLocationToPreamble(SourceLocation Loc) { if (SourceMgr) PreambleID = SourceMgr->getPreambleFileID(); - if (Loc.isInvalid() || Preamble.empty() || PreambleID.isInvalid()) + if (Loc.isInvalid() || !Preamble || PreambleID.isInvalid()) return Loc; unsigned Offs; if (SourceMgr->isInFileID(Loc, SourceMgr->getMainFileID(), &Offs) && - Offs < Preamble.size()) { + Offs < Preamble->getBounds().Size) { SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(PreambleID); return FileLoc.getLocWithOffset(Offs); } @@ -2932,17 +2571,6 @@ InputKind ASTUnit::getInputKind() const { return InputKind(Lang, Fmt, PP); } -void ASTUnit::PreambleData::countLines() const { - NumLines = 0; - if (empty()) - return; - - NumLines = std::count(Buffer.begin(), Buffer.end(), '\n'); - - if (Buffer.back() != '\n') - ++NumLines; -} - #ifndef NDEBUG ASTUnit::ConcurrencyState::ConcurrencyState() { Mutex = new llvm::sys::MutexImpl(/*recursive=*/true); diff --git a/lib/Frontend/CMakeLists.txt b/lib/Frontend/CMakeLists.txt index 18abecd2071c..ba3bd7d28c70 100644 --- a/lib/Frontend/CMakeLists.txt +++ b/lib/Frontend/CMakeLists.txt @@ -38,6 +38,7 @@ add_clang_library(clangFrontend ModuleDependencyCollector.cpp MultiplexConsumer.cpp PCHContainerOperations.cpp + PrecompiledPreamble.cpp PrintPreprocessedOutput.cpp SerializedDiagnosticPrinter.cpp SerializedDiagnosticReader.cpp diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp new file mode 100644 index 000000000000..385e48a41057 --- /dev/null +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -0,0 +1,561 @@ +//===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Helper class to build precompiled preamble. +// +//===----------------------------------------------------------------------===// + +#include "clang/Frontend/PrecompiledPreamble.h" +#include "clang/AST/DeclObjC.h" +#include "clang/Basic/TargetInfo.h" +#include "clang/Basic/VirtualFileSystem.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/CompilerInvocation.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Frontend/FrontendOptions.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/PreprocessorOptions.h" +#include "clang/Serialization/ASTWriter.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Mutex.h" +#include "llvm/Support/MutexGuard.h" + +using namespace clang; + +namespace { + +/// Keeps a track of files to be deleted in destructor. +class TemporaryFiles { +public: + // A static instance to be used by all clients. + static TemporaryFiles &getInstance(); + +private: + // Disallow constructing the class directly. + TemporaryFiles() = default; + // Disallow copy. + TemporaryFiles(const TemporaryFiles &) = delete; + +public: + ~TemporaryFiles(); + + /// Adds \p File to a set of tracked files. + void addFile(StringRef File); + + /// Remove \p File from disk and from the set of tracked files. + void removeFile(StringRef File); + +private: + llvm::sys::SmartMutex Mutex; + llvm::StringSet<> Files; +}; + +TemporaryFiles &TemporaryFiles::getInstance() { + static TemporaryFiles Instance; + return Instance; +} + +TemporaryFiles::~TemporaryFiles() { + llvm::MutexGuard Guard(Mutex); + for (const auto &File : Files) + llvm::sys::fs::remove(File.getKey()); +} + +void TemporaryFiles::addFile(StringRef File) { + llvm::MutexGuard Guard(Mutex); + auto IsInserted = Files.insert(File).second; + assert(IsInserted && "File has already been added"); +} + +void TemporaryFiles::removeFile(StringRef File) { + llvm::MutexGuard Guard(Mutex); + auto WasPresent = Files.erase(File); + assert(WasPresent && "File was not tracked"); + llvm::sys::fs::remove(File); +} + +class PreambleMacroCallbacks : public PPCallbacks { +public: + PreambleMacroCallbacks(PreambleCallbacks &Callbacks) : Callbacks(Callbacks) {} + + void MacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) override { + Callbacks.HandleMacroDefined(MacroNameTok, MD); + } + +private: + PreambleCallbacks &Callbacks; +}; + +class PrecompilePreambleAction : public ASTFrontendAction { +public: + PrecompilePreambleAction(PreambleCallbacks &Callbacks) + : Callbacks(Callbacks) {} + + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; + + bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; } + + void setEmittedPreamblePCH(ASTWriter &Writer) { + this->HasEmittedPreamblePCH = true; + Callbacks.AfterPCHEmitted(Writer); + } + + bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); } + bool hasCodeCompletionSupport() const override { return false; } + bool hasASTFileSupport() const override { return false; } + TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; } + +private: + friend class PrecompilePreambleConsumer; + + bool HasEmittedPreamblePCH = false; + PreambleCallbacks &Callbacks; +}; + +class PrecompilePreambleConsumer : public PCHGenerator { +public: + PrecompilePreambleConsumer(PrecompilePreambleAction &Action, + const Preprocessor &PP, StringRef isysroot, + std::unique_ptr Out) + : PCHGenerator(PP, "", isysroot, std::make_shared(), + ArrayRef>(), + /*AllowASTWithErrors=*/true), + Action(Action), Out(std::move(Out)) {} + + bool HandleTopLevelDecl(DeclGroupRef DG) override { + Action.Callbacks.HandleTopLevelDecl(DG); + return true; + } + + void HandleTranslationUnit(ASTContext &Ctx) override { + PCHGenerator::HandleTranslationUnit(Ctx); + if (!hasEmittedPCH()) + return; + + // Write the generated bitstream to "Out". + *Out << getPCH(); + // Make sure it hits disk now. + Out->flush(); + // Free the buffer. + llvm::SmallVector Empty; + getPCH() = std::move(Empty); + + Action.setEmittedPreamblePCH(getWriter()); + } + +private: + PrecompilePreambleAction &Action; + std::unique_ptr Out; +}; + +std::unique_ptr +PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, + + StringRef InFile) { + std::string Sysroot; + std::string OutputFile; + std::unique_ptr OS = + GeneratePCHAction::ComputeASTConsumerArguments(CI, InFile, Sysroot, + OutputFile); + if (!OS) + return nullptr; + + if (!CI.getFrontendOpts().RelocatablePCH) + Sysroot.clear(); + + CI.getPreprocessor().addPPCallbacks( + llvm::make_unique(Callbacks)); + return llvm::make_unique( + *this, CI.getPreprocessor(), Sysroot, std::move(OS)); +} + +template bool moveOnNoError(llvm::ErrorOr Val, T &Output) { + if (!Val) + return false; + Output = std::move(*Val); + return true; +} + +} // namespace + +PreambleBounds clang::ComputePreambleBounds(const LangOptions &LangOpts, + llvm::MemoryBuffer *Buffer, + unsigned MaxLines) { + auto Pre = Lexer::ComputePreamble(Buffer->getBuffer(), LangOpts, MaxLines); + return PreambleBounds(Pre.first, Pre.second); +} + +llvm::ErrorOr PrecompiledPreamble::Build( + const CompilerInvocation &Invocation, + const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, + DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS, + std::shared_ptr PCHContainerOps, + PreambleCallbacks &Callbacks) { + assert(VFS && "VFS is null"); + + if (!Bounds.Size) + return BuildPreambleError::PreambleIsEmpty; + + auto PreambleInvocation = std::make_shared(Invocation); + FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts(); + PreprocessorOptions &PreprocessorOpts = + PreambleInvocation->getPreprocessorOpts(); + + // Create a temporary file for the precompiled preamble. In rare + // circumstances, this can fail. + llvm::ErrorOr PreamblePCHFile = + PrecompiledPreamble::TempPCHFile::CreateNewPreamblePCHFile(); + if (!PreamblePCHFile) + return BuildPreambleError::CouldntCreateTempFile; + + // Save the preamble text for later; we'll need to compare against it for + // subsequent reparses. + std::vector PreambleBytes(MainFileBuffer->getBufferStart(), + MainFileBuffer->getBufferStart() + + Bounds.Size); + bool PreambleEndsAtStartOfLine = Bounds.PreambleEndsAtStartOfLine; + + // Tell the compiler invocation to generate a temporary precompiled header. + FrontendOpts.ProgramAction = frontend::GeneratePCH; + // FIXME: Generate the precompiled header into memory? + FrontendOpts.OutputFile = PreamblePCHFile->getFilePath(); + PreprocessorOpts.PrecompiledPreambleBytes.first = 0; + PreprocessorOpts.PrecompiledPreambleBytes.second = false; + + // Create the compiler instance to use for building the precompiled preamble. + std::unique_ptr Clang( + new CompilerInstance(std::move(PCHContainerOps))); + + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar CICleanup( + Clang.get()); + + Clang->setInvocation(std::move(PreambleInvocation)); + Clang->setDiagnostics(&Diagnostics); + + // Create the target instance. + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); + if (!Clang->hasTarget()) + return BuildPreambleError::CouldntCreateTargetInfo; + + // Inform the target of the language options. + // + // FIXME: We shouldn't need to do this, the target should be immutable once + // created. This complexity should be lifted elsewhere. + Clang->getTarget().adjust(Clang->getLangOpts()); + + assert(Clang->getFrontendOpts().Inputs.size() == 1 && + "Invocation must have exactly one source file!"); + assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() == + InputKind::Source && + "FIXME: AST inputs not yet supported here!"); + assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != + InputKind::LLVM_IR && + "IR inputs not support here!"); + + // Clear out old caches and data. + Diagnostics.Reset(); + ProcessWarningOptions(Diagnostics, Clang->getDiagnosticOpts()); + + VFS = + createVFSFromCompilerInvocation(Clang->getInvocation(), Diagnostics, VFS); + if (!VFS) + return BuildPreambleError::CouldntCreateVFSOverlay; + + // Create a file manager object to provide access to and cache the filesystem. + Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); + + // Create the source manager. + Clang->setSourceManager( + new SourceManager(Diagnostics, Clang->getFileManager())); + + auto PreambleDepCollector = std::make_shared(); + Clang->addDependencyCollector(PreambleDepCollector); + + // Remap the main source file to the preamble buffer. + StringRef MainFilePath = FrontendOpts.Inputs[0].getFile(); + auto PreambleInputBuffer = llvm::MemoryBuffer::getMemBufferCopy( + MainFileBuffer->getBuffer().slice(0, Bounds.Size), MainFilePath); + if (PreprocessorOpts.RetainRemappedFileBuffers) { + // MainFileBuffer will be deleted by unique_ptr after leaving the method. + PreprocessorOpts.addRemappedFile(MainFilePath, PreambleInputBuffer.get()); + } else { + // In that case, remapped buffer will be deleted by CompilerInstance on + // BeginSourceFile, so we call release() to avoid double deletion. + PreprocessorOpts.addRemappedFile(MainFilePath, + PreambleInputBuffer.release()); + } + + std::unique_ptr Act; + Act.reset(new PrecompilePreambleAction(Callbacks)); + if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) + return BuildPreambleError::BeginSourceFileFailed; + + Act->Execute(); + + // Run the callbacks. + Callbacks.AfterExecute(*Clang); + + Act->EndSourceFile(); + + if (!Act->hasEmittedPreamblePCH()) + return BuildPreambleError::CouldntEmitPCH; + + // Keep track of all of the files that the source manager knows about, + // so we can verify whether they have changed or not. + llvm::StringMap FilesInPreamble; + + SourceManager &SourceMgr = Clang->getSourceManager(); + for (auto &Filename : PreambleDepCollector->getDependencies()) { + const FileEntry *File = Clang->getFileManager().getFile(Filename); + if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())) + continue; + if (time_t ModTime = File->getModificationTime()) { + FilesInPreamble[File->getName()] = + PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(), + ModTime); + } else { + llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); + FilesInPreamble[File->getName()] = + PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer); + } + } + + return PrecompiledPreamble( + std::move(*PreamblePCHFile), std::move(PreambleBytes), + PreambleEndsAtStartOfLine, std::move(FilesInPreamble)); +} + +PreambleBounds PrecompiledPreamble::getBounds() const { + return PreambleBounds(PreambleBytes.size(), PreambleEndsAtStartOfLine); +} + +bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, + const llvm::MemoryBuffer *MainFileBuffer, + PreambleBounds Bounds, + vfs::FileSystem *VFS) const { + + assert( + Bounds.Size <= MainFileBuffer->getBufferSize() && + "Buffer is too large. Bounds were calculated from a different buffer?"); + + auto PreambleInvocation = std::make_shared(Invocation); + PreprocessorOptions &PreprocessorOpts = + PreambleInvocation->getPreprocessorOpts(); + + if (!Bounds.Size) + return false; + + // We've previously computed a preamble. Check whether we have the same + // preamble now that we did before, and that there's enough space in + // the main-file buffer within the precompiled preamble to fit the + // new main file. + if (PreambleBytes.size() != Bounds.Size || + PreambleEndsAtStartOfLine != Bounds.PreambleEndsAtStartOfLine || + memcmp(PreambleBytes.data(), MainFileBuffer->getBufferStart(), + Bounds.Size) != 0) + return false; + // The preamble has not changed. We may be able to re-use the precompiled + // preamble. + + // Check that none of the files used by the preamble have changed. + // First, make a record of those files that have been overridden via + // remapping or unsaved_files. + std::map OverriddenFiles; + for (const auto &R : PreprocessorOpts.RemappedFiles) { + vfs::Status Status; + if (!moveOnNoError(VFS->status(R.second), Status)) { + // If we can't stat the file we're remapping to, assume that something + // horrible happened. + return false; + } + + OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile( + Status.getSize(), llvm::sys::toTimeT(Status.getLastModificationTime())); + } + + for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { + vfs::Status Status; + if (!moveOnNoError(VFS->status(RB.first), Status)) + return false; + + OverriddenFiles[Status.getUniqueID()] = + PreambleFileHash::createForMemoryBuffer(RB.second); + } + + // Check whether anything has changed. + for (const auto &F : FilesInPreamble) { + vfs::Status Status; + if (!moveOnNoError(VFS->status(F.first()), Status)) { + // If we can't stat the file, assume that something horrible happened. + return false; + } + + std::map::iterator Overridden = + OverriddenFiles.find(Status.getUniqueID()); + if (Overridden != OverriddenFiles.end()) { + // This file was remapped; check whether the newly-mapped file + // matches up with the previous mapping. + if (Overridden->second != F.second) + return false; + continue; + } + + // The file was not remapped; check whether it has changed on disk. + if (Status.getSize() != uint64_t(F.second.Size) || + llvm::sys::toTimeT(Status.getLastModificationTime()) != + F.second.ModTime) + return false; + } + return true; +} + +void PrecompiledPreamble::AddImplicitPreamble( + CompilerInvocation &CI, llvm::MemoryBuffer *MainFileBuffer) const { + auto &PreprocessorOpts = CI.getPreprocessorOpts(); + + // Configure ImpicitPCHInclude. + PreprocessorOpts.PrecompiledPreambleBytes.first = PreambleBytes.size(); + PreprocessorOpts.PrecompiledPreambleBytes.second = PreambleEndsAtStartOfLine; + PreprocessorOpts.ImplicitPCHInclude = PCHFile.getFilePath(); + PreprocessorOpts.DisablePCHValidation = true; + + // Remap main file to point to MainFileBuffer. + auto MainFilePath = CI.getFrontendOpts().Inputs[0].getFile(); + PreprocessorOpts.addRemappedFile(MainFilePath, MainFileBuffer); +} + +PrecompiledPreamble::PrecompiledPreamble( + TempPCHFile PCHFile, std::vector PreambleBytes, + bool PreambleEndsAtStartOfLine, + llvm::StringMap FilesInPreamble) + : PCHFile(std::move(PCHFile)), FilesInPreamble(FilesInPreamble), + PreambleBytes(std::move(PreambleBytes)), + PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} + +llvm::ErrorOr +PrecompiledPreamble::TempPCHFile::CreateNewPreamblePCHFile() { + // FIXME: This is a hack so that we can override the preamble file during + // crash-recovery testing, which is the only case where the preamble files + // are not necessarily cleaned up. + const char *TmpFile = ::getenv("CINDEXTEST_PREAMBLE_FILE"); + if (TmpFile) + return TempPCHFile::createFromCustomPath(TmpFile); + return TempPCHFile::createInSystemTempDir("preamble", "pch"); +} + +llvm::ErrorOr +PrecompiledPreamble::TempPCHFile::createInSystemTempDir(const Twine &Prefix, + StringRef Suffix) { + llvm::SmallString<64> File; + auto EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, /*ref*/ File); + if (EC) + return EC; + return TempPCHFile(std::move(File).str()); +} + +llvm::ErrorOr +PrecompiledPreamble::TempPCHFile::createFromCustomPath(const Twine &Path) { + return TempPCHFile(Path.str()); +} + +PrecompiledPreamble::TempPCHFile::TempPCHFile(std::string FilePath) + : FilePath(std::move(FilePath)) { + TemporaryFiles::getInstance().addFile(*this->FilePath); +} + +PrecompiledPreamble::TempPCHFile::TempPCHFile(TempPCHFile &&Other) { + FilePath = std::move(Other.FilePath); + Other.FilePath = None; +} + +PrecompiledPreamble::TempPCHFile &PrecompiledPreamble::TempPCHFile:: +operator=(TempPCHFile &&Other) { + RemoveFileIfPresent(); + + FilePath = std::move(Other.FilePath); + Other.FilePath = None; + return *this; +} + +PrecompiledPreamble::TempPCHFile::~TempPCHFile() { RemoveFileIfPresent(); } + +void PrecompiledPreamble::TempPCHFile::RemoveFileIfPresent() { + if (FilePath) { + TemporaryFiles::getInstance().removeFile(*FilePath); + FilePath = None; + } +} + +llvm::StringRef PrecompiledPreamble::TempPCHFile::getFilePath() const { + assert(FilePath && "TempPCHFile doesn't have a FilePath. Had it been moved?"); + return *FilePath; +} + +PrecompiledPreamble::PreambleFileHash +PrecompiledPreamble::PreambleFileHash::createForFile(off_t Size, + time_t ModTime) { + PreambleFileHash Result; + Result.Size = Size; + Result.ModTime = ModTime; + Result.MD5 = {}; + return Result; +} + +PrecompiledPreamble::PreambleFileHash +PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer( + const llvm::MemoryBuffer *Buffer) { + PreambleFileHash Result; + Result.Size = Buffer->getBufferSize(); + Result.ModTime = 0; + + llvm::MD5 MD5Ctx; + MD5Ctx.update(Buffer->getBuffer().data()); + MD5Ctx.final(Result.MD5); + + return Result; +} + +void PreambleCallbacks::AfterExecute(CompilerInstance &CI) {} +void PreambleCallbacks::AfterPCHEmitted(ASTWriter &Writer) {} +void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {} +void PreambleCallbacks::HandleMacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) {} + +std::error_code clang::make_error_code(BuildPreambleError Error) { + return std::error_code(static_cast(Error), BuildPreambleErrorCategory()); +} + +const char *BuildPreambleErrorCategory::name() const noexcept { + return "build-preamble.error"; +} + +std::string BuildPreambleErrorCategory::message(int condition) const { + switch (static_cast(condition)) { + case BuildPreambleError::PreambleIsEmpty: + return "Preamble is empty"; + case BuildPreambleError::CouldntCreateTempFile: + return "Could not create temporary file for PCH"; + case BuildPreambleError::CouldntCreateTargetInfo: + return "CreateTargetInfo() return null"; + case BuildPreambleError::CouldntCreateVFSOverlay: + return "Could not create VFS Overlay"; + case BuildPreambleError::BeginSourceFileFailed: + return "BeginSourceFile() return an error"; + case BuildPreambleError::CouldntEmitPCH: + return "Could not emit PCH"; + } + llvm_unreachable("unexpected BuildPreambleError"); +} From 1299cb573f444dad1d6925dad23a68c7b15308b6 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 21 Jun 2017 10:27:24 +0000 Subject: [PATCH 019/214] Revert r305678: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system This commit also reverts follow-up commits r305680 and r305685 that have buildbot fixes. The change in r305678 wasn't correct because it relied on `llvm::sys::getProcessTriple`, which uses a pre-configured OS version. We should lookup the actual macOS version of the system on which the compiler is running. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305891 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Darwin.cpp | 23 +---------------------- test/Driver/darwin-sdk-vs-os-version.c | 10 ---------- 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 test/Driver/darwin-sdk-vs-os-version.c diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index b47df960dd9e..e41b50c40b28 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1118,27 +1118,6 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, } } -/// Returns the most appropriate macOS target version for the current process. -/// -/// If the macOS SDK version is the same or earlier than the system version, -/// then the SDK version is returned. Otherwise the system version is returned. -static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { - unsigned Major, Minor, Micro; - llvm::Triple SystemTriple(llvm::sys::getProcessTriple()); - if (!SystemTriple.isMacOSX()) - return MacOSSDKVersion; - SystemTriple.getMacOSXVersion(Major, Minor, Micro); - VersionTuple SystemVersion(Major, Minor, Micro); - bool HadExtra; - if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, - HadExtra)) - return MacOSSDKVersion; - VersionTuple SDKVersion(Major, Minor, Micro); - if (SDKVersion > SystemVersion) - return SystemVersion.getAsString(); - return MacOSSDKVersion; -} - void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { const OptTable &Opts = getDriver().getOpts(); @@ -1231,7 +1210,7 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = getSystemOrSDKMacOSVersion(Version); + OSXTarget = Version; else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) WatchOSTarget = Version; diff --git a/test/Driver/darwin-sdk-vs-os-version.c b/test/Driver/darwin-sdk-vs-os-version.c deleted file mode 100644 index 391f4d5a7305..000000000000 --- a/test/Driver/darwin-sdk-vs-os-version.c +++ /dev/null @@ -1,10 +0,0 @@ -// REQUIRES: system-darwin - -// Ensure that we never pick a version that's based on the SDK that's newer than -// the system version: -// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk -// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk -// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s - -// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" From 4bdcdc6dddb5e16533b43a368edba7a8260dadf7 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Wed, 21 Jun 2017 11:12:07 +0000 Subject: [PATCH 020/214] [analyzer] LocalizationChecker: Support new localizable APIs. Add support for new methods that were added in macOS High Sierra & iOS 11 and require a localized string. Patch by Kulpreet Chilana! rdar://problem/32795210 Differential Revision: https://reviews.llvm.org/D34266 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305896 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checkers/LocalizationChecker.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp index af35c2b0e991..6bbaaac05e6b 100644 --- a/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp @@ -281,6 +281,9 @@ void NonLocalizedStringChecker::initUIMethods(ASTContext &Ctx) const { IdentifierInfo *setLabelNSSegmentedControl[] = { &Ctx.Idents.get("setLabel"), &Ctx.Idents.get("forSegment")}; ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0) + IdentifierInfo *setToolTipNSSegmentedControl[] = { + &Ctx.Idents.get("setToolTip"), &Ctx.Idents.get("forSegment")}; + ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0) NEW_RECEIVER(NSButtonCell) ADD_UNARY_METHOD(NSButtonCell, setTitle, 0) @@ -562,6 +565,46 @@ void NonLocalizedStringChecker::initUIMethods(ASTContext &Ctx) const { IdentifierInfo *setTitleUISegmentedControl[] = { &Ctx.Idents.get("setTitle"), &Ctx.Idents.get("forSegmentAtIndex")}; ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0) + + NEW_RECEIVER(NSAccessibilityCustomRotorItemResult) + IdentifierInfo + *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = { + &Ctx.Idents.get("initWithItemLoadingToken"), + &Ctx.Idents.get("customLabel")}; + ADD_METHOD(NSAccessibilityCustomRotorItemResult, + initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1) + ADD_UNARY_METHOD(NSAccessibilityCustomRotorItemResult, setCustomLabel, 0) + + NEW_RECEIVER(UIContextualAction) + IdentifierInfo *contextualActionWithStyleUIContextualAction[] = { + &Ctx.Idents.get("contextualActionWithStyle"), &Ctx.Idents.get("title"), + &Ctx.Idents.get("handler")}; + ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3, + 1) + ADD_UNARY_METHOD(UIContextualAction, setTitle, 0) + + NEW_RECEIVER(NSAccessibilityCustomRotor) + IdentifierInfo *initWithLabelNSAccessibilityCustomRotor[] = { + &Ctx.Idents.get("initWithLabel"), &Ctx.Idents.get("itemSearchDelegate")}; + ADD_METHOD(NSAccessibilityCustomRotor, + initWithLabelNSAccessibilityCustomRotor, 2, 0) + ADD_UNARY_METHOD(NSAccessibilityCustomRotor, setLabel, 0) + + NEW_RECEIVER(NSWindowTab) + ADD_UNARY_METHOD(NSWindowTab, setTitle, 0) + ADD_UNARY_METHOD(NSWindowTab, setToolTip, 0) + + NEW_RECEIVER(NSAccessibilityCustomAction) + IdentifierInfo *initWithNameNSAccessibilityCustomAction[] = { + &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("handler")}; + ADD_METHOD(NSAccessibilityCustomAction, + initWithNameNSAccessibilityCustomAction, 2, 0) + IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = { + &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("target"), + &Ctx.Idents.get("selector")}; + ADD_METHOD(NSAccessibilityCustomAction, + initWithNameTargetNSAccessibilityCustomAction, 3, 0) + ADD_UNARY_METHOD(NSAccessibilityCustomAction, setName, 0) } #define LSF_INSERT(function_name) LSF.insert(&Ctx.Idents.get(function_name)); From 12b5e0baa25a1529352f985a391f1e42cf14fb0e Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 21 Jun 2017 11:26:58 +0000 Subject: [PATCH 021/214] Fix unused-variable compilation error. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305898 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/PrecompiledPreamble.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index 385e48a41057..15b24cbed484 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -73,12 +73,14 @@ TemporaryFiles::~TemporaryFiles() { void TemporaryFiles::addFile(StringRef File) { llvm::MutexGuard Guard(Mutex); auto IsInserted = Files.insert(File).second; + (void)IsInserted; assert(IsInserted && "File has already been added"); } void TemporaryFiles::removeFile(StringRef File) { llvm::MutexGuard Guard(Mutex); auto WasPresent = Files.erase(File); + (void)WasPresent; assert(WasPresent && "File was not tracked"); llvm::sys::fs::remove(File); } From a86381f7e1838d1d03d263ff65bd89537b52985b Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Wed, 21 Jun 2017 11:29:35 +0000 Subject: [PATCH 022/214] [analyzer] Bump a few default performance thresholds. This makes the analyzer around 10% slower by default, allowing it to find deeper bugs. Default values for the following -analyzer-config change: max-nodes: 150000 -> 225000; max-inlinable-size: 50 -> 100. rdar://problem/32539666 Differential Revision: https://reviews.llvm.org/D34277 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305900 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 4 ++-- test/Analysis/analyzer-config.c | 4 ++-- test/Analysis/analyzer-config.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 45ef612ee1d5..11b9f8c4f725 100644 --- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -293,7 +293,7 @@ unsigned AnalyzerOptions::getMaxInlinableSize() { DefaultValue = 4; break; case UMK_Deep: - DefaultValue = 50; + DefaultValue = 100; break; } @@ -332,7 +332,7 @@ unsigned AnalyzerOptions::getMaxNodesPerTopLevelFunction() { DefaultValue = 75000; break; case UMK_Deep: - DefaultValue = 150000; + DefaultValue = 225000; break; } MaxNodesPerTopLevelFunction = getOptionAsInteger("max-nodes", DefaultValue); diff --git a/test/Analysis/analyzer-config.c b/test/Analysis/analyzer-config.c index c0153a50532a..70521c63fbad 100644 --- a/test/Analysis/analyzer-config.c +++ b/test/Analysis/analyzer-config.c @@ -19,8 +19,8 @@ void foo() { // CHECK-NEXT: ipa = dynamic-bifurcate // CHECK-NEXT: ipa-always-inline-size = 3 // CHECK-NEXT: leak-diagnostics-reference-allocation = false -// CHECK-NEXT: max-inlinable-size = 50 -// CHECK-NEXT: max-nodes = 150000 +// CHECK-NEXT: max-inlinable-size = 100 +// CHECK-NEXT: max-nodes = 225000 // CHECK-NEXT: max-times-inline-large = 32 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14 // CHECK-NEXT: mode = deep diff --git a/test/Analysis/analyzer-config.cpp b/test/Analysis/analyzer-config.cpp index f84be1781160..60c03c1e497b 100644 --- a/test/Analysis/analyzer-config.cpp +++ b/test/Analysis/analyzer-config.cpp @@ -30,8 +30,8 @@ class Foo { // CHECK-NEXT: ipa = dynamic-bifurcate // CHECK-NEXT: ipa-always-inline-size = 3 // CHECK-NEXT: leak-diagnostics-reference-allocation = false -// CHECK-NEXT: max-inlinable-size = 50 -// CHECK-NEXT: max-nodes = 150000 +// CHECK-NEXT: max-inlinable-size = 100 +// CHECK-NEXT: max-nodes = 225000 // CHECK-NEXT: max-times-inline-large = 32 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14 // CHECK-NEXT: mode = deep From 2b802eb186d5a699e7f16fac42f7107e9f694f5f Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Wed, 21 Jun 2017 12:03:12 +0000 Subject: [PATCH 023/214] [clang-format] Support sorting using declarations Summary: This patch adds UsingDeclarationsSorter, a TokenAnalyzer that sorts consecutive using declarations. Reviewers: klimek Reviewed By: klimek Subscribers: Typz, djasper, cfe-commits, klimek, mgorny Differential Revision: https://reviews.llvm.org/D33823 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305901 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 10 + lib/Format/CMakeLists.txt | 1 + lib/Format/Format.cpp | 11 + lib/Format/UsingDeclarationsSorter.cpp | 144 +++++++++++ lib/Format/UsingDeclarationsSorter.h | 37 +++ unittests/Format/CMakeLists.txt | 1 + .../Format/UsingDeclarationsSorterTest.cpp | 234 ++++++++++++++++++ 7 files changed, 438 insertions(+) create mode 100644 lib/Format/UsingDeclarationsSorter.cpp create mode 100644 lib/Format/UsingDeclarationsSorter.h create mode 100644 unittests/Format/UsingDeclarationsSorterTest.cpp diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 1891c06eba51..3d311a0ba810 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1641,6 +1641,16 @@ tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, ArrayRef Ranges, StringRef FileName = ""); +/// \brief Sort consecutive using declarations in the given \p Ranges in +/// \p Code. +/// +/// Returns the ``Replacements`` that sort the using declarations in all +/// \p Ranges in \p Code. +tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, + StringRef Code, + ArrayRef Ranges, + StringRef FileName = ""); + /// \brief Returns the ``LangOpts`` that the formatter expects you to set. /// /// \param Style determines specific settings for lexing mode. diff --git a/lib/Format/CMakeLists.txt b/lib/Format/CMakeLists.txt index 0c7511c1bb07..42e6d53d9fe6 100644 --- a/lib/Format/CMakeLists.txt +++ b/lib/Format/CMakeLists.txt @@ -13,6 +13,7 @@ add_clang_library(clangFormat TokenAnnotator.cpp UnwrappedLineFormatter.cpp UnwrappedLineParser.cpp + UsingDeclarationsSorter.cpp WhitespaceManager.cpp LINK_LIBS diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 39da87cf9988..aebe22c07ecd 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -23,6 +23,7 @@ #include "TokenAnnotator.h" #include "UnwrappedLineFormatter.h" #include "UnwrappedLineParser.h" +#include "UsingDeclarationsSorter.h" #include "WhitespaceManager.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" @@ -1943,6 +1944,16 @@ tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, return Fix.process(); } +tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, + StringRef Code, + ArrayRef Ranges, + StringRef FileName) { + std::unique_ptr Env = + Environment::CreateVirtualEnvironment(Code, FileName, Ranges); + UsingDeclarationsSorter Sorter(*Env, Style); + return Sorter.process(); +} + LangOptions getFormattingLangOpts(const FormatStyle &Style) { LangOptions LangOpts; LangOpts.CPlusPlus = 1; diff --git a/lib/Format/UsingDeclarationsSorter.cpp b/lib/Format/UsingDeclarationsSorter.cpp new file mode 100644 index 000000000000..fb4f59fbc9bc --- /dev/null +++ b/lib/Format/UsingDeclarationsSorter.cpp @@ -0,0 +1,144 @@ +//===--- UsingDeclarationsSorter.cpp ----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief This file implements UsingDeclarationsSorter, a TokenAnalyzer that +/// sorts consecutive using declarations. +/// +//===----------------------------------------------------------------------===// + +#include "UsingDeclarationsSorter.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/Regex.h" + +#include + +#define DEBUG_TYPE "using-declarations-sorter" + +namespace clang { +namespace format { + +namespace { + +struct UsingDeclaration { + const AnnotatedLine *Line; + std::string Label; + + UsingDeclaration(const AnnotatedLine *Line, const std::string &Label) + : Line(Line), Label(Label) {} + + bool operator<(const UsingDeclaration &Other) const { + return Label < Other.Label; + } +}; + +/// Computes the label of a using declaration starting at tthe using token +/// \p UsingTok. +/// If \p UsingTok doesn't begin a using declaration, returns the empty string. +/// Note that this detects specifically using declarations, as in: +/// using A::B::C; +/// and not type aliases, as in: +/// using A = B::C; +/// Type aliases are in general not safe to permute. +std::string computeUsingDeclarationLabel(const FormatToken *UsingTok) { + assert(UsingTok && UsingTok->is(tok::kw_using) && "Expecting a using token"); + std::string Label; + const FormatToken *Tok = UsingTok->Next; + if (Tok && Tok->is(tok::kw_typename)) { + Label.append("typename "); + Tok = Tok->Next; + } + if (Tok && Tok->is(tok::coloncolon)) { + Label.append("::"); + Tok = Tok->Next; + } + bool HasIdentifier = false; + while (Tok && Tok->is(tok::identifier)) { + HasIdentifier = true; + Label.append(Tok->TokenText.str()); + Tok = Tok->Next; + if (!Tok || Tok->isNot(tok::coloncolon)) + break; + Label.append("::"); + Tok = Tok->Next; + } + if (HasIdentifier && Tok && Tok->isOneOf(tok::semi, tok::comma)) + return Label; + return ""; +} + +void endUsingDeclarationBlock( + SmallVectorImpl *UsingDeclarations, + const SourceManager &SourceMgr, tooling::Replacements *Fixes) { + SmallVector SortedUsingDeclarations( + UsingDeclarations->begin(), UsingDeclarations->end()); + std::sort(SortedUsingDeclarations.begin(), SortedUsingDeclarations.end()); + for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) { + if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line) + continue; + auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation(); + auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc(); + auto SortedBegin = + SortedUsingDeclarations[I].Line->First->Tok.getLocation(); + auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc(); + StringRef Text(SourceMgr.getCharacterData(SortedBegin), + SourceMgr.getCharacterData(SortedEnd) - + SourceMgr.getCharacterData(SortedBegin)); + DEBUG({ + StringRef OldText(SourceMgr.getCharacterData(Begin), + SourceMgr.getCharacterData(End) - + SourceMgr.getCharacterData(Begin)); + llvm::dbgs() << "Replacing '" << OldText << "' with '" << Text << "'\n"; + }); + auto Range = CharSourceRange::getCharRange(Begin, End); + auto Err = Fixes->add(tooling::Replacement(SourceMgr, Range, Text)); + if (Err) { + llvm::errs() << "Error while sorting using declarations: " + << llvm::toString(std::move(Err)) << "\n"; + } + } + UsingDeclarations->clear(); +} + +} // namespace + +UsingDeclarationsSorter::UsingDeclarationsSorter(const Environment &Env, + const FormatStyle &Style) + : TokenAnalyzer(Env, Style) {} + +tooling::Replacements UsingDeclarationsSorter::analyze( + TokenAnnotator &Annotator, SmallVectorImpl &AnnotatedLines, + FormatTokenLexer &Tokens) { + const SourceManager &SourceMgr = Env.getSourceManager(); + AffectedRangeMgr.computeAffectedLines(AnnotatedLines.begin(), + AnnotatedLines.end()); + tooling::Replacements Fixes; + SmallVector UsingDeclarations; + for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) { + if (!AnnotatedLines[I]->Affected || AnnotatedLines[I]->InPPDirective || + !AnnotatedLines[I]->startsWith(tok::kw_using) || + AnnotatedLines[I]->First->Finalized) { + endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); + continue; + } + if (AnnotatedLines[I]->First->NewlinesBefore > 1) + endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); + std::string Label = computeUsingDeclarationLabel(AnnotatedLines[I]->First); + if (Label.empty()) { + endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); + continue; + } + UsingDeclarations.push_back(UsingDeclaration(AnnotatedLines[I], Label)); + } + endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); + return Fixes; +} + +} // namespace format +} // namespace clang diff --git a/lib/Format/UsingDeclarationsSorter.h b/lib/Format/UsingDeclarationsSorter.h new file mode 100644 index 000000000000..f7d5f97e3a2a --- /dev/null +++ b/lib/Format/UsingDeclarationsSorter.h @@ -0,0 +1,37 @@ +//===--- UsingDeclarationsSorter.h ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief This file declares UsingDeclarationsSorter, a TokenAnalyzer that +/// sorts consecutive using declarations. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_FORMAT_USINGDECLARATIONSSORTER_H +#define LLVM_CLANG_LIB_FORMAT_USINGDECLARATIONSSORTER_H + +#include "TokenAnalyzer.h" + +namespace clang { +namespace format { + +class UsingDeclarationsSorter : public TokenAnalyzer { +public: + UsingDeclarationsSorter(const Environment &Env, const FormatStyle &Style); + + tooling::Replacements + analyze(TokenAnnotator &Annotator, + SmallVectorImpl &AnnotatedLines, + FormatTokenLexer &Tokens) override; +}; + +} // end namespace format +} // end namespace clang + +#endif diff --git a/unittests/Format/CMakeLists.txt b/unittests/Format/CMakeLists.txt index 507d643ba102..5c04ba1143c6 100644 --- a/unittests/Format/CMakeLists.txt +++ b/unittests/Format/CMakeLists.txt @@ -14,6 +14,7 @@ add_clang_unittest(FormatTests NamespaceEndCommentsFixerTest.cpp SortImportsTestJS.cpp SortIncludesTest.cpp + UsingDeclarationsSorterTest.cpp ) target_link_libraries(FormatTests diff --git a/unittests/Format/UsingDeclarationsSorterTest.cpp b/unittests/Format/UsingDeclarationsSorterTest.cpp new file mode 100644 index 000000000000..858a62c2d799 --- /dev/null +++ b/unittests/Format/UsingDeclarationsSorterTest.cpp @@ -0,0 +1,234 @@ +//===- UsingDeclarationsSorterTest.cpp - Formatting unit tests ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang/Format/Format.h" + +#include "llvm/Support/Debug.h" +#include "gtest/gtest.h" + +#define DEBUG_TYPE "using-declarations-sorter-test" + +namespace clang { +namespace format { +namespace { + +class UsingDeclarationsSorterTest : public ::testing::Test { +protected: + std::string sortUsingDeclarations(llvm::StringRef Code, + const std::vector &Ranges, + const FormatStyle &Style = getLLVMStyle()) { + DEBUG(llvm::errs() << "---\n"); + DEBUG(llvm::errs() << Code << "\n\n"); + tooling::Replacements Replaces = + clang::format::sortUsingDeclarations(Style, Code, Ranges, ""); + auto Result = applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast(Result)); + DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); + return *Result; + } + + std::string sortUsingDeclarations(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle()) { + return sortUsingDeclarations(Code, + /*Ranges=*/{1, tooling::Range(0, Code.size())}, + Style); + } +}; + +TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) { + EXPECT_EQ("using a;\n" + "using b;", + sortUsingDeclarations("using a;\n" + "using b;")); + EXPECT_EQ("using a;\n" + "using aa;", + sortUsingDeclarations("using aa;\n" + "using a;")); + EXPECT_EQ("using ::a;\n" + "using a;", + sortUsingDeclarations("using a;\n" + "using ::a;")); + + EXPECT_EQ("using a::bcd;\n" + "using a::cd;", + sortUsingDeclarations("using a::cd;\n" + "using a::bcd;")); + + EXPECT_EQ("using a;\n" + "using a::a;", + sortUsingDeclarations("using a::a;\n" + "using a;")); + + EXPECT_EQ("using a::ba::aa;\n" + "using a::bb::ccc;", + sortUsingDeclarations("using a::bb::ccc;\n" + "using a::ba::aa;")); + + EXPECT_EQ("using a;\n" + "using typename a;", + sortUsingDeclarations("using typename a;\n" + "using a;")); + + EXPECT_EQ("using typename z;\n" + "using typenamea;", + sortUsingDeclarations("using typenamea;\n" + "using typename z;")); + + EXPECT_EQ("using a, b;\n" + "using aa;", + sortUsingDeclarations("using aa;\n" + "using a, b;")); +} + +TEST_F(UsingDeclarationsSorterTest, SortsMultipleTopLevelDeclarations) { + EXPECT_EQ("using a;\n" + "using b;\n" + "using c;\n" + "using d;\n" + "using e;", + sortUsingDeclarations("using d;\n" + "using b;\n" + "using e;\n" + "using a;\n" + "using c;")); + + EXPECT_EQ("#include \n" + "using ::std::endl;\n" + "using std::cin;\n" + "using std::cout;\n" + "int main();", + sortUsingDeclarations("#include \n" + "using std::cout;\n" + "using std::cin;\n" + "using ::std::endl;\n" + "int main();")); +} + +TEST_F(UsingDeclarationsSorterTest, BreaksOnEmptyLines) { + EXPECT_EQ("using b;\n" + "using c;\n" + "\n" + "using a;\n" + "using d;", + sortUsingDeclarations("using c;\n" + "using b;\n" + "\n" + "using d;\n" + "using a;")); +} + +TEST_F(UsingDeclarationsSorterTest, BreaksOnUsingNamespace) { + EXPECT_EQ("using b;\n" + "using namespace std;\n" + "using a;", + sortUsingDeclarations("using b;\n" + "using namespace std;\n" + "using a;")); +} + +TEST_F(UsingDeclarationsSorterTest, KeepsUsingDeclarationsInPPDirectives) { + EXPECT_EQ("#define A \\\n" + "using b;\\\n" + "using a;", + sortUsingDeclarations("#define A \\\n" + "using b;\\\n" + "using a;")); +} + +TEST_F(UsingDeclarationsSorterTest, KeepsTypeAliases) { + auto Code = "struct C { struct B { struct A; }; };\n" + "using B = C::B;\n" + "using A = B::A;"; + EXPECT_EQ(Code, sortUsingDeclarations(Code)); +} + +TEST_F(UsingDeclarationsSorterTest, MovesTrailingCommentsWithDeclarations) { + EXPECT_EQ("using a; // line a1\n" + "using b; /* line b1\n" + " * line b2\n" + " * line b3 */\n" + "using c; // line c1\n" + " // line c2", + sortUsingDeclarations("using c; // line c1\n" + " // line c2\n" + "using b; /* line b1\n" + " * line b2\n" + " * line b3 */\n" + "using a; // line a1")); +} + +TEST_F(UsingDeclarationsSorterTest, SortsInStructScope) { + EXPECT_EQ("struct pt3 : pt2 {\n" + " using pt2::x;\n" + " using pt2::y;\n" + " float z;\n" + "};", + sortUsingDeclarations("struct pt3 : pt2 {\n" + " using pt2::y;\n" + " using pt2::x;\n" + " float z;\n" + "};")); +} + +TEST_F(UsingDeclarationsSorterTest, KeepsOperators) { + EXPECT_EQ("using a::operator();\n" + "using a::operator-;\n" + "using a::operator+;", + sortUsingDeclarations("using a::operator();\n" + "using a::operator-;\n" + "using a::operator+;")); +} + +TEST_F(UsingDeclarationsSorterTest, SortsUsingDeclarationsInsideNamespaces) { + EXPECT_EQ("namespace A {\n" + "struct B;\n" + "struct C;\n" + "}\n" + "namespace X {\n" + "using A::B;\n" + "using A::C;\n" + "}", + sortUsingDeclarations("namespace A {\n" + "struct B;\n" + "struct C;\n" + "}\n" + "namespace X {\n" + "using A::C;\n" + "using A::B;\n" + "}")); +} + +TEST_F(UsingDeclarationsSorterTest, SupportsClangFormatOff) { + EXPECT_EQ("// clang-format off\n" + "using b;\n" + "using a;\n" + "// clang-format on\n" + "using c;\n" + "using d;", + sortUsingDeclarations("// clang-format off\n" + "using b;\n" + "using a;\n" + "// clang-format on\n" + "using d;\n" + "using c;")); +} + +TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) { + EXPECT_EQ("using b;\n" + "using a;\n" + "using c;", + sortUsingDeclarations("using b;\n" + "using c;\n" // starts at offset 10 + "using a;", + {tooling::Range(10, 15)})); +} + +} // end namespace +} // end namespace format +} // end namespace clang From a3faa5a0e193a4fac5bb77d824be62c38f660052 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Wed, 21 Jun 2017 12:34:27 +0000 Subject: [PATCH 024/214] Fixed compiler warnings after r305890. Should fix buildbots that pass -Werror. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305902 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/ASTUnit.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 238ac3393130..1f34f10f55af 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -924,9 +924,6 @@ class TopLevelDeclTrackerAction : public ASTFrontendAction { class ASTUnitPreambleCallbacks : public PreambleCallbacks { public: - ASTUnitPreambleCallbacks(llvm::SmallVectorImpl &StoredDiags) - : StoredDiags(StoredDiags) {} - unsigned getHash() const { return Hash; } std::vector takeTopLevelDecls() { return std::move(TopLevelDecls); } @@ -964,7 +961,6 @@ class ASTUnitPreambleCallbacks : public PreambleCallbacks { } private: - llvm::SmallVectorImpl &StoredDiags; unsigned Hash = 0; std::vector TopLevelDecls; std::vector TopLevelDeclIDs; @@ -1259,7 +1255,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( SmallVector NewPreambleDiagsStandalone; SmallVector NewPreambleDiags; - ASTUnitPreambleCallbacks Callbacks(NewPreambleDiags); + ASTUnitPreambleCallbacks Callbacks; { llvm::Optional Capture; if (CaptureDiagnostics) @@ -1282,18 +1278,16 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( case BuildPreambleError::PreambleIsEmpty: // Try again next time. PreambleRebuildCounter = 1; - break; + return nullptr; case BuildPreambleError::CouldntCreateTargetInfo: case BuildPreambleError::BeginSourceFileFailed: case BuildPreambleError::CouldntEmitPCH: case BuildPreambleError::CouldntCreateVFSOverlay: // These erros are more likely to repeat, retry after some period. PreambleRebuildCounter = DefaultPreambleRebuildInterval; - break; - default: - llvm_unreachable("unexpected BuildPreambleError"); + return nullptr; } - return nullptr; + llvm_unreachable("unexpected BuildPreambleError"); } } From cabb95e0814719bf953eeeda569e6abafa5fbfad Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Wed, 21 Jun 2017 12:46:57 +0000 Subject: [PATCH 025/214] Function with unparsed body is a definition While a function body is being parsed, the function declaration is not considered as a definition because it does not have a body yet. In some cases it leads to incorrect interpretation, the case is presented in https://bugs.llvm.org/show_bug.cgi?id=14785: ``` template struct Somewhat { void internal() const {} friend void operator+(int const &, Somewhat const &) {} }; void operator+(int const &, Somewhat const &x) { x.internal(); } ``` When statement `x.internal()` in the body of global `operator+` is parsed, the type of `x` must be completed, so the instantiation of `Somewhat` is started. It instantiates the declaration of `operator+` defined inline, and makes a check for redefinition. The check does not detect another definition because the declaration of `operator+` is still not defining as does not have a body yet. To solves this problem the function `isThisDeclarationADefinition` considers a function declaration as a definition if it has flag `WillHaveBody` set. This change fixes PR14785. Differential Revision: https://reviews.llvm.org/D30375 This is a recommit of 305379, reverted in 305381, with small changes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305903 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 2 +- lib/Sema/SemaCUDA.cpp | 6 ---- lib/Sema/SemaDecl.cpp | 1 + lib/Sema/SemaDeclCXX.cpp | 3 ++ lib/Sema/SemaTemplateInstantiateDecl.cpp | 3 ++ test/SemaCXX/friend2.cpp | 37 ++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index b15c9d3f1ee8..30552be9b381 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1874,7 +1874,7 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, /// bool isThisDeclarationADefinition() const { return IsDeleted || IsDefaulted || Body || IsLateTemplateParsed || - hasDefiningAttr(); + WillHaveBody || hasDefiningAttr(); } /// doesThisDeclarationHaveABody - Returns whether this specific diff --git a/lib/Sema/SemaCUDA.cpp b/lib/Sema/SemaCUDA.cpp index b938ac387c4d..cac5f682275e 100644 --- a/lib/Sema/SemaCUDA.cpp +++ b/lib/Sema/SemaCUDA.cpp @@ -629,12 +629,6 @@ static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) { // emitted, because (say) the definition could include "inline". FunctionDecl *Def = FD->getDefinition(); - // We may currently be parsing the body of FD, in which case - // FD->getDefinition() will be null, but we still want to treat FD as though - // it's a definition. - if (!Def && FD->willHaveBody()) - Def = FD; - if (Def && !isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(Def))) return true; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d6164b3ff5e7..2f78d06a82d6 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -12232,6 +12232,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (FD) { FD->setBody(Body); + FD->setWillHaveBody(false); if (getLangOpts().CPlusPlus14) { if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() && diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 844299bb87cf..0b46e15bb0a3 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -13878,6 +13878,9 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) { return; } + // Deleted function does not have a body. + Fn->setWillHaveBody(false); + if (const FunctionDecl *Prev = Fn->getPreviousDecl()) { // Don't consider the implicit declaration we generate for explicit // specializations. FIXME: Do not generate these implicit declarations. diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index c58122cd271b..479760222d15 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1782,6 +1782,9 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, Previous.clear(); } + if (isFriend) + Function->setObjectOfFriendDecl(); + SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous, isExplicitSpecialization); diff --git a/test/SemaCXX/friend2.cpp b/test/SemaCXX/friend2.cpp index 347af0d61b1b..d1d4b628ba2d 100644 --- a/test/SemaCXX/friend2.cpp +++ b/test/SemaCXX/friend2.cpp @@ -170,3 +170,40 @@ struct Test { template class Test; } + +namespace pr14785 { +template +struct Somewhat { + void internal() const { } + friend void operator+(int const &, Somewhat const &) {} // expected-error{{redefinition of 'operator+'}} +}; + +void operator+(int const &, Somewhat const &x) { // expected-note {{previous definition is here}} + x.internal(); // expected-note{{in instantiation of template class 'pr14785::Somewhat' requested here}} +} +} + +namespace D30375 { +template struct B { + template bool insert(A &); +}; + +template +template bool B::insert(A &x) { return x < x; } + +template class D { + B t; + +public: + K x; + bool insert() { return t.insert(x); } + template friend bool operator<(const D &, const D &); +}; + +template bool operator<(const D &, const D &); + +void func() { + D> cache; + cache.insert(); +} +} From 4a8ecfcda38f13f785093ebac220c85a62c3a944 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 21 Jun 2017 13:51:04 +0000 Subject: [PATCH 026/214] [index] Nested class declarations should be annotated with the "specializationOf" relation if they pseudo-override a type in the base template This commit fixes an issue where Xcode's renaming engine couldn't find the reference to the second occurrence of "InnerClass" in this example: template struct Ts { template struct InnerClass { }; }; template<> struct Ts { template struct InnerClass; // This occurrence wasn't renamed }; rdar://31884960 Differential Revision: https://reviews.llvm.org/D34392 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305911 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexDecl.cpp | 4 +++- test/Index/Core/index-source.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index 2162c039c48b..2b0368131bb9 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -351,9 +351,11 @@ class IndexingDeclVisitor : public ConstDeclVisitor { IndexCtx.indexTagDecl(D, Relations); } else { auto *Parent = dyn_cast(D->getDeclContext()); + SmallVector Relations; + gatherTemplatePseudoOverrides(D, Relations); return IndexCtx.handleReference(D, D->getLocation(), Parent, D->getLexicalDeclContext(), - SymbolRoleSet()); + SymbolRoleSet(), Relations); } } return true; diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 10f2d8f77747..76fdc551c009 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -134,6 +134,9 @@ class PseudoOverridesInSpecializations { template struct InnerTemplate { }; template struct InnerTemplate { }; + + template + class InnerClass { }; }; template<> @@ -195,8 +198,22 @@ class PseudoOverridesInSpecializations { // CHECK-NEXT: RelChild // CHECK-NEXT: RelSpecialization | InnerTemplate | c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerTemplate template struct InnerTemplate { }; + + template + class InnerClass; +// CHECK: [[@LINE-1]]:9 | class(Gen)/C++ | InnerClass | c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass | | Ref,RelCont,RelSpecialization | rel: 2 +// CHECK-NEXT: RelCont +// CHECK-NEXT: RelSpecialization | InnerClass | c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerClass }; +template +class PseudoOverridesInSpecializations::InnerClass { +}; +// CHECK: [[@LINE-2]]:54 | class(Gen)/C++ | InnerClass | c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass | | Def,RelChild | rel: 1 +// CHECK-NEXT: RelChild +// CHECK: [[@LINE-4]]:7 | class(Gen)/C++ | PseudoOverridesInSpecializations | c:@ST>2#T#T@PseudoOverridesInSpecializations | | Ref,RelCont | rel: 1 +// CHECK-NEXT: RelCont + template class PseudoOverridesInSpecializations { typedef float TypealiasOrRecord; From 100ecde90ef26ee81763214d5fb335415ffc2b53 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Wed, 21 Jun 2017 13:56:02 +0000 Subject: [PATCH 027/214] clang-format: introduce InlineOnly short function style Summary: This is the same as Inline, except it does not imply all empty functions are merged: with this style, empty functions are merged only if they also match the 'inline' criteria (i.e. defined in a class). This is helpful to avoid inlining functions in implementations files. Reviewers: djasper, krasimir Reviewed By: djasper Subscribers: klimek, rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D34399 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305912 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 20 +++++++++++- lib/Format/Format.cpp | 1 + lib/Format/TokenAnnotator.cpp | 4 +-- lib/Format/UnwrappedLineFormatter.cpp | 2 +- unittests/Format/FormatTest.cpp | 46 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 3d311a0ba810..0a3e55440376 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -184,9 +184,23 @@ struct FormatStyle { enum ShortFunctionStyle { /// \brief Never merge functions into a single line. SFS_None, + /// \brief Only merge functions defined inside a class. Same as "inline", + /// except it does not implies "empty": i.e. top level empty functions + /// are not merged either. + /// \code + /// class Foo { + /// void f() { foo(); } + /// }; + /// void f() { + /// foo(); + /// } + /// void f() { + /// } + /// \endcode + SFS_InlineOnly, /// \brief Only merge empty functions. /// \code - /// void f() { bar(); } + /// void f() {} /// void f2() { /// bar2(); /// } @@ -197,6 +211,10 @@ struct FormatStyle { /// class Foo { /// void f() { foo(); } /// }; + /// void f() { + /// foo(); + /// } + /// void f() {} /// \endcode SFS_Inline, /// \brief Merge all functions fitting on a single line. diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index aebe22c07ecd..3e3667bfd829 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -97,6 +97,7 @@ template <> struct ScalarEnumerationTraits { IO.enumCase(Value, "All", FormatStyle::SFS_All); IO.enumCase(Value, "true", FormatStyle::SFS_All); IO.enumCase(Value, "Inline", FormatStyle::SFS_Inline); + IO.enumCase(Value, "InlineOnly", FormatStyle::SFS_InlineOnly); IO.enumCase(Value, "Empty", FormatStyle::SFS_Empty); } }; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e419b9d68799..505f42ec9a06 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2480,8 +2480,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None || Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty || (Left.NestingLevel == 0 && Line.Level == 0 && - Style.AllowShortFunctionsOnASingleLine == - FormatStyle::SFS_Inline); + Style.AllowShortFunctionsOnASingleLine & + FormatStyle::SFS_InlineOnly); } else if (Style.Language == FormatStyle::LK_Java) { if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next && Right.Next->is(tok::string_literal)) diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 63a0b7df59fc..8836c07cac71 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -226,7 +226,7 @@ class LineJoiner { Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All || (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && I[1]->First->is(tok::r_brace)) || - (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline && + (Style.AllowShortFunctionsOnASingleLine & FormatStyle::SFS_InlineOnly && TheLine->Level != 0); if (Style.CompactNamespaces) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 51849d9650d5..b43f735d4cb7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6509,6 +6509,52 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { MergeInlineOnly); } +TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { + FormatStyle MergeInlineOnly = getLLVMStyle(); + MergeInlineOnly.AllowShortFunctionsOnASingleLine = + FormatStyle::SFS_InlineOnly; + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + MergeInlineOnly); + verifyFormat("int f() {\n" + " return 42;\n" + "}", + MergeInlineOnly); + + // SFS_InlineOnly does not imply SFS_Empty + verifyFormat("class C {\n" + " int f() {}\n" + "};", + MergeInlineOnly); + verifyFormat("int f() {\n" + "}", + MergeInlineOnly); + + // Also verify behavior when BraceWrapping.AfterFunction = true + MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom; + MergeInlineOnly.BraceWrapping.AfterFunction = true; + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + MergeInlineOnly); + verifyFormat("int f()\n" + "{\n" + " return 42;\n" + "}", + MergeInlineOnly); + + // SFS_InlineOnly does not imply SFS_Empty + verifyFormat("int f()\n" + "{\n" + "}", + MergeInlineOnly); + verifyFormat("class C {\n" + " int f() {}\n" + "};", + MergeInlineOnly); +} + TEST_F(FormatTest, SplitEmptyFunctionBody) { FormatStyle Style = getLLVMStyle(); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; From a807ad0a5a57cbe9e283d74b538a08f5e1445cb2 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Wed, 21 Jun 2017 16:37:22 +0000 Subject: [PATCH 028/214] Correct VectorCall x86 (32 bit) behavior for SSE Register Assignment In running some internal vectorcall tests in 32 bit mode, we discovered that the behavior I'd previously implemented for x64 (and applied to x32) regarding the assignment of SSE registers was incorrect. See spec here: https://msdn.microsoft.com/en-us/library/dn375768.aspx My previous implementation applied register argument position from the x64 version to both. This isn't correct for x86, so this removes and refactors that section. Additionally, it corrects the integer/int-pointer assignments. Unlike x64, x86 permits integers to be assigned independent of position. Finally, the code for 32 bit was cleaned up a little to clarify the intent, as well as given a descriptive comment. Differential Revision: https://reviews.llvm.org/D34455 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305928 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetInfo.cpp | 128 ++++++++++++++++--------------------- test/CodeGen/vectorcall.c | 19 ++++-- 2 files changed, 71 insertions(+), 76 deletions(-) diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index d6a5e75a40cf..8d00e055306d 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -951,8 +951,7 @@ class X86_32ABIInfo : public SwiftABIInfo { Class classify(QualType Ty) const; ABIArgInfo classifyReturnType(QualType RetTy, CCState &State) const; ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State) const; - ABIArgInfo reclassifyHvaArgType(QualType RetTy, CCState &State, - const ABIArgInfo& current) const; + /// \brief Updates the number of available free registers, returns /// true if any registers were allocated. bool updateFreeRegs(QualType Ty, CCState &State) const; @@ -1536,27 +1535,6 @@ bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State) const { return true; } -ABIArgInfo -X86_32ABIInfo::reclassifyHvaArgType(QualType Ty, CCState &State, - const ABIArgInfo ¤t) const { - // Assumes vectorCall calling convention. - const Type *Base = nullptr; - uint64_t NumElts = 0; - - if (!Ty->isBuiltinType() && !Ty->isVectorType() && - isHomogeneousAggregate(Ty, Base, NumElts)) { - if (State.FreeSSERegs >= NumElts) { - // HVA types get passed directly in registers if there is room. - State.FreeSSERegs -= NumElts; - return getDirectX86Hva(); - } - // If there's no room, the HVA gets passed as normal indirect - // structure. - return getIndirectResult(Ty, /*ByVal=*/false, State); - } - return current; -} - ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState &State) const { // FIXME: Set alignment on indirect arguments. @@ -1575,35 +1553,20 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, } } - // vectorcall adds the concept of a homogenous vector aggregate, similar - // to other targets, regcall uses some of the HVA rules. + // Regcall uses the concept of a homogenous vector aggregate, similar + // to other targets. const Type *Base = nullptr; uint64_t NumElts = 0; - if ((State.CC == llvm::CallingConv::X86_VectorCall || - State.CC == llvm::CallingConv::X86_RegCall) && + if (State.CC == llvm::CallingConv::X86_RegCall && isHomogeneousAggregate(Ty, Base, NumElts)) { - if (State.CC == llvm::CallingConv::X86_RegCall) { - if (State.FreeSSERegs >= NumElts) { - State.FreeSSERegs -= NumElts; - if (Ty->isBuiltinType() || Ty->isVectorType()) - return ABIArgInfo::getDirect(); - return ABIArgInfo::getExpand(); - - } - return getIndirectResult(Ty, /*ByVal=*/false, State); - } else if (State.CC == llvm::CallingConv::X86_VectorCall) { - if (State.FreeSSERegs >= NumElts && (Ty->isBuiltinType() || Ty->isVectorType())) { - // Actual floating-point types get registers first time through if - // there is registers available - State.FreeSSERegs -= NumElts; + if (State.FreeSSERegs >= NumElts) { + State.FreeSSERegs -= NumElts; + if (Ty->isBuiltinType() || Ty->isVectorType()) return ABIArgInfo::getDirect(); - } else if (!Ty->isBuiltinType() && !Ty->isVectorType()) { - // HVA Types only get registers after everything else has been - // set, so it gets set as indirect for now. - return ABIArgInfo::getIndirect(getContext().getTypeAlignInChars(Ty)); - } + return ABIArgInfo::getExpand(); } + return getIndirectResult(Ty, /*ByVal=*/false, State); } if (isAggregateTypeForABI(Ty)) { @@ -1684,31 +1647,53 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, void X86_32ABIInfo::computeVectorCallArgs(CGFunctionInfo &FI, CCState &State, bool &UsedInAlloca) const { - // Vectorcall only allows the first 6 parameters to be passed in registers, - // and homogeneous vector aggregates are only put into registers as a second - // priority. - unsigned Count = 0; - CCState ZeroState = State; - ZeroState.FreeRegs = ZeroState.FreeSSERegs = 0; - // HVAs must be done as a second priority for registers, so the deferred - // items are dealt with by going through the pattern a second time. + // Vectorcall x86 works subtly different than in x64, so the format is + // a bit different than the x64 version. First, all vector types (not HVAs) + // are assigned, with the first 6 ending up in the YMM0-5 or XMM0-5 registers. + // This differs from the x64 implementation, where the first 6 by INDEX get + // registers. + // After that, integers AND HVAs are assigned Left to Right in the same pass. + // Integers are passed as ECX/EDX if one is available (in order). HVAs will + // first take up the remaining YMM/XMM registers. If insufficient registers + // remain but an integer register (ECX/EDX) is available, it will be passed + // in that, else, on the stack. for (auto &I : FI.arguments()) { - if (Count < VectorcallMaxParamNumAsReg) - I.info = classifyArgumentType(I.type, State); - else - // Parameters after the 6th cannot be passed in registers, - // so pretend there are no registers left for them. - I.info = classifyArgumentType(I.type, ZeroState); - UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca); - ++Count; + // First pass do all the vector types. + const Type *Base = nullptr; + uint64_t NumElts = 0; + const QualType& Ty = I.type; + if ((Ty->isVectorType() || Ty->isBuiltinType()) && + isHomogeneousAggregate(Ty, Base, NumElts)) { + if (State.FreeSSERegs >= NumElts) { + State.FreeSSERegs -= NumElts; + I.info = ABIArgInfo::getDirect(); + } else { + I.info = classifyArgumentType(Ty, State); + } + UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca); + } } - Count = 0; - // Go through the arguments a second time to get HVAs registers if there - // are still some available. + for (auto &I : FI.arguments()) { - if (Count < VectorcallMaxParamNumAsReg) - I.info = reclassifyHvaArgType(I.type, State, I.info); - ++Count; + // Second pass, do the rest! + const Type *Base = nullptr; + uint64_t NumElts = 0; + const QualType& Ty = I.type; + bool IsHva = isHomogeneousAggregate(Ty, Base, NumElts); + + if (IsHva && !Ty->isVectorType() && !Ty->isBuiltinType()) { + // Assign true HVAs (non vector/native FP types). + if (State.FreeSSERegs >= NumElts) { + State.FreeSSERegs -= NumElts; + I.info = getDirectX86Hva(); + } else { + I.info = getIndirectResult(Ty, /*ByVal=*/false, State); + } + } else if (!IsHva) { + // Assign all Non-HVAs, so this will exclude Vector/FP args. + I.info = classifyArgumentType(Ty, State); + UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca); + } } } @@ -3901,6 +3886,8 @@ void WinX86_64ABIInfo::computeVectorCallArgs(CGFunctionInfo &FI, bool IsRegCall) const { unsigned Count = 0; for (auto &I : FI.arguments()) { + // Vectorcall in x64 only permits the first 6 arguments to be passed + // as XMM/YMM registers. if (Count < VectorcallMaxParamNumAsReg) I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall); else { @@ -3913,11 +3900,8 @@ void WinX86_64ABIInfo::computeVectorCallArgs(CGFunctionInfo &FI, ++Count; } - Count = 0; for (auto &I : FI.arguments()) { - if (Count < VectorcallMaxParamNumAsReg) - I.info = reclassifyHvaArgType(I.type, FreeSSERegs, I.info); - ++Count; + I.info = reclassifyHvaArgType(I.type, FreeSSERegs, I.info); } } diff --git a/test/CodeGen/vectorcall.c b/test/CodeGen/vectorcall.c index 167f72ca2cfd..fa244fb908e0 100644 --- a/test/CodeGen/vectorcall.c +++ b/test/CodeGen/vectorcall.c @@ -100,8 +100,19 @@ void __vectorcall odd_size_hva(struct OddSizeHVA a) {} // X32: define x86_vectorcallcc void @"\01odd_size_hva@@32"(%struct.OddSizeHVA inreg %a.coerce) // X64: define x86_vectorcallcc void @"\01odd_size_hva@@32"(%struct.OddSizeHVA inreg %a.coerce) -// The Vectorcall ABI only allows passing the first 6 items in registers, so this shouldn't +// The Vectorcall ABI only allows passing the first 6 items in registers in x64, so this shouldn't // consider 'p7' as a register. Instead p5 gets put into the register on the second pass. -struct HFA2 __vectorcall AddParticles(struct HFA2 p1, float p2, struct HFA4 p3, int p4, struct HFA2 p5, float p6, float p7){ return p1;} -// X32: define x86_vectorcallcc %struct.HFA2 @"\01AddParticles@@80"(%struct.HFA2 inreg %p1.coerce, float %p2, %struct.HFA4* inreg %p3, i32 inreg %p4, %struct.HFA2 inreg %p5.coerce, float %p6, float %p7) -// X64: define x86_vectorcallcc %struct.HFA2 @"\01AddParticles@@96"(%struct.HFA2 inreg %p1.coerce, float %p2, %struct.HFA4* %p3, i32 %p4, %struct.HFA2 inreg %p5.coerce, float %p6, float %p7) +// x86 should pass p2, p6 and p7 in registers, then p1 in the second pass. +struct HFA2 __vectorcall AddParticles(struct HFA2 p1, float p2, struct HFA4 p3, int p4, struct HFA2 p5, float p6, float p7, int p8){ return p1;} +// X32: define x86_vectorcallcc %struct.HFA2 @"\01AddParticles@@84"(%struct.HFA2 inreg %p1.coerce, float %p2, %struct.HFA4* inreg %p3, i32 inreg %p4, %struct.HFA2* %p5, float %p6, float %p7, i32 %p8) +// X64: define x86_vectorcallcc %struct.HFA2 @"\01AddParticles@@104"(%struct.HFA2 inreg %p1.coerce, float %p2, %struct.HFA4* %p3, i32 %p4, %struct.HFA2 inreg %p5.coerce, float %p6, float %p7, i32 %p8) + +// Vectorcall in both architectures allows passing of an HVA as long as there is room, +// even if it is not one of the first 6 arguments. First pass puts p4 into a +// register on both. p9 ends up in a register in x86 only. Second pass puts p1 +// in a register, does NOT put p7 in a register (since theres no room), then puts +// p8 in a register. +void __vectorcall HVAAnywhere(struct HFA2 p1, int p2, int p3, float p4, int p5, int p6, struct HFA4 p7, struct HFA2 p8, float p9){} +// X32: define x86_vectorcallcc void @"\01HVAAnywhere@@88"(%struct.HFA2 inreg %p1.coerce, i32 inreg %p2, i32 inreg %p3, float %p4, i32 %p5, i32 %p6, %struct.HFA4* %p7, %struct.HFA2 inreg %p8.coerce, float %p9) +// X64: define x86_vectorcallcc void @"\01HVAAnywhere@@112"(%struct.HFA2 inreg %p1.coerce, i32 %p2, i32 %p3, float %p4, i32 %p5, i32 %p6, %struct.HFA4* %p7, %struct.HFA2 inreg %p8.coerce, float %p9) + From dba970f4d143480b964f77b363ec23f22cea0390 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 21 Jun 2017 16:50:38 +0000 Subject: [PATCH 029/214] Use -NOT prefix instead of adding `not` to FileCheck. If we want to make sure that a particular string is not in an output, the regular way of doing it is to add `-NOT` prefix instead of checking if FileCheck resulted in an error. Differential Revision: https://reviews.llvm.org/D34435 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305930 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Driver/autocomplete.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c index 78ac4b07cf07..c7e339b616f1 100644 --- a/test/Driver/autocomplete.c +++ b/test/Driver/autocomplete.c @@ -2,8 +2,8 @@ // FSYN: -fsyntax-only // RUN: %clang --autocomplete=-s | FileCheck %s -check-prefix=STD // STD: -std={{.*}}-stdlib= -// RUN: %clang --autocomplete=foo | not FileCheck %s -check-prefix=NONE -// NONE: foo +// RUN: %clang --autocomplete=foo | FileCheck %s -check-prefix=FOO +// FOO-NOT: foo // RUN: %clang --autocomplete=-stdlib=,l | FileCheck %s -check-prefix=STDLIB // STDLIB: libc++ libstdc++ // RUN: %clang --autocomplete=-stdlib=, | FileCheck %s -check-prefix=STDLIBALL From b5b472a91f6b26ce2aba5a81d13b36cdefbb3dc1 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 21 Jun 2017 18:52:44 +0000 Subject: [PATCH 030/214] [preprocessor] Fix assertion hit when 'SingleFileParseMode' option is enabled and #if with an undefined identifier and without #else 'HandleEndifDirective' asserts that 'WasSkipping' is false, so switch to using 'FoundNonSkip' as the hint for 'SingleFileParseMode' to keep going with parsing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305940 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPDirectives.cpp | 12 ++++++------ test/Index/single-file-parse.m | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 422bfc896875..8c79e50176e1 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -2658,7 +2658,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, // In 'single-file-parse mode' undefined identifiers trigger parsing of all // the directive blocks. CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(), - /*wasskip*/true, /*foundnonskip*/false, + /*wasskip*/false, /*foundnonskip*/false, /*foundelse*/false); } else if (!MI == isIfndef) { // Yes, remember that we are inside a conditional, then lex the next token. @@ -2705,7 +2705,7 @@ void Preprocessor::HandleIfDirective(Token &IfToken, if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) { // In 'single-file-parse mode' undefined identifiers trigger parsing of all // the directive blocks. - CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/true, + CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false, /*foundnonskip*/false, /*foundelse*/false); } else if (ConditionalTrue) { // Yes, remember that we are inside a conditional, then lex the next token. @@ -2768,11 +2768,11 @@ void Preprocessor::HandleElseDirective(Token &Result) { if (Callbacks) Callbacks->Else(Result.getLocation(), CI.IfLoc); - if (PPOpts->SingleFileParseMode && CI.WasSkipping) { + if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) { // In 'single-file-parse mode' undefined identifiers trigger parsing of all // the directive blocks. CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false, - /*foundnonskip*/true, /*foundelse*/true); + /*foundnonskip*/false, /*foundelse*/true); return; } @@ -2811,10 +2811,10 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) { SourceRange(ConditionalBegin, ConditionalEnd), PPCallbacks::CVK_NotEvaluated, CI.IfLoc); - if (PPOpts->SingleFileParseMode && CI.WasSkipping) { + if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) { // In 'single-file-parse mode' undefined identifiers trigger parsing of all // the directive blocks. - CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/true, + CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false, /*foundnonskip*/false, /*foundelse*/false); return; } diff --git a/test/Index/single-file-parse.m b/test/Index/single-file-parse.m index 6e2189c43ddb..f75b9bd0ee54 100644 --- a/test/Index/single-file-parse.m +++ b/test/Index/single-file-parse.m @@ -109,3 +109,13 @@ @interface Test27 @end // CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test28 @interface Test28 @end #endif + +#if SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test29 +@interface Test29 @end +#endif + +#ifdef SOMETHING_NOT_DEFINED +// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test30 +@interface Test30 @end +#endif From 612cecf9e41fd6e4cee4ba49ad43c947055d17dc Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 21 Jun 2017 19:59:05 +0000 Subject: [PATCH 031/214] [test] Make absolute line numbers relative; NFC Done to remove noise from https://reviews.llvm.org/D32332 (and to make this test more resilient to changes in general). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305947 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Sema/overloadable.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index 49d8085651d4..be9b862f2934 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -106,8 +106,8 @@ void fn_type_conversions() { void foo(char *c) __attribute__((overloadable)); void (*ptr1)(void *) = &foo; void (*ptr2)(char *) = &foo; - void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type ''}} expected-note@105{{candidate function}} expected-note@106{{candidate function}} - void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type ''}} expected-note@105{{candidate function}} expected-note@106{{candidate function}} + void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type ''}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} + void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type ''}} expected-note@-5{{candidate function}} expected-note@-4{{candidate function}} void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible function pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}} void *specific2 = (void (*)(void *))&foo; @@ -117,8 +117,8 @@ void fn_type_conversions() { void disabled(char *c) __attribute__((overloadable, enable_if(1, "The function name lies."))); // To be clear, these should all point to the last overload of 'disabled' void (*dptr1)(char *c) = &disabled; - void (*dptr2)(void *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type ''}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'char *')}} - void (*dptr3)(int *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type ''}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'int *' but has 'char *')}} + void (*dptr2)(void *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type ''}} expected-note@-5{{candidate function made ineligible by enable_if}} expected-note@-4{{candidate function made ineligible by enable_if}} expected-note@-3{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'char *')}} + void (*dptr3)(int *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type ''}} expected-note@-6{{candidate function made ineligible by enable_if}} expected-note@-5{{candidate function made ineligible by enable_if}} expected-note@-4{{candidate function has type mismatch at 1st parameter (expected 'int *' but has 'char *')}} void *specific_disabled = &disabled; } @@ -131,14 +131,14 @@ void incompatible_pointer_type_conversions() { void foo(char *c) __attribute__((overloadable)); void foo(short *c) __attribute__((overloadable)); foo(charbuf); - foo(ucharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@131{{candidate function}} expected-note@132{{candidate function}} - foo(intbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@131{{candidate function}} expected-note@132{{candidate function}} + foo(ucharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-3{{candidate function}} expected-note@-2{{candidate function}} + foo(intbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} void bar(unsigned char *c) __attribute__((overloadable)); void bar(signed char *c) __attribute__((overloadable)); - bar(charbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@137{{candidate function}} expected-note@138{{candidate function}} + bar(charbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@-2{{candidate function}} expected-note@-1{{candidate function}} bar(ucharbuf); - bar(intbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@137{{candidate function}} expected-note@138{{candidate function}} + bar(intbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} } void dropping_qualifiers_is_incompatible() { @@ -148,8 +148,8 @@ void dropping_qualifiers_is_incompatible() { void foo(char *c) __attribute__((overloadable)); void foo(const volatile unsigned char *c) __attribute__((overloadable)); - foo(ccharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}} - foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}} + foo(ccharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-3{{candidate function}} expected-note@-2{{candidate function}} + foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} } // Bug: we used to treat `__typeof__(foo)` as though it was `__typeof__(&foo)` From 85856463603bb3be56436220b5a273d200584238 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 21 Jun 2017 21:43:40 +0000 Subject: [PATCH 032/214] SwiftCC: Perform physical layout when computing coercion types We need to take type alignment padding into account whe computing physical layouts. The layout must be compatible with the input layout, offsets are defined in terms of offsets within a packed struct which are computed in terms of the alloc size of a type. Usingthe store size we would insert padding for the following type for example: struct { int3 v; long long l; } __attribute((packed)) On x86-64 int3 is padded to int4 alignment. The swiftcc type would be <{ <3 x float>, [4 x i8], i64 }> which is not compatible with <{ <3 x float>, i64 }>. The latter has i64 at offset 16 and the former at offset 20. rdar://32618125 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305956 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SwiftCallingConv.cpp | 8 +++++++- test/CodeGen/64bit-swiftcall.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/SwiftCallingConv.cpp b/lib/CodeGen/SwiftCallingConv.cpp index 0bfe30a32c80..fc8e36d2c599 100644 --- a/lib/CodeGen/SwiftCallingConv.cpp +++ b/lib/CodeGen/SwiftCallingConv.cpp @@ -57,6 +57,10 @@ static CharUnits getTypeStoreSize(CodeGenModule &CGM, llvm::Type *type) { return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type)); } +static CharUnits getTypeAllocSize(CodeGenModule &CGM, llvm::Type *type) { + return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type)); +} + void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) { // Deal with various aggregate types as special cases: @@ -542,7 +546,9 @@ SwiftAggLowering::getCoerceAndExpandTypes() const { packed = true; elts.push_back(entry.Type); - lastEnd = entry.End; + + lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type); + assert(entry.End <= lastEnd); } // We don't need to adjust 'packed' to deal with possible tail padding diff --git a/test/CodeGen/64bit-swiftcall.c b/test/CodeGen/64bit-swiftcall.c index 06c314501552..92ba37cd7fe6 100644 --- a/test/CodeGen/64bit-swiftcall.c +++ b/test/CodeGen/64bit-swiftcall.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64 @@ -1014,3 +1015,20 @@ typedef struct { TEST(struct_v1f3) // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3() // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float) + +typedef struct { + int3 vect; + unsigned long long val; +} __attribute__((packed)) padded_alloc_size_vector; +TEST(padded_alloc_size_vector) +// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64) +// X86-64-NOT: [4 x i8] +// x86-64: ret void + +typedef union { + float f1; + float3 fv2; +} union_hom_fp_partial2; +TEST(union_hom_fp_partial2) +// X86-64-LABEL: take_union_hom_fp_partial2(i64, float) +// ARM64-LABEL: take_union_hom_fp_partial2(i64, float) From 02f895ab3e0581ebf29c5b86b774911746a34570 Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Thu, 22 Jun 2017 10:09:40 +0000 Subject: [PATCH 033/214] [analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume Differential Revision: https://reviews.llvm.org/D34502 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305991 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checkers/BuiltinFunctionChecker.cpp | 4 +++- test/Analysis/builtin-assume.c | 8 -------- test/Analysis/builtin-functions.cpp | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) delete mode 100644 test/Analysis/builtin-assume.c diff --git a/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp index 48d6cd8a527c..097d4198800d 100644 --- a/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp @@ -50,8 +50,10 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE, state = state->assume(ArgSVal.castAs(), true); // FIXME: do we want to warn here? Not right now. The most reports might // come from infeasible paths, thus being false positives. - if (!state) + if (!state) { + C.generateSink(C.getState(), C.getPredecessor()); return true; + } C.addTransition(state); return true; diff --git a/test/Analysis/builtin-assume.c b/test/Analysis/builtin-assume.c deleted file mode 100644 index 00d651d9e3be..000000000000 --- a/test/Analysis/builtin-assume.c +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s - -void clang_analyzer_eval(int); - -void f(int i) { - __builtin_assume(i < 10); - clang_analyzer_eval(i < 15); // expected-warning {{TRUE}} -} diff --git a/test/Analysis/builtin-functions.cpp b/test/Analysis/builtin-functions.cpp index 4e9859754d62..2c1950251145 100644 --- a/test/Analysis/builtin-functions.cpp +++ b/test/Analysis/builtin-functions.cpp @@ -1,6 +1,7 @@ // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify void clang_analyzer_eval(bool); +void clang_analyzer_warnIfReached(); void testAddressof(int x) { clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}} @@ -50,3 +51,16 @@ void test_assume_aligned_4(char *p) { q = (char*) __builtin_assume_aligned(p + 1, 16); clang_analyzer_eval(p == q); // expected-warning{{FALSE}} } + +void f(int i) { + __builtin_assume(i < 10); + clang_analyzer_eval(i < 15); // expected-warning {{TRUE}} +} + +void g(int i) { + if (i > 5) { + __builtin_assume(i < 5); + clang_analyzer_warnIfReached(); // Assumtion contradicts constraints. + // We give up the analysis on this path. + } +} From ac0f61a33a039a52dfc4e2e7b0970c38593b0fa1 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 22 Jun 2017 11:20:07 +0000 Subject: [PATCH 034/214] [index] Add the "SpecializationOf" relation to the forward declarations of class template specializations This commit fixes an issue where a forward declaration of a class template specialization was not related to the base template. We need to relate even forward declarations because specializations don't have to be defined. rdar://32869409 Differential Revision: https://reviews.llvm.org/D34462 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305996 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexDecl.cpp | 22 ++++++++++------------ test/Index/Core/index-source.cpp | 10 +++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index 2b0368131bb9..d1127722c8ca 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -611,18 +611,16 @@ class IndexingDeclVisitor : public ConstDeclVisitor { ClassTemplateSpecializationDecl *D) { // FIXME: Notify subsequent callbacks if info comes from implicit // instantiation. - if (D->isThisDeclarationADefinition()) { - llvm::PointerUnion - Template = D->getSpecializedTemplateOrPartial(); - const Decl *SpecializationOf = - Template.is() - ? (Decl *)Template.get() - : Template.get(); - IndexCtx.indexTagDecl( - D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf), - SpecializationOf)); - } + llvm::PointerUnion + Template = D->getSpecializedTemplateOrPartial(); + const Decl *SpecializationOf = + Template.is() + ? (Decl *)Template.get() + : Template.get(); + IndexCtx.indexTagDecl( + D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf), + SpecializationOf)); if (TypeSourceInfo *TSI = D->getTypeAsWritten()) IndexCtx.indexTypeSourceInfo(TSI, /*Parent=*/nullptr, D->getLexicalDeclContext()); diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 76fdc551c009..6d20fdd48e50 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -282,7 +282,9 @@ class SpecializationDecl { }; template<> class SpecializationDecl; -// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl | | Ref | rel: 0 +// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | SpecializationDecl | c:@S@SpecializationDecl>#I | | Decl,RelSpecialization | rel: 1 +// CHECK-NEXT: RelSpecialization | SpecializationDecl | c:@ST>1#T@SpecializationDecl +// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl | | Ref | rel: 0 template<> class SpecializationDecl { }; @@ -292,8 +294,10 @@ class SpecializationDecl { }; template class PartialSpecilizationClass; -// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass | | Ref | rel: 0 -// CHECK-NEXT: [[@LINE-2]]:33 | class/C++ | Cls | c:@S@Cls | | Ref | rel: 0 +// CHECK: [[@LINE-1]]:7 | class(Gen,TPS)/C++ | PartialSpecilizationClass | c:@SP>1#T@PartialSpecilizationClass>#$@S@Cls#t0.0 | | Decl,RelSpecialization | rel: 1 +// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass +// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass | | Ref | rel: 0 +// CHECK-NEXT: [[@LINE-4]]:33 | class/C++ | Cls | c:@S@Cls | | Ref | rel: 0 template<> class PartialSpecilizationClass : Cls { }; From 0900716ae20ebeb4a40ccfa892148d7e55df2ae6 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 22 Jun 2017 17:02:24 +0000 Subject: [PATCH 035/214] [Sema] Add -Wunguarded-availability-new The new compiler warning -Wunguarded-availability-new is a subset of -Wunguarded-availability. It is on by default. It only warns about uses of APIs that have been introduced in macOS >= 10.13, iOS >= 11, watchOS >= 4 and tvOS >= 11. We decided to use this kind of solution as we didn't want to turn on -Wunguarded-availability by default, because we didn't want our users to get warnings about uses of old APIs in their existing projects. rdar://31054725 Differential Revision: https://reviews.llvm.org/D34264 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306033 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 4 +- include/clang/Basic/DiagnosticSemaKinds.td | 10 ++ lib/Sema/SemaDeclAttr.cpp | 60 +++++++- test/SemaObjC/unguarded-availability-new.m | 160 +++++++++++++++++++++ 4 files changed, 228 insertions(+), 6 deletions(-) create mode 100644 test/SemaObjC/unguarded-availability-new.m diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 36b64a125228..464c2425a1f1 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -98,7 +98,9 @@ def CXX11CompatDeprecatedWritableStr : def DeprecatedAttributes : DiagGroup<"deprecated-attributes">; def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">; def UnavailableDeclarations : DiagGroup<"unavailable-declarations">; -def UnguardedAvailability : DiagGroup<"unguarded-availability">; +def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">; +def UnguardedAvailability : DiagGroup<"unguarded-availability", + [UnguardedAvailabilityNew]>; // partial-availability is an alias of unguarded-availability. def : DiagGroup<"partial-availability", [UnguardedAvailability]>; def DeprecatedDynamicExceptionSpec diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 0dd151cbd9c6..62faadcc5fe9 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2870,8 +2870,13 @@ def note_protocol_method : Note< def warn_unguarded_availability : Warning<"%0 is only available on %1 %2 or newer">, InGroup, DefaultIgnore; +def warn_unguarded_availability_new : + Warning, + InGroup; def warn_partial_availability : Warning<"%0 is only available conditionally">, InGroup, DefaultIgnore; +def warn_partial_availability_new : Warning, + InGroup; def note_partial_availability_silence : Note< "explicitly redeclare %0 to silence this warning">; def note_unguarded_available_silence : Note< @@ -2879,9 +2884,14 @@ def note_unguarded_available_silence : Note< " this warning">; def warn_partial_message : Warning<"%0 is partial: %1">, InGroup, DefaultIgnore; +def warn_partial_message_new : Warning, + InGroup; def warn_partial_fwdclass_message : Warning< "%0 may be partial because the receiver type is unknown">, InGroup, DefaultIgnore; +def warn_partial_fwdclass_message_new : + Warning, + InGroup; def warn_at_available_unchecked_use : Warning< "%select{@available|__builtin_available}0 does not guard availability here; " "use if (%select{@available|__builtin_available}0) instead">, diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index b43642f5493b..e8503427536d 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -6903,6 +6903,32 @@ static bool ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K, return true; } +static bool +shouldDiagnoseAvailabilityByDefault(const ASTContext &Context, + const VersionTuple &DeploymentVersion, + const VersionTuple &DeclVersion) { + const auto &Triple = Context.getTargetInfo().getTriple(); + VersionTuple ForceAvailabilityFromVersion; + switch (Triple.getOS()) { + case llvm::Triple::IOS: + case llvm::Triple::TvOS: + ForceAvailabilityFromVersion = VersionTuple(/*Major=*/11); + break; + case llvm::Triple::WatchOS: + ForceAvailabilityFromVersion = VersionTuple(/*Major=*/4); + break; + case llvm::Triple::Darwin: + case llvm::Triple::MacOSX: + ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13); + break; + default: + // New targets should always warn about availability. + return Triple.getVendor() == llvm::Triple::Apple; + } + return DeploymentVersion >= ForceAvailabilityFromVersion || + DeclVersion >= ForceAvailabilityFromVersion; +} + static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, Decl *Ctx, const NamedDecl *D, StringRef Message, SourceLocation Loc, @@ -6991,13 +7017,26 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, } break; - case AR_NotYetIntroduced: - diag = diag::warn_partial_availability; - diag_message = diag::warn_partial_message; - diag_fwdclass_message = diag::warn_partial_fwdclass_message; + case AR_NotYetIntroduced: { + // We would like to emit the diagnostic even if -Wunguarded-availability is + // not specified for deployment targets >= to iOS 11 or equivalent or + // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or + // later. + const AvailabilityAttr *AA = getAttrForPlatform(S.getASTContext(), D); + VersionTuple Introduced = AA->getIntroduced(); + bool NewWarning = shouldDiagnoseAvailabilityByDefault( + S.Context, S.Context.getTargetInfo().getPlatformMinVersion(), + Introduced); + diag = NewWarning ? diag::warn_partial_availability_new + : diag::warn_partial_availability; + diag_message = NewWarning ? diag::warn_partial_message_new + : diag::warn_partial_message; + diag_fwdclass_message = NewWarning ? diag::warn_partial_fwdclass_message_new + : diag::warn_partial_fwdclass_message; property_note_select = /* partial */ 2; available_here_select_kind = /* partial */ 3; break; + } case AR_Available: llvm_unreachable("Warning for availability of available declaration?"); @@ -7317,7 +7356,18 @@ void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability( if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx)) return; - SemaRef.Diag(Range.getBegin(), diag::warn_unguarded_availability) + // We would like to emit the diagnostic even if -Wunguarded-availability is + // not specified for deployment targets >= to iOS 11 or equivalent or + // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or + // later. + unsigned DiagKind = + shouldDiagnoseAvailabilityByDefault( + SemaRef.Context, + SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced) + ? diag::warn_unguarded_availability_new + : diag::warn_unguarded_availability; + + SemaRef.Diag(Range.getBegin(), DiagKind) << Range << D << AvailabilityAttr::getPrettyPlatformName( SemaRef.getASTContext().getTargetInfo().getPlatformName()) diff --git a/test/SemaObjC/unguarded-availability-new.m b/test/SemaObjC/unguarded-availability-new.m new file mode 100644 index 000000000000..33baedebc279 --- /dev/null +++ b/test/SemaObjC/unguarded-availability-new.m @@ -0,0 +1,160 @@ +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -xobjective-c++ -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s + +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability-new -DNO_WARNING -fblocks -fsyntax-only -verify %s + +// unguarded-availability implies unguarded-availability-new: +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.11 -Wunguarded-availability -Wno-unguarded-availability-new -DNO_WARNING -DWARN_PREV -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s + +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-ios11 -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.12 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s + +// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios10.3 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s + +// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos10 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s + +// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos3 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s + +#ifdef MAC +#define PLATFORM macos +#define NEXT 10.14 + +#define AVAILABLE_PREV __attribute__((availability(macos, introduced = 10.12))) +#define AVAILABLE_CURRENT __attribute__((availability(macos, introduced = 10.13))) +#define AVAILABLE_NEXT __attribute__((availability(macos, introduced = 10.14))) +#endif + +#ifdef IOS +#define PLATFORM ios +#define NEXT 12 + +#define AVAILABLE_PREV __attribute__((availability(ios, introduced = 10))) +#define AVAILABLE_CURRENT __attribute__((availability(ios, introduced = 11))) +#define AVAILABLE_NEXT __attribute__((availability(ios, introduced = 12))) +#endif + +#ifdef TVOS +#define PLATFORM tvos +#define NEXT 13 + +#define AVAILABLE_PREV __attribute__((availability(tvos, introduced = 10))) +#define AVAILABLE_CURRENT __attribute__((availability(tvos, introduced = 11))) +#define AVAILABLE_NEXT __attribute__((availability(tvos, introduced = 13))) +#endif + +#ifdef WATCHOS +#define PLATFORM watchos +#define NEXT 5 + +#define AVAILABLE_PREV __attribute__((availability(watchos, introduced = 3))) +#define AVAILABLE_CURRENT __attribute__((availability(watchos, introduced = 4))) +#define AVAILABLE_NEXT __attribute__((availability(watchos, introduced = 5))) +#endif + +void previouslyAvailable() AVAILABLE_PREV; +#ifdef WARN_PREV + // expected-note@-2 {{'previouslyAvailable' has been explicitly marked partial here}} +#endif +void currentlyAvailable() AVAILABLE_CURRENT; +#ifdef WARN_CURRENT + // expected-note@-2 {{'currentlyAvailable' has been explicitly marked partial here}} +#endif +void willBeAvailabile() AVAILABLE_NEXT; +#ifndef NO_WARNING + // expected-note@-2 {{'willBeAvailabile' has been explicitly marked partial here}} +#endif + +#ifdef TEST_FUNC_CURRENT +#define FUNC_AVAILABLE AVAILABLE_CURRENT +#endif +#ifdef TEST_FUNC_NEXT +#define FUNC_AVAILABLE AVAILABLE_NEXT +#endif +#ifndef FUNC_AVAILABLE +#define FUNC_AVAILABLE +#endif + +typedef int AVAILABLE_NEXT new_int; +#ifndef NO_WARNING + // expected-note@-2 {{'new_int' has been explicitly marked partial here}} +#endif +FUNC_AVAILABLE new_int x; +#ifndef NO_WARNING +#ifdef MAC + // expected-warning@-3 {{'new_int' is partial: introduced in macOS 10.14}} expected-note@-3 {{explicitly redeclare 'new_int' to silence this warning}} +#endif +#ifdef IOS + // expected-warning@-6 {{'new_int' is partial: introduced in iOS 12}} expected-note@-6 {{explicitly redeclare 'new_int' to silence this warning}} +#endif +#ifdef TVOS + // expected-warning@-9 {{'new_int' is partial: introduced in tvOS 13}} expected-note@-9 {{explicitly redeclare 'new_int' to silence this warning}} +#endif +#ifdef WATCHOS + // expected-warning@-12 {{'new_int' is partial: introduced in watchOS 5}} expected-note@-12 {{explicitly redeclare 'new_int' to silence this warning}} +#endif +#endif + +void test() FUNC_AVAILABLE { + previouslyAvailable(); +#ifdef WARN_PREV +#ifdef MAC + // expected-warning@-3 {{'previouslyAvailable' is only available on macOS 10.12 or newer}} +#endif + // expected-note@-5 {{enclose 'previouslyAvailable' in an @available check to silence this warning}} +#endif + currentlyAvailable(); +#ifdef WARN_CURRENT +#ifdef MAC + // expected-warning@-3 {{'currentlyAvailable' is only available on macOS 10.13 or newer}} +#endif +#ifdef IOS + // expected-warning@-6 {{'currentlyAvailable' is only available on iOS 11 or newer}} +#endif +#ifdef TVOS + // expected-warning@-9 {{'currentlyAvailable' is only available on tvOS 11 or newer}} +#endif +#ifdef WATCHOS + // expected-warning@-12 {{'currentlyAvailable' is only available on watchOS 4 or newer}} +#endif + // expected-note@-14 {{enclose 'currentlyAvailable' in an @available check to silence this warning}} +#endif + willBeAvailabile(); +#ifndef NO_WARNING +#ifdef MAC + // expected-warning@-3 {{'willBeAvailabile' is only available on macOS 10.14 or newer}} +#endif +#ifdef IOS + // expected-warning@-6 {{'willBeAvailabile' is only available on iOS 12 or newer}} +#endif +#ifdef TVOS + // expected-warning@-9 {{'willBeAvailabile' is only available on tvOS 13 or newer}} +#endif +#ifdef WATCHOS + // expected-warning@-12 {{'willBeAvailabile' is only available on watchOS 5 or newer}} +#endif + // expected-note@-14 {{enclose 'willBeAvailabile' in an @available check to silence this warning}} +#endif + if (@available(PLATFORM NEXT, *)) + willBeAvailabile(); // OK +} + +#ifdef NO_WARNING +#ifndef WARN_PREV +// expected-no-diagnostics +#endif +#endif From 9607465f43932913a4e5fc9183e8c63951393b6c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 22 Jun 2017 22:18:46 +0000 Subject: [PATCH 036/214] PR33002: When we instantiate the definition of a static data member, we might have attached an initializer to the in-class declaration. If so, include the initializer in the update record for the instantiation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306065 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 ---- lib/Serialization/ASTReaderDecl.cpp | 15 ++++++++++-- lib/Serialization/ASTWriter.cpp | 11 ++++++++- test/Modules/const-var-init-update.cpp | 30 ++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 test/Modules/const-var-init-update.cpp diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 479760222d15..578386fc113d 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4290,9 +4290,6 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs); PreviousContext.pop(); - // FIXME: Need to inform the ASTConsumer that we instantiated the - // initializer? - // This variable may have local implicit instantiations that need to be // instantiated within this scope. LocalInstantiations.perform(); @@ -4402,7 +4399,6 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, if (Def->isStaticDataMember() && !Def->isOutOfLine()) { // We're instantiating an inline static data member whose definition was // provided inside the class. - // FIXME: Update record? InstantiateVariableInitializer(Var, Def, TemplateArgs); } else if (!VarSpec) { Var = cast_or_null(SubstDecl(Def, Var->getDeclContext(), diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index ed103e629216..3cc3a8efae3f 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -3934,10 +3934,21 @@ void ASTDeclReader::UpdateDecl(Decl *D) { break; } - case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: - cast(D)->getMemberSpecializationInfo()->setPointOfInstantiation( + case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: { + VarDecl *VD = cast(D); + VD->getMemberSpecializationInfo()->setPointOfInstantiation( ReadSourceLocation()); + uint64_t Val = Record.readInt(); + if (Val && !VD->getInit()) { + VD->setInit(Record.readExpr()); + if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 + EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); + Eval->CheckedICE = true; + Eval->IsICE = Val == 3; + } + } break; + } case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { auto Param = cast(D); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index dcacabec1225..1c0db14ced14 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -5033,9 +5033,18 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { case UPD_CXX_ADDED_FUNCTION_DEFINITION: break; - case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: + case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: { + const VarDecl *VD = cast(D); Record.AddSourceLocation(Update.getLoc()); + if (VD->getInit()) { + Record.push_back(!VD->isInitKnownICE() ? 1 + : (VD->isInitICE() ? 3 : 2)); + Record.AddStmt(const_cast(VD->getInit())); + } else { + Record.push_back(0); + } break; + } case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: Record.AddStmt(const_cast( diff --git a/test/Modules/const-var-init-update.cpp b/test/Modules/const-var-init-update.cpp new file mode 100644 index 000000000000..61080eb83917 --- /dev/null +++ b/test/Modules/const-var-init-update.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -std=c++1z -fmodules %s -verify +// expected-no-diagnostics + +#pragma clang module build std +module std { module limits {} module other {} } +#pragma clang module contents +#pragma clang module begin std.limits +template struct numeric_limits { + static constexpr T __max = 5; + static constexpr T max() { return __max; } +}; +#pragma clang module end +#pragma clang module begin std.other +inline void f() { numeric_limits nl; } +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module build module_b +module module_b {} +#pragma clang module contents +#pragma clang module begin module_b +#pragma clang module import std.limits +constexpr int a = numeric_limits::max(); +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module import std.limits +#pragma clang module import module_b +constexpr int b = a; +static_assert(b == 5); From 20f171571be48643f23ce255c69c1c7a45aad161 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 23 Jun 2017 00:02:55 +0000 Subject: [PATCH 037/214] [WebAssembly] Add default -allow-undefined-file to linker args Also, don't use the outdated lib32/lib64 naming of files within the sysroot. The more modern/flexible approach IIUC is to use seperate sysroots or /lib/ and /include/. Differential Revision: https://reviews.llvm.org/D33565 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306074 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/WebAssembly.cpp | 5 +++-- test/Driver/wasm-toolchain.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Driver/ToolChains/WebAssembly.cpp b/lib/Driver/ToolChains/WebAssembly.cpp index 3471569b6884..fcb6418b2517 100644 --- a/lib/Driver/ToolChains/WebAssembly.cpp +++ b/lib/Driver/ToolChains/WebAssembly.cpp @@ -83,6 +83,8 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); + CmdArgs.push_back("-allow-undefined-file"); + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("wasm.syms"))); CmdArgs.push_back("-lc"); CmdArgs.push_back("-lcompiler_rt"); } @@ -104,8 +106,7 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, getProgramPaths().push_back(getDriver().getInstalledDir()); - getFilePaths().push_back( - getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); + getFilePaths().push_back(getDriver().SysRoot + "/lib"); } bool WebAssembly::IsMathErrnoDefault() const { return false; } diff --git a/test/Driver/wasm-toolchain.c b/test/Driver/wasm-toolchain.c index 3be60df92672..8debc0287007 100644 --- a/test/Driver/wasm-toolchain.c +++ b/test/Driver/wasm-toolchain.c @@ -27,18 +27,18 @@ // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" // A basic C link command-line with optimization. WebAssembly is somewhat // special in enabling --gc-sections by default. // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" // Ditto, but ensure that a user --no-gc-sections comes after the // default --gc-sections. // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck -check-prefix=NO_GC_SECTIONS %s // NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" From 8f8ada1d408483feee9739b842838fd276cc2c1f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 23 Jun 2017 01:04:34 +0000 Subject: [PATCH 038/214] PR33552: Distinguish between declarations that are owned by no module and declarations that are owned but unconditionally visible. This allows us to set declarations as visible even if they have a local owning module, without losing information. In turn, that means that our Objective-C support can keep on incorrectly assuming the "hidden" bit on the declaration is the whole story with regard to name visibility. This will also be useful once we support the C++ Modules TS export semantics. Objective-C name visibility is still incorrect in any case where the "hidden" bit is not the complete story: for instance, in Objective-C++ the set of visible categories will be wrong during template instantiation, and with local submodule visibility enabled it will be wrong when building modules. Fixing that will require a major overhaul of how visibility is handled for Objective-C (and particularly for categories). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306075 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclBase.h | 155 ++++++++++++++--------- lib/AST/ASTContext.cpp | 2 +- lib/AST/DeclBase.cpp | 6 +- lib/Sema/SemaDecl.cpp | 8 +- lib/Sema/SemaExprCXX.cpp | 4 +- lib/Sema/SemaLookup.cpp | 4 +- lib/Sema/SemaTemplateInstantiate.cpp | 4 +- lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +- lib/Serialization/ASTReader.cpp | 6 +- lib/Serialization/ASTReaderDecl.cpp | 28 ++-- test/Misc/ast-dump-decl.c | 22 +++- test/Misc/ast-dump-decl.cpp | 5 - 12 files changed, 147 insertions(+), 101 deletions(-) diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index c26e2d7bde95..0f1f481ae49b 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -202,26 +202,33 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { OBJC_TQ_CSNullability = 0x40 }; -protected: - // Enumeration values used in the bits stored in NextInContextAndBits. - enum { - /// \brief Whether this declaration is a top-level declaration (function, - /// global variable, etc.) that is lexically inside an objc container - /// definition. - TopLevelDeclInObjCContainerFlag = 0x01, - - /// \brief Whether this declaration is private to the module in which it was - /// defined. - ModulePrivateFlag = 0x02 + /// The kind of ownership a declaration has, for visibility purposes. + /// This enumeration is designed such that higher values represent higher + /// levels of name hiding. + enum class ModuleOwnershipKind : unsigned { + /// This declaration is not owned by a module. + Unowned, + /// This declaration has an owning module, but is globally visible + /// (typically because its owning module is visible and we know that + /// modules cannot later become hidden in this compilation). + /// After serialization and deserialization, this will be converted + /// to VisibleWhenImported. + Visible, + /// This declaration has an owning module, and is visible when that + /// module is imported. + VisibleWhenImported, + /// This declaration has an owning module, but is only visible to + /// lookups that occur within that module. + ModulePrivate }; - + +protected: /// \brief The next declaration within the same lexical /// DeclContext. These pointers form the linked list that is /// traversed via DeclContext's decls_begin()/decls_end(). /// - /// The extra two bits are used for the TopLevelDeclInObjCContainer and - /// ModulePrivate bits. - llvm::PointerIntPair NextInContextAndBits; + /// The extra two bits are used for the ModuleOwnershipKind. + llvm::PointerIntPair NextInContextAndBits; private: friend class DeclContext; @@ -282,6 +289,11 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// are regarded as "referenced" but not "used". unsigned Referenced : 1; + /// \brief Whether this declaration is a top-level declaration (function, + /// global variable, etc.) that is lexically inside an objc container + /// definition. + unsigned TopLevelDeclInObjCContainer : 1; + /// \brief Whether statistic collection is enabled. static bool StatisticsEnabled; @@ -294,11 +306,6 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// \brief Whether this declaration was loaded from an AST file. unsigned FromASTFile : 1; - /// \brief Whether this declaration is hidden from normal name lookup, e.g., - /// because it is was loaded from an AST file is either module-private or - /// because its submodule has not been made visible. - unsigned Hidden : 1; - /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. unsigned IdentifierNamespace : 13; @@ -332,26 +339,38 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { private: bool AccessDeclContextSanity() const; + /// Get the module ownership kind to use for a local lexical child of \p DC, + /// which may be either a local or (rarely) an imported declaration. + static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) { + if (DC) { + auto *D = cast(DC); + auto MOK = D->getModuleOwnershipKind(); + if (MOK != ModuleOwnershipKind::Unowned && + (!D->isFromASTFile() || D->hasLocalOwningModuleStorage())) + return MOK; + // If D is not local and we have no local module storage, then we don't + // need to track module ownership at all. + } + return ModuleOwnershipKind::Unowned; + } + protected: Decl(Kind DK, DeclContext *DC, SourceLocation L) - : NextInContextAndBits(), DeclCtx(DC), Loc(L), DeclKind(DK), - InvalidDecl(0), HasAttrs(false), Implicit(false), Used(false), - Referenced(false), Access(AS_none), FromASTFile(0), - Hidden(DC && cast(DC)->Hidden && - (!cast(DC)->isFromASTFile() || - hasLocalOwningModuleStorage())), + : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)), + DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(0), HasAttrs(false), + Implicit(false), Used(false), Referenced(false), + TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0), IdentifierNamespace(getIdentifierNamespaceForKind(DK)), CacheValidAndLinkage(0) { if (StatisticsEnabled) add(DK); } Decl(Kind DK, EmptyShell Empty) - : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), - HasAttrs(false), Implicit(false), Used(false), Referenced(false), - Access(AS_none), FromASTFile(0), Hidden(0), - IdentifierNamespace(getIdentifierNamespaceForKind(DK)), - CacheValidAndLinkage(0) - { + : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), HasAttrs(false), + Implicit(false), Used(false), Referenced(false), + TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0), + IdentifierNamespace(getIdentifierNamespaceForKind(DK)), + CacheValidAndLinkage(0) { if (StatisticsEnabled) add(DK); } @@ -551,16 +570,11 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// global variable, etc.) that is lexically inside an objc container /// definition. bool isTopLevelDeclInObjCContainer() const { - return NextInContextAndBits.getInt() & TopLevelDeclInObjCContainerFlag; + return TopLevelDeclInObjCContainer; } void setTopLevelDeclInObjCContainer(bool V = true) { - unsigned Bits = NextInContextAndBits.getInt(); - if (V) - Bits |= TopLevelDeclInObjCContainerFlag; - else - Bits &= ~TopLevelDeclInObjCContainerFlag; - NextInContextAndBits.setInt(Bits); + TopLevelDeclInObjCContainer = V; } /// \brief Looks on this and related declarations for an applicable @@ -570,7 +584,7 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// \brief Whether this declaration was marked as being private to the /// module in which it was defined. bool isModulePrivate() const { - return NextInContextAndBits.getInt() & ModulePrivateFlag; + return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate; } /// \brief Whether this declaration is exported (by virtue of being lexically @@ -585,15 +599,14 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { const Attr *getDefiningAttr() const; protected: - /// \brief Specify whether this declaration was marked as being private + /// \brief Specify that this declaration was marked as being private /// to the module in which it was defined. - void setModulePrivate(bool MP = true) { - unsigned Bits = NextInContextAndBits.getInt(); - if (MP) - Bits |= ModulePrivateFlag; - else - Bits &= ~ModulePrivateFlag; - NextInContextAndBits.setInt(Bits); + void setModulePrivate() { + // The module-private specifier has no effect on unowned declarations. + // FIXME: We should track this in some way for source fidelity. + if (getModuleOwnershipKind() == ModuleOwnershipKind::Unowned) + return; + setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate); } /// \brief Set the owning module ID. @@ -692,7 +705,7 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// \brief Get the imported owning module, if this decl is from an imported /// (non-local) module. Module *getImportedOwningModule() const { - if (!isFromASTFile()) + if (!isFromASTFile() || !hasOwningModule()) return nullptr; return getOwningModuleSlow(); @@ -701,31 +714,57 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// \brief Get the local owning module, if known. Returns nullptr if owner is /// not yet known or declaration is not from a module. Module *getLocalOwningModule() const { - if (isFromASTFile() || !Hidden) + if (isFromASTFile() || !hasOwningModule()) return nullptr; assert(hasLocalOwningModuleStorage() && - "hidden local decl but no local module storage"); + "owned local decl but no local module storage"); return reinterpret_cast(this)[-1]; } void setLocalOwningModule(Module *M) { - assert(!isFromASTFile() && Hidden && hasLocalOwningModuleStorage() && + assert(!isFromASTFile() && hasOwningModule() && + hasLocalOwningModuleStorage() && "should not have a cached owning module"); reinterpret_cast(this)[-1] = M; } + /// Is this declaration owned by some module? + bool hasOwningModule() const { + return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned; + } + + /// Get the module that owns this declaration. Module *getOwningModule() const { return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); } - /// \brief Determine whether this declaration is hidden from name lookup. - bool isHidden() const { return Hidden; } + /// \brief Determine whether this declaration might be hidden from name + /// lookup. Note that the declaration might be visible even if this returns + /// \c false, if the owning module is visible within the query context. + // FIXME: Rename this to make it clearer what it does. + bool isHidden() const { + return (int)getModuleOwnershipKind() > (int)ModuleOwnershipKind::Visible; + } + + /// Set that this declaration is globally visible, even if it came from a + /// module that is not visible. + void setVisibleDespiteOwningModule() { + if (hasOwningModule()) + setModuleOwnershipKind(ModuleOwnershipKind::Visible); + } + + /// \brief Get the kind of module ownership for this declaration. + ModuleOwnershipKind getModuleOwnershipKind() const { + return NextInContextAndBits.getInt(); + } /// \brief Set whether this declaration is hidden from name lookup. - void setHidden(bool Hide) { - assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) && - "declaration with no owning module can't be hidden"); - Hidden = Hide; + void setModuleOwnershipKind(ModuleOwnershipKind MOK) { + assert(!(getModuleOwnershipKind() == ModuleOwnershipKind::Unowned && + MOK != ModuleOwnershipKind::Unowned && !isFromASTFile() && + !hasLocalOwningModuleStorage()) && + "no storage available for owning module for this declaration"); + NextInContextAndBits.setInt(MOK); } unsigned getIdentifierNamespace() const { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 69767e068cb3..fabfdc9ef7e5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -894,7 +894,7 @@ void ASTContext::mergeDefinitionIntoModule(NamedDecl *ND, Module *M, if (getLangOpts().ModulesLocalVisibility) MergedDefModules[ND].push_back(M); else - ND->setHidden(false); + ND->setVisibleDespiteOwningModule(); } void ASTContext::deduplicateMergedDefinitonsFor(NamedDecl *ND) { diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 77ba6cf445dd..a0594a020362 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -278,12 +278,12 @@ void Decl::setLexicalDeclContext(DeclContext *DC) { // FIXME: We shouldn't be changing the lexical context of declarations // imported from AST files. if (!isFromASTFile()) { - Hidden = cast(DC)->Hidden && hasLocalOwningModuleStorage(); - if (Hidden) + setModuleOwnershipKind(getModuleOwnershipKindForChildOf(DC)); + if (hasOwningModule()) setLocalOwningModule(cast(DC)->getOwningModule()); } - assert((!Hidden || getOwningModule()) && + assert((!hasOwningModule() || getOwningModule()) && "hidden declaration has no owning module"); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2f78d06a82d6..b94b8d9e4c1c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -16104,7 +16104,10 @@ void Sema::ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod) { // lexically within the module. if (getLangOpts().trackLocalOwningModule()) { for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { - cast(DC)->setHidden(true); + cast(DC)->setModuleOwnershipKind( + getLangOpts().ModulesLocalVisibility + ? Decl::ModuleOwnershipKind::VisibleWhenImported + : Decl::ModuleOwnershipKind::Visible); cast(DC)->setLocalOwningModule(Mod); } } @@ -16144,7 +16147,8 @@ void Sema::ActOnModuleEnd(SourceLocation EomLoc, Module *Mod) { for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { cast(DC)->setLocalOwningModule(getCurrentModule()); if (!getCurrentModule()) - cast(DC)->setHidden(false); + cast(DC)->setModuleOwnershipKind( + Decl::ModuleOwnershipKind::Unowned); } } } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a9ff21bc41ab..710ead30790f 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2630,7 +2630,7 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, // Make the function visible to name lookup, even if we found it in // an unimported module. It either is an implicitly-declared global // allocation function, or is suppressing that function. - Func->setHidden(false); + Func->setVisibleDespiteOwningModule(); return; } } @@ -2662,7 +2662,7 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, FnType, /*TInfo=*/nullptr, SC_None, false, true); Alloc->setImplicit(); // Global allocation functions should always be visible. - Alloc->setHidden(false); + Alloc->setVisibleDespiteOwningModule(); // Implicit sized deallocation functions always have default visibility. Alloc->addAttr( diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 9f657a446c02..2e7fb875a276 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1341,7 +1341,7 @@ void Sema::makeMergedDefinitionVisible(NamedDecl *ND) { Context.mergeDefinitionIntoModule(ND, M); else // We're not building a module; just make the definition visible. - ND->setHidden(false); + ND->setVisibleDespiteOwningModule(); // If ND is a template declaration, make the template parameters // visible too. They're not (necessarily) within a mergeable DeclContext. @@ -1528,7 +1528,7 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { !SemaRef.getLangOpts().ModulesLocalVisibility) { // Cache the fact that this declaration is implicitly visible because // its parent has a visible definition. - D->setHidden(false); + D->setVisibleDespiteOwningModule(); } return true; } diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index fe92dd8ac653..f4f0c804aee1 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2045,7 +2045,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, // The instantiation is visible here, even if it was first declared in an // unimported module. - Instantiation->setHidden(false); + Instantiation->setVisibleDespiteOwningModule(); // FIXME: This loses the as-written tag kind for an explicit instantiation. Instantiation->setTagKind(Pattern->getTagKind()); @@ -2247,7 +2247,7 @@ bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, // The instantiation is visible here, even if it was first declared in an // unimported module. - Instantiation->setHidden(false); + Instantiation->setVisibleDespiteOwningModule(); // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 578386fc113d..abe912fb548b 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3868,7 +3868,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // The instantiation is visible here, even if it was first declared in an // unimported module. - Function->setHidden(false); + Function->setVisibleDespiteOwningModule(); // Copy the inner loc start from the pattern. Function->setInnerLocStart(PatternDecl->getInnerLocStart()); @@ -4274,7 +4274,7 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // The instantiation is visible here, even if it was first declared in an // unimported module. - Var->setHidden(false); + Var->setVisibleDespiteOwningModule(); // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index d033a9b32c0f..ef2841849ff6 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -3580,8 +3580,8 @@ static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); for (Decl *D : Names) { - bool wasHidden = D->Hidden; - D->Hidden = false; + bool wasHidden = D->isHidden(); + D->setVisibleDespiteOwningModule(); if (wasHidden && SemaObj) { if (ObjCMethodDecl *Method = dyn_cast(D)) { @@ -3648,7 +3648,7 @@ void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, if (Def->isHidden()) { // If MergedDef is visible or becomes visible, make the definition visible. if (!MergedDef->isHidden()) - Def->Hidden = false; + Def->setVisibleDespiteOwningModule(); else if (getContext().getLangOpts().ModulesLocalVisibility) { getContext().mergeDefinitionIntoModule( Def, MergedDef->getImportedOwningModule(), diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 3cc3a8efae3f..07ab421cfc51 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -522,31 +522,29 @@ void ASTDeclReader::VisitDecl(Decl *D) { D->setTopLevelDeclInObjCContainer(Record.readInt()); D->setAccess((AccessSpecifier)Record.readInt()); D->FromASTFile = true; - D->setModulePrivate(Record.readInt()); - D->Hidden = D->isModulePrivate(); + bool ModulePrivate = Record.readInt(); // Determine whether this declaration is part of a (sub)module. If so, it // may not yet be visible. if (unsigned SubmoduleID = readSubmoduleID()) { // Store the owning submodule ID in the declaration. + D->setModuleOwnershipKind( + ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate + : Decl::ModuleOwnershipKind::VisibleWhenImported); D->setOwningModuleID(SubmoduleID); - if (D->Hidden) { - // Module-private declarations are never visible, so there is no work to do. + if (ModulePrivate) { + // Module-private declarations are never visible, so there is no work to + // do. } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { // If local visibility is being tracked, this declaration will become - // hidden and visible as the owning module does. Inform Sema that this - // declaration might not be visible. - D->Hidden = true; + // hidden and visible as the owning module does. } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { - if (Owner->NameVisibility != Module::AllVisible) { - // The owning module is not visible. Mark this declaration as hidden. - D->Hidden = true; - - // Note that this declaration was hidden because its owning module is - // not yet visible. + // Mark the declaration as visible when its owning module becomes visible. + if (Owner->NameVisibility == Module::AllVisible) + D->setVisibleDespiteOwningModule(); + else Reader.HiddenNamesMap[Owner].push_back(D); - } } } } @@ -4144,7 +4142,7 @@ void ASTDeclReader::UpdateDecl(Decl *D) { Reader.HiddenNamesMap[Owner].push_back(Exported); } else { // The declaration is now visible. - Exported->Hidden = false; + Exported->setVisibleDespiteOwningModule(); } break; } diff --git a/test/Misc/ast-dump-decl.c b/test/Misc/ast-dump-decl.c index 45edea26b4f8..313c808c4ac8 100644 --- a/test/Misc/ast-dump-decl.c +++ b/test/Misc/ast-dump-decl.c @@ -1,8 +1,13 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix CHECK -strict-whitespace %s // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -check-prefix CHECK-TU -strict-whitespace %s +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=X -triple x86_64-unknown-unknown -fmodule-map-file=%S/Inputs/module.modulemap -ast-dump -ast-dump-filter Test %s -DMODULES | FileCheck -check-prefix CHECK -check-prefix CHECK-MODULES -strict-whitespace %s int TestLocation; -// CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:4:1, col:5> col:5 TestLocation +// CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:[[@LINE-1]]:1, col:5> col:5 TestLocation + +#ifdef MODULES +#pragma clang module begin X +#endif struct TestIndent { int x; @@ -33,7 +38,7 @@ typedef int TestTypedefDecl; // CHECK: TypedefDecl{{.*}} TestTypedefDecl 'int' __module_private__ typedef int TestTypedefDeclPrivate; -// CHECK: TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__ +// CHECK-MODULE: TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__ enum TestEnumDecl { testEnumDecl @@ -53,7 +58,7 @@ enum TestEnumDeclForward; // CHECK: EnumDecl{{.*}} TestEnumDeclForward __module_private__ enum TestEnumDeclPrivate; -// CHECK: EnumDecl{{.*}} TestEnumDeclPrivate __module_private__ +// CHECK-MODULE: EnumDecl{{.*}} TestEnumDeclPrivate __module_private__ struct TestRecordDecl { int i; @@ -83,7 +88,7 @@ struct TestRecordDeclForward; // CHECK: RecordDecl{{.*}} struct TestRecordDeclForward __module_private__ struct TestRecordDeclPrivate; -// CHECK: RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__ +// CHECK-MODULE: RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__ enum testEnumConstantDecl { TestEnumConstantDecl, @@ -136,7 +141,7 @@ struct testFieldDecl { // CHECK: FieldDecl{{.*}} TestFieldDecl 'int' // CHECK: FieldDecl{{.*}} TestFieldDeclWidth 'int' // CHECK-NEXT: IntegerLiteral -// CHECK: FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__ +// CHECK-MODULE: FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__ int TestVarDecl; // CHECK: VarDecl{{.*}} TestVarDecl 'int' @@ -148,7 +153,7 @@ __thread int TestVarDeclThread; // CHECK: VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}} __module_private__ int TestVarDeclPrivate; -// CHECK: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__ +// CHECK-MODULE: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__ int TestVarDeclInit = 0; // CHECK: VarDecl{{.*}} TestVarDeclInit 'int' @@ -156,3 +161,8 @@ int TestVarDeclInit = 0; void testParmVarDecl(int TestParmVarDecl); // CHECK: ParmVarDecl{{.*}} TestParmVarDecl 'int' + +#ifdef MODULES +#pragma clang module end +#endif + diff --git a/test/Misc/ast-dump-decl.cpp b/test/Misc/ast-dump-decl.cpp index e1cdeb0995fa..7370f46c5b32 100644 --- a/test/Misc/ast-dump-decl.cpp +++ b/test/Misc/ast-dump-decl.cpp @@ -95,17 +95,12 @@ class TestCXXRecordDeclPack : public T... { thread_local int TestThreadLocalInt; // CHECK: TestThreadLocalInt {{.*}} tls_dynamic -__module_private__ class TestCXXRecordDeclPrivate; -// CHECK: CXXRecordDecl{{.*}} class TestCXXRecordDeclPrivate __module_private__ - class testCXXMethodDecl { - __module_private__ void TestCXXMethodDeclPrivate(); virtual void TestCXXMethodDeclPure() = 0; void TestCXXMethodDeclDelete() = delete; void TestCXXMethodDeclThrow() throw(); void TestCXXMethodDeclThrowType() throw(int); }; -// CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPrivate 'void (void)' __module_private__ // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclPure 'void (void)' virtual pure // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclDelete 'void (void)' delete // CHECK: CXXMethodDecl{{.*}} TestCXXMethodDeclThrow 'void (void) throw()' From 516572b01686e96be619f9ae090ca4bb0166cb30 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 23 Jun 2017 01:18:27 +0000 Subject: [PATCH 039/214] Add missing file from r306075. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306077 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Misc/Inputs/module.modulemap | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/Misc/Inputs/module.modulemap diff --git a/test/Misc/Inputs/module.modulemap b/test/Misc/Inputs/module.modulemap new file mode 100644 index 000000000000..a8ecb09390a2 --- /dev/null +++ b/test/Misc/Inputs/module.modulemap @@ -0,0 +1 @@ +module X {} From 742c4c842393005d91a6f805f665b077014d061a Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Fri, 23 Jun 2017 02:38:45 +0000 Subject: [PATCH 040/214] [Frontend] 'Show hotness' can be used with a sampling profile Summary: Prior to this change, using `-fdiagnostics-show-hotness` with a sampling profile specified via `-fprofile-sample-use=` would result in the Clang frontend emitting a warning: "argument '-fdiagnostics-show-hotness' requires profile-guided optimization information". Of course, a sampling profile *is* profile-guided optimization information, so the warning is misleading. Furthermore, despite the warning, hotness was displayed based on the data in the sampling profile. Prevent the warning from being emitted when a sampling profile is used, and add a test that verifies this. Reviewers: anemet, davidxl Reviewed By: davidxl Subscribers: danielcdh, cfe-commits Differential Revision: https://reviews.llvm.org/D34082 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306079 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInvocation.cpp | 8 ++++++-- .../optimization-remark-with-hotness-sample.proftext | 7 +++++++ test/Frontend/optimization-remark-with-hotness.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index e6feaf7447dd..203723953a6f 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -892,14 +892,18 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DiagnosticsWithHotness = Args.hasArg(options::OPT_fdiagnostics_show_hotness); + bool UsingSampleProfile = !Opts.SampleProfileFile.empty(); + if (Opts.DiagnosticsWithHotness && - Opts.getProfileUse() == CodeGenOptions::ProfileNone) + Opts.getProfileUse() == CodeGenOptions::ProfileNone && + !UsingSampleProfile) { Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo); + } // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile // can be incorporated into the IR. - if (!Opts.SampleProfileFile.empty()) + if (UsingSampleProfile) NeedLocTracking = true; // If the user requested a flag that requires source locations available in diff --git a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext new file mode 100644 index 000000000000..aeea583de4d4 --- /dev/null +++ b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext @@ -0,0 +1,7 @@ +foo:0:0 + 0: 0 +bar:29:29 + 6: foo:0 +main:0:0 + 0: 0 bar:0 + diff --git a/test/Frontend/optimization-remark-with-hotness.c b/test/Frontend/optimization-remark-with-hotness.c index 708f5ec8d4bf..30ead64b8eb5 100644 --- a/test/Frontend/optimization-remark-with-hotness.c +++ b/test/Frontend/optimization-remark-with-hotness.c @@ -1,11 +1,21 @@ +// Generate instrumentation and sampling profile data. // RUN: llvm-profdata merge \ -// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \ +// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \ // RUN: -o %t.profdata +// RUN: llvm-profdata merge -sample \ +// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \ +// RUN: -o %t-sample.profdata +// // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ // RUN: -fdiagnostics-show-hotness -verify +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline -Rpass-missed=inline \ +// RUN: -fdiagnostics-show-hotness -verify // The clang version of the previous test. // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \ // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \ From 8864382ad994c9d0b90802128e349c04677feb4d Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 23 Jun 2017 08:48:00 +0000 Subject: [PATCH 041/214] [clang-format] Update style documentation, NFC Summary: Style documentation is generated automatically by `docs/tools/dump_format_style.py`. This hasn't been ran for a while. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34457 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306089 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangFormatStyleOptions.rst | 109 +++++++++++++++++++++++++++---- include/clang/Format/Format.h | 11 ++-- 2 files changed, 101 insertions(+), 19 deletions(-) diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index fb014241809c..a94a8b67a42f 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -309,12 +309,28 @@ the configuration (without a prefix: ``Auto``). * ``SFS_None`` (in configuration: ``None``) Never merge functions into a single line. + * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) + Only merge functions defined inside a class. Same as "inline", + except it does not implies "empty": i.e. top level empty functions + are not merged either. + + .. code-block:: c++ + + class Foo { + void f() { foo(); } + }; + void f() { + foo(); + } + void f() { + } + * ``SFS_Empty`` (in configuration: ``Empty``) Only merge empty functions. .. code-block:: c++ - void f() { bar(); } + void f() {} void f2() { bar2(); } @@ -327,6 +343,10 @@ the configuration (without a prefix: ``Auto``). class Foo { void f() { foo(); } }; + void f() { + foo(); + } + void f() {} * ``SFS_All`` (in configuration: ``All``) Merge all functions fitting on a single line. @@ -521,11 +541,11 @@ the configuration (without a prefix: ``Auto``). .. code-block:: c++ true: - class foo - {}; + class foo {}; false: - class foo {}; + class foo + {}; * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..). @@ -659,6 +679,18 @@ the configuration (without a prefix: ``Auto``). * ``bool IndentBraces`` Indent the wrapped braces themselves. + * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line. + This option is used only if the opening brace of the function has + already been wrapped, i.e. the `AfterFunction` brace wrapping mode is + set, and the function could/should not be put on a single line (as per + `AllowShortFunctionsOnASingleLine` and constructor formatting options). + + .. code-block:: c++ + + int f() vs. inf f() + {} { + } + **BreakAfterJavaFieldAnnotations** (``bool``) Break after each annotation on a field in Java files. @@ -899,17 +931,40 @@ the configuration (without a prefix: ``Auto``). firstValue : SecondValueVeryVeryVeryVeryLong; -**BreakConstructorInitializersBeforeComma** (``bool``) - Always break constructor initializers before commas and align - the commas with the colon. +**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) + The constructor initializers style to use. + + Possible values: + + * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) + Break constructor initializers before the colon and after the commas. + + .. code-block:: c++ + + Constructor() + : initializer1(), + initializer2() + + * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) + Break constructor initializers before the colon and commas, and align + the commas with the colon. + + .. code-block:: c++ + + Constructor() + : initializer1() + , initializer2() + + * ``BCIS_AfterColon`` (in configuration: ``AfterColon``) + Break constructor initializers after the colon and commas. + + .. code-block:: c++ + + Constructor() : + initializer1(), + initializer2() - .. code-block:: c++ - true: false: - SomeClass::Constructor() vs. SomeClass::Constructor() : a(a), - : a(a) b(b), - , b(b) c(c) {} - , c(c) {} **BreakStringLiterals** (``bool``) Allow breaking string literals when formatting. @@ -931,6 +986,31 @@ the configuration (without a prefix: ``Auto``). // Will leave the following line unaffected #include // FOOBAR pragma: keep +**CompactNamespaces** (``bool``) + If ``true``, consecutive namespace declarations will be on the same + line. If ``false``, each namespace is declared on a new line. + + .. code-block:: c++ + + true: + namespace Foo { namespace Bar { + }} + + false: + namespace Foo { + namespace Bar { + } + } + + If it does not fit on a single line, the overflowing namespaces get + wrapped: + + .. code-block:: c++ + + namespace Foo { namespace Bar { + namespace Extra { + }}} + **ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) If the constructor initializers don't fit on a line, put each initializer on its own line. @@ -1321,6 +1401,9 @@ the configuration (without a prefix: ``Auto``). Add a space in front of an Objective-C protocol list, i.e. use ``Foo `` instead of ``Foo``. +**PenaltyBreakAssignment** (``unsigned``) + The penalty for breaking around an assignment operator. + **PenaltyBreakBeforeFirstCallParameter** (``unsigned``) The penalty for breaking a function call after ``call(``. diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 0a3e55440376..72f31943ed21 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -652,12 +652,12 @@ struct FormatStyle { /// struct foo /// { /// int x; - /// } + /// }; /// /// false: /// struct foo { /// int x; - /// } + /// }; /// \endcode bool AfterStruct; /// \brief Wrap union definitions. @@ -733,7 +733,7 @@ struct FormatStyle { /// ? firstValue /// : SecondValueVeryVeryVeryVeryLong; /// - /// true: + /// false: /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? /// firstValue : /// SecondValueVeryVeryVeryVeryLong; @@ -741,8 +741,7 @@ struct FormatStyle { bool BreakBeforeTernaryOperators; /// \brief Different ways to break initializers. - enum BreakConstructorInitializersStyle - { + enum BreakConstructorInitializersStyle { /// Break constructor initializers before the colon and after the commas. /// \code /// Constructor() @@ -767,7 +766,7 @@ struct FormatStyle { BCIS_AfterColon }; - /// \brief The constructor initializers style to use.. + /// \brief The constructor initializers style to use. BreakConstructorInitializersStyle BreakConstructorInitializers; /// \brief Break after each annotation on a field in Java files. From 4c8bc8646c93899503aa9efbb92832e952c4bbec Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 23 Jun 2017 11:29:40 +0000 Subject: [PATCH 042/214] [clang-format] Update dump_format_style.py to indent nested fields Summary: This updates the format options documentation script to indent the documentation of nested fields. The previous format caused some problems, as when a bulleted list ends with a multiline comment. See the buildbot failure http://lab.llvm.org:8011/builders/clang-sphinx-docs/builds/10020/steps/docs-clang-html/logs/stdio Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34552 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306093 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangFormatStyleOptions.rst | 204 +++++++++++++++---------------- docs/tools/dump_format_style.py | 11 +- 2 files changed, 108 insertions(+), 107 deletions(-) diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index a94a8b67a42f..8555f06875cf 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -538,158 +538,158 @@ the configuration (without a prefix: ``Auto``). * ``bool AfterClass`` Wrap class definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - class foo {}; + true: + class foo {}; - false: - class foo - {}; + false: + class foo + {}; * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..). - .. code-block:: c++ + .. code-block:: c++ - true: - if (foo()) - { - } else - {} - for (int i = 0; i < 10; ++i) - {} + true: + if (foo()) + { + } else + {} + for (int i = 0; i < 10; ++i) + {} - false: - if (foo()) { - } else { - } - for (int i = 0; i < 10; ++i) { - } + false: + if (foo()) { + } else { + } + for (int i = 0; i < 10; ++i) { + } * ``bool AfterEnum`` Wrap enum definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - enum X : int - { - B - }; + true: + enum X : int + { + B + }; - false: - enum X : int { B }; + false: + enum X : int { B }; * ``bool AfterFunction`` Wrap function definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - void foo() - { - bar(); - bar2(); - } + true: + void foo() + { + bar(); + bar2(); + } - false: - void foo() { - bar(); - bar2(); - } + false: + void foo() { + bar(); + bar2(); + } * ``bool AfterNamespace`` Wrap namespace definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - namespace - { - int foo(); - int bar(); - } + true: + namespace + { + int foo(); + int bar(); + } - false: - namespace { - int foo(); - int bar(); - } + false: + namespace { + int foo(); + int bar(); + } * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..). * ``bool AfterStruct`` Wrap struct definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - struct foo - { - int x; - }; + true: + struct foo + { + int x; + }; - false: - struct foo { - int x; - }; + false: + struct foo { + int x; + }; * ``bool AfterUnion`` Wrap union definitions. - .. code-block:: c++ + .. code-block:: c++ - true: - union foo - { - int x; - } + true: + union foo + { + int x; + } - false: - union foo { - int x; - } + false: + union foo { + int x; + } * ``bool BeforeCatch`` Wrap before ``catch``. - .. code-block:: c++ + .. code-block:: c++ - true: - try { - foo(); - } - catch () { - } + true: + try { + foo(); + } + catch () { + } - false: - try { - foo(); - } catch () { - } + false: + try { + foo(); + } catch () { + } * ``bool BeforeElse`` Wrap before ``else``. - .. code-block:: c++ + .. code-block:: c++ - true: - if (foo()) { - } - else { - } + true: + if (foo()) { + } + else { + } - false: - if (foo()) { - } else { - } + false: + if (foo()) { + } else { + } * ``bool IndentBraces`` Indent the wrapped braces themselves. * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line. - This option is used only if the opening brace of the function has - already been wrapped, i.e. the `AfterFunction` brace wrapping mode is - set, and the function could/should not be put on a single line (as per - `AllowShortFunctionsOnASingleLine` and constructor formatting options). + This option is used only if the opening brace of the function has + already been wrapped, i.e. the `AfterFunction` brace wrapping mode is + set, and the function could/should not be put on a single line (as per + `AllowShortFunctionsOnASingleLine` and constructor formatting options). - .. code-block:: c++ + .. code-block:: c++ - int f() vs. inf f() - {} { - } + int f() vs. inf f() + {} { + } **BreakAfterJavaFieldAnnotations** (``bool``) diff --git a/docs/tools/dump_format_style.py b/docs/tools/dump_format_style.py index 81a5af6ef42b..e2571f46448d 100755 --- a/docs/tools/dump_format_style.py +++ b/docs/tools/dump_format_style.py @@ -24,10 +24,10 @@ def doxygen2rst(text): text = re.sub(r'\\\w+ ', '', text) return text -def indent(text, columns): +def indent(text, columns, indent_first_line=True): indent = ' ' * columns s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S) - if s.startswith('\n'): + if not indent_first_line or s.startswith('\n'): return s return indent + s @@ -64,7 +64,9 @@ def __init__(self, name, comment): self.comment = comment.strip() def __str__(self): - return '\n* ``%s`` %s' % (self.name, doxygen2rst(self.comment)) + return '\n* ``%s`` %s' % ( + self.name, + doxygen2rst(indent(self.comment, 2, indent_first_line=False))) class Enum: def __init__(self, name, comment): @@ -179,7 +181,7 @@ class State: if enums.has_key(option.type): option.enum = enums[option.type] elif nested_structs.has_key(option.type): - option.nested_struct = nested_structs[option.type]; + option.nested_struct = nested_structs[option.type] else: raise Exception('Unknown type: %s' % option.type) return options @@ -195,4 +197,3 @@ class State: with open(DOC_FILE, 'wb') as output: output.write(contents) - From 598aad0fe0d99790d34390533e51e3d0e85531ef Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 23 Jun 2017 11:46:03 +0000 Subject: [PATCH 043/214] [clang-format] Add a SortUsingDeclaration option and enable it by default Summary: This patch adds a `SortUsingDeclaration` style option and enables it for llvm style. Reviewers: klimek Reviewed By: klimek Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34453 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306094 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangFormatStyleOptions.rst | 9 ++++ include/clang/Format/Format.h | 8 ++++ lib/Format/Format.cpp | 70 ++++++++++++++++++++------------ unittests/Format/FormatTest.cpp | 8 ++++ 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index 8555f06875cf..6133ca9900c9 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -1475,6 +1475,15 @@ the configuration (without a prefix: ``Auto``). #include "b.h" vs. #include "a.h" #include "a.h" #include "b.h" +**SortUsingDeclarations** (``bool``) + If ``true``, clang-format will sort using declarations. + + .. code-block:: c++ + + false: true: + using std::cout; vs. using std::cin; + using std::cin; using std::cout; + **SpaceAfterCStyleCast** (``bool``) If ``true``, a space is inserted after C style casts. diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 72f31943ed21..c1b62477ed1c 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1270,6 +1270,14 @@ struct FormatStyle { /// \endcode bool SortIncludes; + /// \brief If ``true``, clang-format will sort using declarations. + /// \code + /// false: true: + /// using std::cout; vs. using std::cin; + /// using std::cin; using std::cout; + /// \endcode + bool SortUsingDeclarations; + /// \brief If ``true``, a space is inserted after C style casts. /// \code /// true: false: diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 3e3667bfd829..7659d56adf25 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -379,6 +379,7 @@ template <> struct MappingTraits { IO.mapOptional("PointerAlignment", Style.PointerAlignment); IO.mapOptional("ReflowComments", Style.ReflowComments); IO.mapOptional("SortIncludes", Style.SortIncludes); + IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations); IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast); IO.mapOptional("SpaceAfterTemplateKeyword", Style.SpaceAfterTemplateKeyword); IO.mapOptional("SpaceBeforeAssignmentOperators", @@ -619,6 +620,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.DisableFormat = false; LLVMStyle.SortIncludes = true; + LLVMStyle.SortUsingDeclarations = true; return LLVMStyle; } @@ -773,6 +775,7 @@ FormatStyle getNoStyle() { FormatStyle NoStyle = getLLVMStyle(); NoStyle.DisableFormat = true; NoStyle.SortIncludes = false; + NoStyle.SortUsingDeclarations = false; return NoStyle; } @@ -1879,38 +1882,53 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, return tooling::Replacements(); if (Expanded.Language == FormatStyle::LK_JavaScript && isMpegTS(Code)) return tooling::Replacements(); - auto Env = Environment::CreateVirtualEnvironment(Code, FileName, Ranges); - - auto reformatAfterApplying = [&] (TokenAnalyzer& Fixer) { - tooling::Replacements Fixes = Fixer.process(); - if (!Fixes.empty()) { - auto NewCode = applyAllReplacements(Code, Fixes); - if (NewCode) { - auto NewEnv = Environment::CreateVirtualEnvironment( - *NewCode, FileName, - tooling::calculateRangesAfterReplacements(Fixes, Ranges)); - Formatter Format(*NewEnv, Expanded, Status); - return Fixes.merge(Format.process()); - } - } - Formatter Format(*Env, Expanded, Status); - return Format.process(); - }; - if (Style.Language == FormatStyle::LK_Cpp && - Style.FixNamespaceComments) { - NamespaceEndCommentsFixer CommentsFixer(*Env, Expanded); - return reformatAfterApplying(CommentsFixer); + typedef std::function + AnalyzerPass; + SmallVector Passes; + + if (Style.Language == FormatStyle::LK_Cpp) { + if (Style.FixNamespaceComments) + Passes.emplace_back([&](const Environment &Env) { + return NamespaceEndCommentsFixer(Env, Expanded).process(); + }); + + if (Style.SortUsingDeclarations) + Passes.emplace_back([&](const Environment &Env) { + return UsingDeclarationsSorter(Env, Expanded).process(); + }); } if (Style.Language == FormatStyle::LK_JavaScript && - Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) { - JavaScriptRequoter Requoter(*Env, Expanded); - return reformatAfterApplying(Requoter); + Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) + Passes.emplace_back([&](const Environment &Env) { + return JavaScriptRequoter(Env, Expanded).process(); + }); + + Passes.emplace_back([&](const Environment &Env) { + return Formatter(Env, Expanded, Status).process(); + }); + + std::unique_ptr Env = + Environment::CreateVirtualEnvironment(Code, FileName, Ranges); + llvm::Optional CurrentCode = None; + tooling::Replacements Fixes; + for (size_t I = 0, E = Passes.size(); I < E; ++I) { + tooling::Replacements PassFixes = Passes[I](*Env); + auto NewCode = applyAllReplacements( + CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes); + if (NewCode) { + Fixes = Fixes.merge(PassFixes); + if (I + 1 < E) { + CurrentCode = std::move(*NewCode); + Env = Environment::CreateVirtualEnvironment( + *CurrentCode, FileName, + tooling::calculateRangesAfterReplacements(Fixes, Ranges)); + } + } } - Formatter Format(*Env, Expanded, Status); - return Format.process(); + return Fixes; } tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b43f735d4cb7..64bb28e0be23 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -9333,6 +9333,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) { CHECK_PARSE_BOOL(Cpp11BracedListStyle); CHECK_PARSE_BOOL(ReflowComments); CHECK_PARSE_BOOL(SortIncludes); + CHECK_PARSE_BOOL(SortUsingDeclarations); CHECK_PARSE_BOOL(SpacesInParentheses); CHECK_PARSE_BOOL(SpacesInSquareBrackets); CHECK_PARSE_BOOL(SpacesInAngles); @@ -10874,6 +10875,13 @@ TEST_F(ReplacementTest, SortIncludesAfterReplacement) { EXPECT_EQ(Expected, *Result); } +TEST_F(FormatTest, FormatSortsUsingDeclarations) { + EXPECT_EQ("using std::cin;\n" + "using std::cout;", + format("using std::cout;\n" + "using std::cin;", getGoogleStyle())); +} + TEST_F(FormatTest, UTF8CharacterLiteralCpp03) { format::FormatStyle Style = format::getLLVMStyle(); Style.Standard = FormatStyle::LS_Cpp03; From bd5d53a9d06c7249efdb3edd7046ed8bf76433be Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 23 Jun 2017 14:10:07 +0000 Subject: [PATCH 044/214] PR26195: Set correct NestedNameSpecifierLoc for the dependent initializer This commit fixes incorrect source positions of dependent c'tor initializers like in the following code: template struct Derived: MyBase::InnerIterator { Derived() : MyBase::InnerIterator() {} /// This line is problematic: all positions point to InnerIterator and nothing points to MyBase }; Patch by Serge Preis! Differential Revision: https://reviews.llvm.org/D32439 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306103 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 9 +++ test/Index/ctor-init-source-loc.cpp | 117 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 test/Index/ctor-init-source-loc.cpp diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0b46e15bb0a3..27b5221fb9f7 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3778,6 +3778,15 @@ Sema::BuildMemInitializer(Decl *ConstructorD, if (BaseType.isNull()) return true; + TInfo = Context.CreateTypeSourceInfo(BaseType); + DependentNameTypeLoc TL = + TInfo->getTypeLoc().castAs(); + if (!TL.isNull()) { + TL.setNameLoc(IdLoc); + TL.setElaboratedKeywordLoc(SourceLocation()); + TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } + R.clear(); R.setLookupName(MemberOrBase); } diff --git a/test/Index/ctor-init-source-loc.cpp b/test/Index/ctor-init-source-loc.cpp new file mode 100644 index 000000000000..330e9c43246c --- /dev/null +++ b/test/Index/ctor-init-source-loc.cpp @@ -0,0 +1,117 @@ +// RUN: c-index-test -test-load-source all %s | FileCheck %s +template +struct Derived: MyBase::InnerIterator +{ + Derived() : MyBase::InnerIterator() {} +// CHECK: TypeRef=MyBase:2:19 Extent=[5:17 - 5:23] +}; + +template +struct Derived2: MyBase::Deeper::InnerIterator +{ + Derived2() : MyBase::Deeper::InnerIterator() {} +// CHECK: TypeRef=MyBase:9:19 Extent=[12:18 - 12:24] +}; + +template +struct Templ; + +template +struct Derived3: Templ::InnerIterator +{ + Derived3() : Templ::InnerIterator() {} +// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23] +// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30] +}; + + +struct Outer { + template + struct Inner { + typedef Q Parm; + }; +}; + +template +struct Derived4: Outer::Inner::Parm +{ + Derived4() : Outer::Inner::Parm() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30] +// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32] +}; + +template +struct Derived5: Outer::Inner::Parm::InnerIterator +{ + Derived5() : Outer::Inner::Parm::InnerIterator() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30] +// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32] +}; + +template +struct Derived6: Outer::Inner +{ + Derived6() : Outer::Inner() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30] +// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32] +}; + +struct Base {}; + +struct Derived7: Outer::Inner::Parm +{ + Derived7() : Outer::Inner::Parm() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30] +// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35] +}; + +struct Derived8: Outer::Inner +{ + Derived8() : Outer::Inner() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30] +// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35] +}; + +namespace Namespace { + template struct Templ; + + struct Outer { + template + struct Inner { + typedef Q Parm; + }; + }; +} + +template +struct Derived9: Namespace::Templ::InnerIterator +{ + Derived9() : Namespace::Templ::InnerIterator() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27] +// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34] +// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41] +}; + +template +struct Derived10: Namespace::Templ +{ + Derived10() : Namespace::Templ() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28] +// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35] +// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42] +}; + +template +struct Derived11: Namespace::Outer::Inner::Parm +{ + Derived11() : Namespace::Outer::Inner::Parm() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28] +// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35] +// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42] +// CHECK: TypeRef=MyBase:109:19 Extent=[112:43 - 112:49] +}; From 4b3bb6fed5ee72f92da9b8028e4c5040cbe329a5 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 23 Jun 2017 15:10:54 +0000 Subject: [PATCH 045/214] Revert r306103: "PR26195: Set correct NestedNameSpecifierLoc for the dependent initializer" It caused buildbot failures such as this one: http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA/builds/3777/steps/test_clang/logs/Clang%20%3A%3A%20Index__ctor-init-source-loc.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306111 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 9 --- test/Index/ctor-init-source-loc.cpp | 117 ---------------------------- 2 files changed, 126 deletions(-) delete mode 100644 test/Index/ctor-init-source-loc.cpp diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 27b5221fb9f7..0b46e15bb0a3 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3778,15 +3778,6 @@ Sema::BuildMemInitializer(Decl *ConstructorD, if (BaseType.isNull()) return true; - TInfo = Context.CreateTypeSourceInfo(BaseType); - DependentNameTypeLoc TL = - TInfo->getTypeLoc().castAs(); - if (!TL.isNull()) { - TL.setNameLoc(IdLoc); - TL.setElaboratedKeywordLoc(SourceLocation()); - TL.setQualifierLoc(SS.getWithLocInContext(Context)); - } - R.clear(); R.setLookupName(MemberOrBase); } diff --git a/test/Index/ctor-init-source-loc.cpp b/test/Index/ctor-init-source-loc.cpp deleted file mode 100644 index 330e9c43246c..000000000000 --- a/test/Index/ctor-init-source-loc.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// RUN: c-index-test -test-load-source all %s | FileCheck %s -template -struct Derived: MyBase::InnerIterator -{ - Derived() : MyBase::InnerIterator() {} -// CHECK: TypeRef=MyBase:2:19 Extent=[5:17 - 5:23] -}; - -template -struct Derived2: MyBase::Deeper::InnerIterator -{ - Derived2() : MyBase::Deeper::InnerIterator() {} -// CHECK: TypeRef=MyBase:9:19 Extent=[12:18 - 12:24] -}; - -template -struct Templ; - -template -struct Derived3: Templ::InnerIterator -{ - Derived3() : Templ::InnerIterator() {} -// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23] -// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30] -}; - - -struct Outer { - template - struct Inner { - typedef Q Parm; - }; -}; - -template -struct Derived4: Outer::Inner::Parm -{ - Derived4() : Outer::Inner::Parm() {} -// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23] -// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30] -// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32] -}; - -template -struct Derived5: Outer::Inner::Parm::InnerIterator -{ - Derived5() : Outer::Inner::Parm::InnerIterator() {} -// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23] -// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30] -// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32] -}; - -template -struct Derived6: Outer::Inner -{ - Derived6() : Outer::Inner() {} -// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23] -// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30] -// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32] -}; - -struct Base {}; - -struct Derived7: Outer::Inner::Parm -{ - Derived7() : Outer::Inner::Parm() {} -// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23] -// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30] -// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35] -}; - -struct Derived8: Outer::Inner -{ - Derived8() : Outer::Inner() {} -// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23] -// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30] -// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35] -}; - -namespace Namespace { - template struct Templ; - - struct Outer { - template - struct Inner { - typedef Q Parm; - }; - }; -} - -template -struct Derived9: Namespace::Templ::InnerIterator -{ - Derived9() : Namespace::Templ::InnerIterator() {} -// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27] -// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34] -// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41] -}; - -template -struct Derived10: Namespace::Templ -{ - Derived10() : Namespace::Templ() {} -// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28] -// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35] -// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42] -}; - -template -struct Derived11: Namespace::Outer::Inner::Parm -{ - Derived11() : Namespace::Outer::Inner::Parm() {} -// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28] -// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35] -// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42] -// CHECK: TypeRef=MyBase:109:19 Extent=[112:43 - 112:49] -}; From 418fa968089358756aafbb9eb06429fbad2ce88a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 23 Jun 2017 15:34:16 +0000 Subject: [PATCH 046/214] Revert "Revert r305164/5/7." Restore the `-gz` option to the driver with some minor tweaks to handle the additional case for `-Wa,--compress-debug-sections`. This intends to make the compression of the debug information controllable from the driver. The following is the behaviour: -gz enable compression (ambiguous for format, will default to zlib-gnu) -gz=none disable compression -gz=zlib-gnu enable compression (deprecated GNU style zlib compression) -gz=zlib enable compression (zlib based compression) Although -Wa,-compress-debug-sections works, it should be discouraged when using the driver to invoke the assembler. However, we permit the assembler to accept the GNU as style argument --compress-debug-sections to maintain compatibility. Note, -gz/-gz= does *NOT* imply -g. That is, you need to additionally specific -g for debug information to be generated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306115 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 7 ++-- include/clang/Driver/Options.td | 4 +++ lib/Driver/ToolChains/Clang.cpp | 55 +++++++++++++++++++++-------- lib/Driver/ToolChains/Gnu.cpp | 19 ++++++++++ lib/Frontend/CompilerInvocation.cpp | 19 ++++++++-- test/Driver/compress-noias.c | 37 +++++++++++++++++++ test/Driver/compress.c | 38 +++++++++++++++++--- test/Driver/nozlibcompress.c | 9 ++--- test/Misc/cc1as-compress.s | 8 +++++ tools/driver/cc1as_main.cpp | 19 ++++++++-- 10 files changed, 182 insertions(+), 33 deletions(-) create mode 100644 test/Driver/compress-noias.c create mode 100644 test/Misc/cc1as-compress.s diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 1132d1345f60..10c4cff64770 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -134,7 +134,6 @@ def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">, //===----------------------------------------------------------------------===// let Flags = [CC1Option, CC1AsOption, NoDriverOption] in { - def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">; def debug_info_macro : Flag<["-"], "debug-info-macro">, HelpText<"Emit macro debug information">; @@ -144,14 +143,16 @@ def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">, HelpText<"The compilation directory to embed in the debug info.">; def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">, HelpText<"The string to embed in the Dwarf debug flags record.">; +def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">, + HelpText<"DWARF debug sections compression">; +def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">, + HelpText<"DWARF debug sections compression type">; def mno_exec_stack : Flag<["-"], "mnoexecstack">, HelpText<"Mark the file as not needing an executable stack">; def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">, HelpText<"Make assembler warnings fatal">; def mrelax_relocations : Flag<["--"], "mrelax-relocations">, HelpText<"Use relaxable elf relocations">; -def compress_debug_sections : Flag<["-"], "compress-debug-sections">, - HelpText<"Compress DWARF debug sections using zlib">; def msave_temp_labels : Flag<["-"], "msave-temp-labels">, HelpText<"Save temporary labels in the symbol table. " "Note this may change .s semantics and shouldn't generally be used " diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index bd4d521752a1..68b331fed2bd 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1563,6 +1563,10 @@ def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group; def gmodules : Flag <["-"], "gmodules">, Group, HelpText<"Generate debug info with external references to clang modules" " or precompiled headers">; +def gz : Flag<["-"], "gz">, Group, + HelpText<"DWARF debug sections compression type">; +def gz_EQ : Joined<["-"], "gz=">, Group, + HelpText<"DWARF debug sections compression type">; def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">; def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>, HelpText<"Display available options">; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index bd4e894d6504..292cf72b56ca 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -910,6 +910,37 @@ static void RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs, } } +static void RenderDebugInfoCompressionArgs(const ArgList &Args, + ArgStringList &CmdArgs, + const Driver &D) { + const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ); + if (!A) + return; + + if (A->getOption().getID() == options::OPT_gz) { + if (llvm::zlib::isAvailable()) + CmdArgs.push_back("-compress-debug-sections"); + else + D.Diag(diag::warn_debug_compression_unavailable); + return; + } + + StringRef Value = A->getValue(); + if (Value == "none") { + CmdArgs.push_back("-compress-debug-sections=none"); + } else if (Value == "zlib" || Value == "zlib-gnu") { + if (llvm::zlib::isAvailable()) { + CmdArgs.push_back( + Args.MakeArgString("-compress-debug-sections=" + Twine(Value))); + } else { + D.Diag(diag::warn_debug_compression_unavailable); + } + } else { + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Value; + } +} + static const char *RelocationModelName(llvm::Reloc::Model Model) { switch (Model) { case llvm::Reloc::Static: @@ -1747,10 +1778,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, // arg after parsing the '-I' arg. bool TakeNextArg = false; - // When using an integrated assembler, translate -Wa, and -Xassembler - // options. - bool CompressDebugSections = false; - bool UseRelaxRelocations = ENABLE_X86_RELAX_RELOCATIONS; const char *MipsTargetFeature = nullptr; for (const Arg *A : @@ -1825,12 +1852,11 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, CmdArgs.push_back("-massembler-fatal-warnings"); } else if (Value == "--noexecstack") { CmdArgs.push_back("-mnoexecstack"); - } else if (Value == "-compress-debug-sections" || - Value == "--compress-debug-sections") { - CompressDebugSections = true; - } else if (Value == "-nocompress-debug-sections" || + } else if (Value.startswith("-compress-debug-sections") || + Value.startswith("--compress-debug-sections") || + Value == "-nocompress-debug-sections" || Value == "--nocompress-debug-sections") { - CompressDebugSections = false; + CmdArgs.push_back(Value.data()); } else if (Value == "-mrelax-relocations=yes" || Value == "--mrelax-relocations=yes") { UseRelaxRelocations = true; @@ -1883,12 +1909,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, } } } - if (CompressDebugSections) { - if (llvm::zlib::isAvailable()) - CmdArgs.push_back("-compress-debug-sections"); - else - D.Diag(diag::warn_debug_compression_unavailable); - } if (UseRelaxRelocations) CmdArgs.push_back("--mrelax-relocations"); if (MipsTargetFeature != nullptr) { @@ -2824,6 +2844,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-generate-type-units"); } + RenderDebugInfoCompressionArgs(Args, CmdArgs, D); + bool UseSeparateSections = isUseSeparateSections(Triple); if (Args.hasFlag(options::OPT_ffunction_sections, @@ -4927,6 +4949,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); const std::string &TripleStr = Triple.getTriple(); + const auto &D = getToolChain().getDriver(); // Don't warn about "clang -w -c foo.s" Args.ClaimAllArgs(options::OPT_w); @@ -5014,6 +5037,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, } RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DwarfVersion, llvm::DebuggerKind::Default); + RenderDebugInfoCompressionArgs(Args, CmdArgs, D); + // Handle -fPIC et al -- the relocation-model affects the assembler // for some targets. diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index d50f8e21f62f..c9d15ea00d8e 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -650,6 +650,8 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { + const auto &D = getToolChain().getDriver(); + claimNoWarnArgs(Args); ArgStringList CmdArgs; @@ -660,6 +662,23 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, std::tie(RelocationModel, PICLevel, IsPIE) = ParsePICArgs(getToolChain(), Args); + if (const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) { + if (A->getOption().getID() == options::OPT_gz) { + CmdArgs.push_back("-compress-debug-sections"); + } else { + StringRef Value = A->getValue(); + if (Value == "none") { + CmdArgs.push_back("-compress-debug-sections=none"); + } else if (Value == "zlib" || Value == "zlib-gnu") { + CmdArgs.push_back( + Args.MakeArgString("-compress-debug-sections=" + Twine(Value))); + } else { + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Value; + } + } + } + switch (getToolChain().getArch()) { default: break; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 203723953a6f..6254b0013bab 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -745,9 +745,22 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); Opts.CallFEntry = Args.hasArg(OPT_mfentry); Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); - // TODO: map this from -gz in the driver and give it a named value - if (Args.hasArg(OPT_compress_debug_sections)) - Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU); + + if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, + OPT_compress_debug_sections_EQ)) { + if (A->getOption().getID() == OPT_compress_debug_sections) { + // TODO: be more clever about the compression type auto-detection + Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU); + } else { + auto DCT = llvm::StringSwitch(A->getValue()) + .Case("none", llvm::DebugCompressionType::None) + .Case("zlib", llvm::DebugCompressionType::Z) + .Case("zlib-gnu", llvm::DebugCompressionType::GNU) + .Default(llvm::DebugCompressionType::None); + Opts.setCompressDebugSections(DCT); + } + } + Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations); Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); for (auto A : Args.filtered(OPT_mlink_bitcode_file, OPT_mlink_cuda_bitcode)) { diff --git a/test/Driver/compress-noias.c b/test/Driver/compress-noias.c new file mode 100644 index 000000000000..d20cf366b8fc --- /dev/null +++ b/test/Driver/compress-noias.c @@ -0,0 +1,37 @@ +// REQUIRES: zlib +// REQUIRES: x86-registered-target + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -Wa,-compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-_COMPRESS_DEBUG_SECTIONS %s +// CHECK-_COMPRESS_DEBUG_SECTIONS: "-compress-debug-sections" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -Wa,--compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-__COMPRESS_DEBUG_SECTIONS %s +// CHECK-__COMPRESS_DEBUG_SECTIONS: "--compress-debug-sections" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -Wa,--compress-debug-sections -Wa,--nocompress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-POSNEG %s +// CHECK-POSNEG: "--compress-debug-sections" +// CHECK-POSNEG: "--nocompress-debug-sections" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -Wa,-compress-debug-sections -Wa,--compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-MULTIPLE %s +// CHECK-MULTIPLE: "-compress-debug-sections" +// CHECK-MULTIPLE: "--compress-debug-sections" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// CHECK-OPT_GZ: "-compress-debug-sections" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// CHECK-OPT_GZ_EQ_NONE: "-compress-debug-sections=none" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// CHECK-OPT_GZ_EQ_ZLIB: "-compress-debug-sections=zlib" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// CHECK-OPT_GZ_EQ_ZLIB_GNU: "-compress-debug-sections=zlib-gnu" + +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// RUN: %clang -### -target i686-unknown-linux-gnu -fno-integrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// CHECK-OPT_GZ_EQ_INVALID: error: unsupported argument 'invalid' to option 'gz=' + diff --git a/test/Driver/compress.c b/test/Driver/compress.c index 6cdc6b72243e..a00ce91225bd 100644 --- a/test/Driver/compress.c +++ b/test/Driver/compress.c @@ -1,8 +1,36 @@ -// RUN: %clang -### -c -integrated-as -Wa,-compress-debug-sections %s 2>&1 | FileCheck --check-prefix=COMPRESS_DEBUG %s -// RUN: %clang -### -c -integrated-as -Wa,--compress-debug-sections %s 2>&1 | FileCheck --check-prefix=COMPRESS_DEBUG %s // REQUIRES: zlib -// COMPRESS_DEBUG: "-compress-debug-sections" +// RUN: %clang -### -fintegrated-as -Wa,-compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-_COMPRESS_DEBUG_SECTIONS %s +// CHECK-_COMPRESS_DEBUG_SECTIONS: "-compress-debug-sections" + +// RUN: %clang -### -fintegrated-as -Wa,--compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-__COMPRESS_DEBUG_SECTIONS %s +// CHECK-__COMPRESS_DEBUG_SECTIONS: "--compress-debug-sections" + +// RUN: %clang -### -fintegrated-as -Wa,--compress-debug-sections -Wa,--nocompress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-POSNEG %s +// CHECK-POSNEG: "--compress-debug-sections" +// CHECK-POSNEG: "--nocompress-debug-sections" + +// RUN: %clang -### -fintegrated-as -Wa,-compress-debug-sections -Wa,--compress-debug-sections -c %s 2>&1 | FileCheck -check-prefix CHECK-MULTIPLE %s +// CHECK-MULTIPLE: "-compress-debug-sections" +// CHECK-MULTIPLE: "--compress-debug-sections" + +// RUN: %clang -### -fintegrated-as -gz -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// CHECK-OPT_GZ: "-compress-debug-sections" + +// RUN: %clang -### -fintegrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// CHECK-OPT_GZ_EQ_NONE: "-compress-debug-sections=none" + +// RUN: %clang -### -fintegrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// RUN: %clang -### -fintegrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// CHECK-OPT_GZ_EQ_ZLIB: "-compress-debug-sections=zlib" + +// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// CHECK-OPT_GZ_EQ_ZLIB_GNU: "-compress-debug-sections=zlib-gnu" + +// RUN: %clang -### -fintegrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// RUN: %clang -### -fintegrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// CHECK-OPT_GZ_EQ_INVALID: error: unsupported argument 'invalid' to option 'gz=' -// RUN: %clang -### -c -integrated-as -Wa,--compress-debug-sections -Wa,--nocompress-debug-sections %s 2>&1 | FileCheck --check-prefix=NOCOMPRESS_DEBUG %s -// NOCOMPRESS_DEBUG-NOT: "-compress-debug-sections" diff --git a/test/Driver/nozlibcompress.c b/test/Driver/nozlibcompress.c index 9986c85d79ae..035b115abd19 100644 --- a/test/Driver/nozlibcompress.c +++ b/test/Driver/nozlibcompress.c @@ -1,6 +1,7 @@ -// RUN: %clang -c %s -Wa,--compress-debug-sections 2>&1 | FileCheck %s -// RUN: %clang -c %s -Wa,--compress-debug-sections -Wa,--nocompress-debug-sections 2>&1 | FileCheck --allow-empty --check-prefix=NOWARN %s // REQUIRES: nozlib -// CHECK: warning: cannot compress debug sections (zlib not installed) -// NOWARN-NOT: warning: cannot compress debug sections (zlib not installed) +// RUN: %clang -fintegrated-as -gz -c %s 2>&1 | FileCheck %s -check-prefix CHECK-WARN +// RUN: %clang -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -allow-empty -check-prefix CHECK-NOWARN %s + +// CHECK-WARN: warning: cannot compress debug sections (zlib not installed) +// CHECK-NOWARN-NOT: warning: cannot compress debug sections (zlib not installed) diff --git a/test/Misc/cc1as-compress.s b/test/Misc/cc1as-compress.s new file mode 100644 index 000000000000..beba227138d8 --- /dev/null +++ b/test/Misc/cc1as-compress.s @@ -0,0 +1,8 @@ +// REQUIRES: zlib +// REQUIRES: x86-registered-target + +// RUN: %clang -cc1as -triple i686 --compress-debug-sections -filetype asm %s -o /dev/null 2>&1 | FileCheck -allow-empty %s +// RUN: %clang -cc1as -triple i686 -compress-debug-sections -filetype asm %s -o /dev/null 2>&1 | FileCheck -allow-empty %s + +// CHECK-NOT: error: unknown argument: + diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 37c14f4a26e1..2fc2b508ef21 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -202,9 +202,22 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels); // Any DebugInfoKind implies GenDwarfForAssembly. Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ); - // TODO: base this on -gz instead - if (Args.hasArg(OPT_compress_debug_sections)) - Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; + + if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, + OPT_compress_debug_sections_EQ)) { + if (A->getOption().getID() == OPT_compress_debug_sections) { + // TODO: be more clever about the compression type auto-detection + Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; + } else { + Opts.CompressDebugSections = + llvm::StringSwitch(A->getValue()) + .Case("none", llvm::DebugCompressionType::None) + .Case("zlib", llvm::DebugCompressionType::Z) + .Case("zlib-gnu", llvm::DebugCompressionType::GNU) + .Default(llvm::DebugCompressionType::None); + } + } + Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations); Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags); Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); From 289dbf7f13ab2e6c98e32aef35b2dab414b36d83 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 23 Jun 2017 15:37:52 +0000 Subject: [PATCH 047/214] Sort the autocomplete candidates before printing them out. Currently, autocompleted options are displayed in the same order as we wrote them in .td files. This patch sort them out in clang so that they are sorted alphabetically. This should improve usability. Differential Revision: https://reviews.llvm.org/D34557 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306116 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 7 +++++++ test/Driver/autocomplete.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 850f6bc9dde7..c8f389bfb0f7 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1245,6 +1245,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg); } + // Sort the autocomplete candidates so that shells print them out in a + // deterministic order. We could sort in any way, but we chose + // case-insensitive sorting for consistency with the -help option + // which prints out options in the case-insensitive alphabetical order. + std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(), + [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; }); + llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n'; return false; } diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c index c7e339b616f1..117d7e9267d0 100644 --- a/test/Driver/autocomplete.c +++ b/test/Driver/autocomplete.c @@ -11,7 +11,7 @@ // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI // MEABI: default // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL -// MEABIALL: default 4 5 gnu +// MEABIALL: 4 5 default gnu // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD // CLSTD: CL2.0 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL @@ -19,18 +19,18 @@ // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER // FNOSANICOVER: func // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s -check-prefix=FNOSANICOVERALL -// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters +// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc trace-pc-guard // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s -check-prefix=FFPALL -// FFPALL: fast on off +// FFPALL: fast off on // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL -// FLTOALL: thin full +// FLTOALL: full thin // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s -check-prefix=FVECLIBALL -// FVECLIBALL: Accelerate SVML none +// FVECLIBALL: Accelerate none SVML // RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s -check-prefix=FSOVERALL -// FSOVERALL: best all +// FSOVERALL: all best // RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s -check-prefix=FVISIBILITYALL -// FVISIBILITYALL: hidden default +// FVISIBILITYALL: default hidden // RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s -check-prefix=MFLOATABIALL -// MFLOATABIALL: soft softfp hard +// MFLOATABIALL: hard soft softfp // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s -check-prefix=MTHREADMODELALL // MTHREADMODELALL: posix single From e69da60ae245599a8e5bc89e4b0d237d084d944a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 23 Jun 2017 16:52:49 +0000 Subject: [PATCH 048/214] test: fix negative test case Add missing -### to the driver to ensure that we dont try to run the actual command. The host may not support the IAS. Should fix the SCEI buildbots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306123 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Driver/nozlibcompress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Driver/nozlibcompress.c b/test/Driver/nozlibcompress.c index 035b115abd19..41e1794ad9c3 100644 --- a/test/Driver/nozlibcompress.c +++ b/test/Driver/nozlibcompress.c @@ -1,7 +1,7 @@ // REQUIRES: nozlib -// RUN: %clang -fintegrated-as -gz -c %s 2>&1 | FileCheck %s -check-prefix CHECK-WARN -// RUN: %clang -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -allow-empty -check-prefix CHECK-NOWARN %s +// RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck %s -check-prefix CHECK-WARN +// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -allow-empty -check-prefix CHECK-NOWARN %s // CHECK-WARN: warning: cannot compress debug sections (zlib not installed) // CHECK-NOWARN-NOT: warning: cannot compress debug sections (zlib not installed) From 24989b18385b3b168ef7dcc866f3edc239ccae7f Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 23 Jun 2017 16:56:27 +0000 Subject: [PATCH 049/214] docs: Add documentation for the ThinLTO cache pruning policy string. Differential Revision: https://reviews.llvm.org/D34546 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306125 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ThinLTO.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/ThinLTO.rst b/docs/ThinLTO.rst index d417febda502..71a23380efb9 100644 --- a/docs/ThinLTO.rst +++ b/docs/ThinLTO.rst @@ -126,6 +126,38 @@ which currently must be enabled through a linker option. - lld (as of LLVM r296702): ``-Wl,--thinlto-cache-dir=/path/to/cache`` +Cache Pruning +------------- + +To help keep the size of the cache under control, ThinLTO supports cache +pruning. Cache pruning is supported with ld64 and ELF lld, but currently only +ELF lld allows you to control the policy with a policy string. The cache +policy must be specified with a linker option. + +- ELF lld (as of LLVM r298036): + ``-Wl,--thinlto-cache-policy,POLICY`` + +A policy string is a series of key-value pairs separated by ``:`` characters. +Possible key-value pairs are: + +- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent + of the available space on the the disk. Set to 100 to indicate no limit, + 50 to indicate that the cache size will not be left over half the available + disk space. A value over 100 is invalid. A value of 0 disables the percentage + size-based pruning. The default is 75%. + +- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the + expiration time for cache files to ``X`` seconds (or minutes, hours + respectively). When a file hasn't been accessed for ``prune_after`` seconds, + it is removed from the cache. A value of 0 disables the expiration-based + pruning. The default is 1 week. + +- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``: + Sets the pruning interval to ``X`` seconds (or minutes, hours + respectively). This is intended to be used to avoid scanning the directory + too often. It does not impact the decision of which files to prune. A + value of 0 forces the scan to occur. The default is every 20 minutes. + Clang Bootstrap --------------- From 99621ffe51bf9d86beef725bbbadfaf1507ecff1 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 23 Jun 2017 17:05:03 +0000 Subject: [PATCH 050/214] Add a ThinLTO cache policy for controlling the maximum cache size in bytes. This is useful when an upper limit on the cache size needs to be controlled independently of the amount of the amount of free space. One use case is a machine with a large number of cache directories (e.g. a buildbot slave hosting a large number of independent build jobs). By imposing an upper size limit on each cache directory, users can more easily estimate the server's capacity. Differential Revision: https://reviews.llvm.org/D34547 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306126 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ThinLTO.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/ThinLTO.rst b/docs/ThinLTO.rst index 71a23380efb9..31fff51a61e9 100644 --- a/docs/ThinLTO.rst +++ b/docs/ThinLTO.rst @@ -146,6 +146,18 @@ Possible key-value pairs are: disk space. A value over 100 is invalid. A value of 0 disables the percentage size-based pruning. The default is 75%. +- ``cache_size_bytes=X``, ``cache_size_bytes=Xk``, ``cache_size_bytes=Xm``, + ``cache_size_bytes=Xg``: + Sets the maximum size for the cache directory to ``X`` bytes (or KB, MB, + GB respectively). A value over the amount of available space on the disk + will be reduced to the amount of available space. A value of 0 disables + the byte size-based pruning. The default is no byte size-based pruning. + + Note that ThinLTO will apply both size-based pruning policies simultaneously, + and changing one does not affect the other. For example, a policy of + ``cache_size_bytes=1g`` on its own will cause both the 1GB and default 75% + policies to be applied unless the default ``cache_size`` is overridden. + - ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the expiration time for cache files to ``X`` seconds (or minutes, hours respectively). When a file hasn't been accessed for ``prune_after`` seconds, From 0737f6e1507ded6b3773528558224558115bd15f Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Fri, 23 Jun 2017 17:05:50 +0000 Subject: [PATCH 051/214] [GSoC] Add support for CC1 options. Summary: Add value completion support for options which are defined in CC1Options.td, because we only handled options in Options.td. Reviewers: ruiu, v.g.vassilev, teemperor Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34558 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306127 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 16 ++++++++-------- test/Driver/autocomplete.c | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 10c4cff64770..c478cfc7833e 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -158,7 +158,7 @@ def msave_temp_labels : Flag<["-"], "msave-temp-labels">, "Note this may change .s semantics and shouldn't generally be used " "on compiler-generated code.">; def mrelocation_model : Separate<["-"], "mrelocation-model">, - HelpText<"The relocation model to use">; + HelpText<"The relocation model to use">, Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">; def fno_math_builtin : Flag<["-"], "fno-math-builtin">, HelpText<"Disable implicit builtin knowledge of math functions">; } @@ -229,7 +229,7 @@ def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">, def masm_verbose : Flag<["-"], "masm-verbose">, HelpText<"Generate verbose assembly output">; def mcode_model : Separate<["-"], "mcode-model">, - HelpText<"The code model to use">; + HelpText<"The code model to use">, Values<"small,kernel,medium,large">; def mdebug_pass : Separate<["-"], "mdebug-pass">, HelpText<"Enable additional debug output">; def mdisable_fp_elim : Flag<["-"], "mdisable-fp-elim">, @@ -308,7 +308,7 @@ def fsanitize_coverage_no_prune HelpText<"Disable coverage pruning (i.e. instrument all blocks/edges)">; def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">, HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, " - "or none">; + "or none">, Values<"none,clang,llvm">; def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">, HelpText<"Generate instrumented code to collect execution counts into " " (overridden by LLVM_PROFILE_FILE env var)">; @@ -348,9 +348,9 @@ def diagnostic_serialized_file : Separate<["-"], "serialize-diagnostic-file">, HelpText<"File for serializing diagnostics in a binary format">; def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">, - HelpText<"Change diagnostic formatting to match IDE and command line tools">; + HelpText<"Change diagnostic formatting to match IDE and command line tools">, Values<"clang,msvc,msvc-fallback,vi">; def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">, - HelpText<"Print diagnostic category">; + HelpText<"Print diagnostic category">, Values<"none,id,name">; def fno_diagnostics_use_presumed_location : Flag<["-"], "fno-diagnostics-use-presumed-location">, HelpText<"Ignore #line directives when displaying diagnostic locations">; def ftabstop : Separate<["-"], "ftabstop">, MetaVarName<"">, @@ -595,11 +595,11 @@ def fconstant_string_class : Separate<["-"], "fconstant-string-class">, MetaVarName<"">, HelpText<"Specify the class to use for constant Objective-C string objects.">; def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">, - HelpText<"Objective-C++ Automatic Reference Counting standard library kind">; + HelpText<"Objective-C++ Automatic Reference Counting standard library kind">, Values<"libc++,libstdc++,none">; def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">, HelpText<"The target Objective-C runtime supports ARC weak operations">; def fobjc_dispatch_method_EQ : Joined<["-"], "fobjc-dispatch-method=">, - HelpText<"Objective-C dispatch method to use">; + HelpText<"Objective-C dispatch method to use">, Values<"legacy,non-legacy,mixed">; def disable_objc_default_synthesize_properties : Flag<["-"], "disable-objc-default-synthesize-properties">, HelpText<"disable the default synthesis of Objective-C properties">; def fencode_extended_block_signature : Flag<["-"], "fencode-extended-block-signature">, @@ -673,7 +673,7 @@ def fnative_half_arguments_and_returns : Flag<["-"], "fnative-half-arguments-and def fallow_half_arguments_and_returns : Flag<["-"], "fallow-half-arguments-and-returns">, HelpText<"Allow function arguments and returns of type half">; def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">, - HelpText<"Set default MS calling convention">; + HelpText<"Set default MS calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall">; def finclude_default_header : Flag<["-"], "finclude-default-header">, HelpText<"Include the default header file for OpenCL">; def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">, diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c index 117d7e9267d0..f0bdcce5707c 100644 --- a/test/Driver/autocomplete.c +++ b/test/Driver/autocomplete.c @@ -34,3 +34,5 @@ // MFLOATABIALL: hard soft softfp // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s -check-prefix=MTHREADMODELALL // MTHREADMODELALL: posix single +// RUN: %clang --autocomplete=-mrelocation-model, | FileCheck %s -check-prefix=MRELOCMODELALL +// MRELOCMODELALL: dynamic-no-pic pic ropi ropi-rwpi rwpi static From 20e77878ed5d88eb9bcf88ee34e6fab4459cb92a Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 23 Jun 2017 18:29:13 +0000 Subject: [PATCH 052/214] [MS] Don't statically initialize dllimport member function pointers We were already applying the same rules to dllimport function pointers. David Majnemer added that logic back in r211677 to fix PR20130. We failed to extend that logic to non-virtual member function pointers, which are basically function pointers in a struct with some extra offsets. Fixes PR33570. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306137 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 16 ++++++ test/CodeGenCXX/dllimport-memptr-global.cpp | 58 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/CodeGenCXX/dllimport-memptr-global.cpp diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 768947d00ac4..60f8143c137d 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1665,6 +1665,19 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc, return true; } +/// Member pointers are constant expressions unless they point to a +/// non-virtual dllimport member function. +static bool CheckMemberPointerConstantExpression(EvalInfo &Info, + SourceLocation Loc, + QualType Type, + const APValue &Value) { + const ValueDecl *Member = Value.getMemberPointerDecl(); + const auto *FD = dyn_cast_or_null(Member); + if (!FD) + return true; + return FD->isVirtual() || !FD->hasAttr(); +} + /// Check that this core constant expression is of literal type, and if not, /// produce an appropriate diagnostic. static bool CheckLiteralType(EvalInfo &Info, const Expr *E, @@ -1757,6 +1770,9 @@ static bool CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc, return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal); } + if (Value.isMemberPointer()) + return CheckMemberPointerConstantExpression(Info, DiagLoc, Type, Value); + // Everything else is fine. return true; } diff --git a/test/CodeGenCXX/dllimport-memptr-global.cpp b/test/CodeGenCXX/dllimport-memptr-global.cpp new file mode 100644 index 000000000000..e64537b8b9f9 --- /dev/null +++ b/test/CodeGenCXX/dllimport-memptr-global.cpp @@ -0,0 +1,58 @@ +// Also check that -Wglobal-constructors does the right thing. Strictly +// speaking, this is a Sema test, but this avoids test case duplication. +// RUN: %clang_cc1 -Wglobal-constructors %s -verify -triple i686-windows-msvc -fms-extensions -std=c++11 +// +// RUN: %clang_cc1 %s -emit-llvm -o - -triple i686-windows-msvc -fms-extensions -std=c++11 | FileCheck %s + +struct __declspec(dllimport) Single { + void nonvirt(); + virtual void virt(); +}; + +struct A { int a; }; +struct B { int b; }; +struct __declspec(dllimport) Multi : A, B { + void nonvirt(); + virtual void virt(); +}; + +struct __declspec(dllimport) Virtual : virtual A { + void nonvirt(); + virtual void virt(); +}; + +struct General; +static_assert(sizeof(void (General::*)()) == 16, "force general memptr model"); +struct __declspec(dllimport) General { + void nonvirt(); + virtual void virt(); +}; + +auto mp_single_nv = &Single::nonvirt; // expected-warning {{global constructor}} +auto mp_multi_nv = &Multi::nonvirt; // expected-warning {{global constructor}} +auto mp_virtual_nv = &Virtual::nonvirt; // expected-warning {{global constructor}} +auto mp_general_nv = &General::nonvirt; // expected-warning {{global constructor}} + +auto mp_single_v = &Single::virt; +auto mp_multi_v = &Multi::virt; +auto mp_virtual_v = &Virtual::virt; +auto mp_general_v = &General::virt; + +// All of the non-virtual globals need dynamic initializers. + +// CHECK: @"\01?mp_single_nv@@3P8Single@@AEXXZQ1@" = global i8* null, align 4 +// CHECK: @"\01?mp_multi_nv@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } zeroinitializer, align 4 +// CHECK: @"\01?mp_virtual_nv@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } zeroinitializer, align 4 +// CHECK: @"\01?mp_general_nv@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, i32 } zeroinitializer, align 4 + +// CHECK: @"\01?mp_single_v@@3P8Single@@AEXXZQ1@" = global i8* bitcast (void (%struct.Single*, ...)* @"\01??_9Single@@$BA@AE" to i8*), align 4 +// CHECK: @"\01?mp_multi_v@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } { i8* bitcast (void (%struct.Multi*, ...)* @"\01??_9Multi@@$BA@AE" to i8*), i32 0 }, align 4 +// CHECK: @"\01?mp_virtual_v@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } { i8* bitcast (void (%struct.Virtual*, ...)* @"\01??_9Virtual@@$BA@AE" to i8*), i32 0, i32 0 }, align 4 +// CHECK: @"\01?mp_general_v@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, i32 } { i8* bitcast (void (%struct.General*, ...)* @"\01??_9General@@$BA@AE" to i8*), i32 0, i32 0, i32 0 }, align 4 + +// CHECK: define internal void @_GLOBAL__sub_I{{.*}}() {{.*}} { +// CHECK: call void @"\01??__Emp_single_nv@@YAXXZ"() +// CHECK: call void @"\01??__Emp_multi_nv@@YAXXZ"() +// CHECK: call void @"\01??__Emp_virtual_nv@@YAXXZ"() +// CHECK: call void @"\01??__Emp_general_nv@@YAXXZ"() +// CHECK: } From 59a70fe4b62cafbeb1fa494d3f920df645c30283 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 23 Jun 2017 20:22:19 +0000 Subject: [PATCH 053/214] Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Throwing in the destructor is not good (C++11 change try to not allow see below). But in reality, those codes are exist. C++11 [class.dtor]p3: A declaration of a destructor that does not have an exception-specification is implicitly considered to have the same exception specification as an implicit declaration. With this change, the application worked before may now run into runtime termination. My goal here is to emit a warning to provide only possible info to where the code may need to be changed. First there is no way, in compile time to identify the “throw” really throw out of the function. Things like the call which throw out… To keep this simple, when “throw” is seen, checking its enclosing function(only destructor and dealloc functions) with noexcept(true) specifier emit warning. Here is implementation detail: A new member function CheckCXXThrowInNonThrowingFunc is added for class Sema in Sema.h. It is used in the call to both BuildCXXThrow and TransformCXXThrowExpr. The function basic check if the enclosing function with non-throwing noexcept specifer, if so emit warning for it. The example of warning message like: k1.cpp:18:3: warning: ''~dependent_warn'' has a (possible implicit) non-throwing noexcept specifier. Throwing exception may cause termination. [-Wthrow-in-dtor] throw 1; ^ k1.cpp:43:30: note: in instantiation of member function 'dependent_warn::~dependent_warn' requested here dependent_warn f; // cause warning Differential Revision: https://reviews.llvm.org/D33333 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306149 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 9 ++ lib/Sema/AnalysisBasedWarnings.cpp | 150 +++++++++++++++++++++ test/CXX/except/except.spec/p11.cpp | 9 +- 3 files changed, 163 insertions(+), 5 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 62faadcc5fe9..cba9b251215a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -6351,6 +6351,15 @@ def err_exceptions_disabled : Error< "cannot use '%0' with exceptions disabled">; def err_objc_exceptions_disabled : Error< "cannot use '%0' with Objective-C exceptions disabled">; +def warn_throw_in_noexcept_func + : Warning<"%0 has a non-throwing exception specification but can still " + "throw, resulting in unexpected program termination">, + InGroup; +def note_throw_in_dtor + : Note<"destructor or deallocator has a (possibly implicit) non-throwing " + "excepton specification">; +def note_throw_in_function + : Note<"non-throwing function declare here">; def err_seh_try_outside_functions : Error< "cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls">; def err_mixing_cxx_try_seh_try : Error< diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index db688b12cbcf..934e13e72d05 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -278,6 +278,150 @@ static void checkRecursiveFunction(Sema &S, const FunctionDecl *FD, S.Diag(Body->getLocStart(), diag::warn_infinite_recursive_function); } +//===----------------------------------------------------------------------===// +// Check for throw in a non-throwing function. +//===----------------------------------------------------------------------===// +enum ThrowState { + FoundNoPathForThrow, + FoundPathForThrow, + FoundPathWithNoThrowOutFunction, +}; + +static bool isThrowCaught(const CXXThrowExpr *Throw, + const CXXCatchStmt *Catch) { + const Type *ThrowType = nullptr; + if (Throw->getSubExpr()) + ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull(); + if (!ThrowType) + return false; + const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull(); + if (!CaughtType) + return true; + if (ThrowType->isReferenceType()) + ThrowType = ThrowType->castAs() + ->getPointeeType() + ->getUnqualifiedDesugaredType(); + if (CaughtType->isReferenceType()) + CaughtType = CaughtType->castAs() + ->getPointeeType() + ->getUnqualifiedDesugaredType(); + if (CaughtType == ThrowType) + return true; + const CXXRecordDecl *CaughtAsRecordType = + CaughtType->getPointeeCXXRecordDecl(); + const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl(); + if (CaughtAsRecordType && ThrowTypeAsRecordType) + return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType); + return false; +} + +static bool isThrowCaughtByHandlers(const CXXThrowExpr *CE, + const CXXTryStmt *TryStmt) { + for (unsigned H = 0, E = TryStmt->getNumHandlers(); H < E; ++H) { + if (isThrowCaught(CE, TryStmt->getHandler(H))) + return true; + } + return false; +} + +static bool doesThrowEscapePath(CFGBlock Block, SourceLocation &OpLoc) { + for (const auto &B : Block) { + if (B.getKind() != CFGElement::Statement) + continue; + const auto *CE = dyn_cast(B.getAs()->getStmt()); + if (!CE) + continue; + + OpLoc = CE->getThrowLoc(); + for (const auto &I : Block.succs()) { + if (!I.isReachable()) + continue; + if (const auto *Terminator = + dyn_cast_or_null(I->getTerminator())) + if (isThrowCaughtByHandlers(CE, Terminator)) + return false; + } + return true; + } + return false; +} + +static bool hasThrowOutNonThrowingFunc(SourceLocation &OpLoc, CFG *BodyCFG) { + + unsigned ExitID = BodyCFG->getExit().getBlockID(); + + SmallVector States(BodyCFG->getNumBlockIDs(), + FoundNoPathForThrow); + States[BodyCFG->getEntry().getBlockID()] = FoundPathWithNoThrowOutFunction; + + SmallVector Stack; + Stack.push_back(&BodyCFG->getEntry()); + while (!Stack.empty()) { + CFGBlock *CurBlock = Stack.back(); + Stack.pop_back(); + + unsigned ID = CurBlock->getBlockID(); + ThrowState CurState = States[ID]; + if (CurState == FoundPathWithNoThrowOutFunction) { + if (ExitID == ID) + continue; + + if (doesThrowEscapePath(*CurBlock, OpLoc)) + CurState = FoundPathForThrow; + } + + // Loop over successor blocks and add them to the Stack if their state + // changes. + for (const auto &I : CurBlock->succs()) + if (I.isReachable()) { + unsigned NextID = I->getBlockID(); + if (NextID == ExitID && CurState == FoundPathForThrow) { + States[NextID] = CurState; + } else if (States[NextID] < CurState) { + States[NextID] = CurState; + Stack.push_back(I); + } + } + } + // Return true if the exit node is reachable, and only reachable through + // a throw expression. + return States[ExitID] == FoundPathForThrow; +} + +static void EmitDiagForCXXThrowInNonThrowingFunc(Sema &S, SourceLocation OpLoc, + const FunctionDecl *FD) { + if (!S.getSourceManager().isInSystemHeader(OpLoc)) { + S.Diag(OpLoc, diag::warn_throw_in_noexcept_func) << FD; + if (S.getLangOpts().CPlusPlus11 && + (isa(FD) || + FD->getDeclName().getCXXOverloadedOperator() == OO_Delete || + FD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete)) + S.Diag(FD->getLocation(), diag::note_throw_in_dtor); + else + S.Diag(FD->getLocation(), diag::note_throw_in_function); + } +} + +static void checkThrowInNonThrowingFunc(Sema &S, const FunctionDecl *FD, + AnalysisDeclContext &AC) { + CFG *BodyCFG = AC.getCFG(); + if (!BodyCFG) + return; + if (BodyCFG->getExit().pred_empty()) + return; + SourceLocation OpLoc; + if (hasThrowOutNonThrowingFunc(OpLoc, BodyCFG)) + EmitDiagForCXXThrowInNonThrowingFunc(S, OpLoc, FD); +} + +static bool isNoexcept(const FunctionDecl *FD) { + const auto *FPT = FD->getType()->castAs(); + if (FPT->getExceptionSpecType() != EST_None && + FPT->isNothrow(FD->getASTContext())) + return true; + return false; +} + //===----------------------------------------------------------------------===// // Check for missing return value. //===----------------------------------------------------------------------===// @@ -2127,6 +2271,12 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, } } + // Check for throw out of non-throwing function. + if (!Diags.isIgnored(diag::warn_throw_in_noexcept_func, D->getLocStart())) + if (const FunctionDecl *FD = dyn_cast(D)) + if (S.getLangOpts().CPlusPlus && isNoexcept(FD)) + checkThrowInNonThrowingFunc(S, FD, AC); + // If none of the previous checks caused a CFG build, trigger one here // for -Wtautological-overlap-compare if (!Diags.isIgnored(diag::warn_tautological_overlap_comparison, diff --git a/test/CXX/except/except.spec/p11.cpp b/test/CXX/except/except.spec/p11.cpp index 1d0a647fb4f4..196f84c557ea 100644 --- a/test/CXX/except/except.spec/p11.cpp +++ b/test/CXX/except/except.spec/p11.cpp @@ -1,12 +1,11 @@ // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s -// expected-no-diagnostics // This is the "let the user shoot themselves in the foot" clause. -void f() noexcept { - throw 0; // no-error +void f() noexcept { // expected-note {{non-throwing function declare here}} + throw 0; // expected-warning {{has a non-throwing exception specification but}} } -void g() throw() { - throw 0; // no-error +void g() throw() { // expected-note {{non-throwing function declare here}} + throw 0; // expected-warning {{has a non-throwing exception specification but}} } void h() throw(int) { throw 0.0; // no-error From 26143cdb50e70efa626feefc8a07ad27536171a3 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 23 Jun 2017 20:30:33 +0000 Subject: [PATCH 054/214] Add test for 306149, warn on throw from noexcept git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306156 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/SemaCXX/warn-throw-out-noexcept-func.cpp | 265 ++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 test/SemaCXX/warn-throw-out-noexcept-func.cpp diff --git a/test/SemaCXX/warn-throw-out-noexcept-func.cpp b/test/SemaCXX/warn-throw-out-noexcept-func.cpp new file mode 100644 index 000000000000..dfd1ff9065ab --- /dev/null +++ b/test/SemaCXX/warn-throw-out-noexcept-func.cpp @@ -0,0 +1,265 @@ +// RUN: %clang_cc1 %s -fdelayed-template-parsing -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++11 +struct A_ShouldDiag { + ~A_ShouldDiag(); // implicitly noexcept(true) +}; +A_ShouldDiag::~A_ShouldDiag() { // expected-note {{destructor or deallocator has a (possibly implicit) non-throwing excepton specification}} + throw 1; // expected-warning {{has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} +} +struct B_ShouldDiag { + int i; + ~B_ShouldDiag() noexcept(true) {} //no disg, no throw stmt +}; +struct R_ShouldDiag : A_ShouldDiag { + B_ShouldDiag b; + ~R_ShouldDiag() { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; + +struct M_ShouldNotDiag { + B_ShouldDiag b; + ~M_ShouldNotDiag() noexcept(false); +}; + +M_ShouldNotDiag::~M_ShouldNotDiag() noexcept(false) { + throw 1; +} + +struct N_ShouldDiag { + B_ShouldDiag b; + ~N_ShouldDiag(); //implicitly noexcept(true) +}; + +N_ShouldDiag::~N_ShouldDiag() { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} +} +struct X_ShouldDiag { + B_ShouldDiag b; + ~X_ShouldDiag() noexcept { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +struct Y_ShouldDiag : A_ShouldDiag { + ~Y_ShouldDiag() noexcept(true) { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +struct C_ShouldNotDiag { + int i; + ~C_ShouldNotDiag() noexcept(false) {} +}; +struct D_ShouldNotDiag { + C_ShouldNotDiag c; + ~D_ShouldNotDiag() { //implicitly noexcept(false) + throw 1; + } +}; +struct E_ShouldNotDiag { + C_ShouldNotDiag c; + ~E_ShouldNotDiag(); //implicitly noexcept(false) +}; +E_ShouldNotDiag::~E_ShouldNotDiag() //implicitly noexcept(false) +{ + throw 1; +} + +template +class A1_ShouldDiag { + T b; + +public: + ~A1_ShouldDiag() { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +template +struct B1_ShouldDiag { + T i; + ~B1_ShouldDiag() noexcept(true) {} +}; +template +struct R1_ShouldDiag : A1_ShouldDiag //expected-note {{in instantiation of member function}} +{ + B1_ShouldDiag b; + ~R1_ShouldDiag() { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +template +struct S1_ShouldDiag : A1_ShouldDiag { + B1_ShouldDiag b; + ~S1_ShouldDiag() noexcept { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +void operator delete(void *ptr) noexcept { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} +} +struct except_fun { + static const bool i = false; +}; +struct noexcept_fun { + static const bool i = true; +}; +template +struct dependent_warn { + ~dependent_warn() noexcept(T::i) { + throw 1; + } +}; +template +struct dependent_warn_noexcept { + ~dependent_warn_noexcept() noexcept(T::i) { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +template +struct dependent_warn_both { + ~dependent_warn_both() noexcept(T::i) { // expected-note {{destructor or deallocator has a}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} + } +}; +void foo() noexcept { //expected-note {{non-throwing function declare here}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} +} +struct Throws { + ~Throws() noexcept(false); +}; + +struct ShouldDiagnose { + Throws T; + ~ShouldDiagnose() noexcept { //expected-note {{destructor or deallocator has a}} + throw; // expected-warning {{has a non-throwing exception specification but}} + } +}; +struct ShouldNotDiagnose { + Throws T; + ~ShouldNotDiagnose() { + throw; + } +}; + +void bar_ShouldNotDiag() noexcept { + try { + throw 1; + } catch (...) { + } +} +void f_ShouldNotDiag() noexcept { + try { + throw 12; + } catch (int) { + } +} +void g_ShouldNotDiag() noexcept { + try { + throw 12; + } catch (...) { + } +} + +void h_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw 12; // expected-warning {{has a non-throwing exception specification but}} + } catch (const char *) { + } +} + +void i_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw 12; + } catch (int) { + throw; // expected-warning {{has a non-throwing exception specification but}} + } +} +void j_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw 12; + } catch (int) { + throw "haha"; // expected-warning {{has a non-throwing exception specification but}} + } +} + +void k_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw 12; + } catch (...) { + throw; // expected-warning {{has a non-throwing exception specification but}} + } +} + +void loo_ShouldDiag(int i) noexcept { //expected-note {{non-throwing function declare here}} + if (i) + try { + throw 12; + } catch (int) { + throw "haha"; //expected-warning {{has a non-throwing exception specification but}} + } + i = 10; +} + +void loo1_ShouldNotDiag() noexcept { + if (0) + throw 12; +} + +void loo2_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + if (1) + throw 12; // expected-warning {{has a non-throwing exception specification but}} +} +struct S {}; + +void l_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw S{}; //expected-warning {{has a non-throwing exception specification but}} + } catch (S *s) { + } +} + +void m_ShouldNotDiag() noexcept { + try { + const S &s = S{}; + throw s; + } catch (S s) { + } + +} +void n_ShouldNotDiag() noexcept { + try { + S s = S{}; + throw s; + } catch (const S &s) { + } +} +void o_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}} + try { + throw; //expected-warning {{has a non-throwing exception specification but}} + } catch (...) { + } +} + +#define NOEXCEPT noexcept +void with_macro() NOEXCEPT { //expected-note {{non-throwing function declare here}} + throw 1; // expected-warning {{has a non-throwing exception specification but}} +} + +void with_try_block() try { + throw 2; +} catch (...) { +} + +void with_try_block1() noexcept try { //expected-note {{non-throwing function declare here}} + throw 2; // expected-warning {{has a non-throwing exception specification but}} +} catch (char *) { +} + +int main() { + R1_ShouldDiag o; //expected-note {{in instantiation of member function}} + S1_ShouldDiag b; //expected-note {{in instantiation of member function}} + dependent_warn f; + dependent_warn_noexcept f1; //expected-note {{in instantiation of member function}} + dependent_warn_both f2; + dependent_warn_both f3; //expected-note {{in instantiation of member function}} + ShouldDiagnose obj; + ShouldNotDiagnose obj1; +} From 310e9c901a2e192479207bbc7d701ef8d1f4aea6 Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Fri, 23 Jun 2017 21:12:56 +0000 Subject: [PATCH 055/214] [MSP430] Fix data layout string. Summary: Change data layout string so it would be compatible with MSP430 EABI. Depends on D34561 Reviewers: asl, awygle Reviewed By: asl Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34562 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306161 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 2 +- test/CodeGen/target-data.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index e23a93e8ced7..aee413e95730 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -7503,7 +7503,7 @@ class MSP430TargetInfo : public TargetInfo { IntPtrType = SignedInt; PtrDiffType = SignedInt; SigAtomicType = SignedLong; - resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16"); + resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"); } void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { diff --git a/test/CodeGen/target-data.c b/test/CodeGen/target-data.c index 1e8ce6a2fd12..68ee8f02d2ee 100644 --- a/test/CodeGen/target-data.c +++ b/test/CodeGen/target-data.c @@ -175,7 +175,7 @@ // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MSP430 -// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16" +// MSP430: target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16" // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=TCE From 9766b307603b0617281b4ccc579112efb6bf56b9 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 23 Jun 2017 21:32:38 +0000 Subject: [PATCH 056/214] [ubsan] Improve diagnostics for return value checks (clang) This patch makes ubsan's nonnull return value diagnostics more precise, which makes the diagnostics more useful when there are multiple return statements in a function. Example: 1 |__attribute__((returns_nonnull)) char *foo() { 2 | if (...) { 3 | return expr_which_might_evaluate_to_null(); 4 | } else { 5 | return another_expr_which_might_evaluate_to_null(); 6 | } 7 |} // <- The current diagnostic always points here! runtime error: Null returned from Line 7, Column 2! With this patch, the diagnostic would point to either Line 3, Column 5 or Line 5, Column 5. This is done by emitting source location metadata for each return statement in a sanitized function. The runtime is passed a pointer to the appropriate metadata so that it can prepare and deduplicate reports. Compiler-rt patch (with more tests): https://reviews.llvm.org/D34298 Differential Revision: https://reviews.llvm.org/D34299 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306163 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 44 ++++++++++--------- lib/CodeGen/CGStmt.cpp | 12 +++++ lib/CodeGen/CodeGenFunction.cpp | 7 +++ lib/CodeGen/CodeGenFunction.h | 17 +++++-- .../ubsan-nonnull-and-nullability.m | 34 +++++++++++++- test/CodeGenObjC/ubsan-nullability.m | 32 ++++++++------ 6 files changed, 107 insertions(+), 39 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 0e5ccc0d9fcc..38d520a2beb0 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -2906,7 +2906,7 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Instruction *Ret; if (RV) { - EmitReturnValueCheck(RV, EndLoc); + EmitReturnValueCheck(RV); Ret = Builder.CreateRet(RV); } else { Ret = Builder.CreateRetVoid(); @@ -2916,8 +2916,7 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, Ret->setDebugLoc(std::move(RetDbgLoc)); } -void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV, - SourceLocation EndLoc) { +void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) { // A current decl may not be available when emitting vtable thunks. if (!CurCodeDecl) return; @@ -2950,27 +2949,30 @@ void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV, SanitizerScope SanScope(this); - llvm::BasicBlock *Check = nullptr; - llvm::BasicBlock *NoCheck = nullptr; - if (requiresReturnValueNullabilityCheck()) { - // Before doing the nullability check, make sure that the preconditions for - // the check are met. - Check = createBasicBlock("nullcheck"); - NoCheck = createBasicBlock("no.nullcheck"); - Builder.CreateCondBr(RetValNullabilityPrecondition, Check, NoCheck); - EmitBlock(Check); - } + // Make sure the "return" source location is valid. If we're checking a + // nullability annotation, make sure the preconditions for the check are met. + llvm::BasicBlock *Check = createBasicBlock("nullcheck"); + llvm::BasicBlock *NoCheck = createBasicBlock("no.nullcheck"); + llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation, "return.sloc.load"); + llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr); + if (requiresReturnValueNullabilityCheck()) + CanNullCheck = + Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition); + Builder.CreateCondBr(CanNullCheck, Check, NoCheck); + EmitBlock(Check); - // Now do the null check. If the returns_nonnull attribute is present, this - // is done unconditionally. + // Now do the null check. llvm::Value *Cond = Builder.CreateIsNotNull(RV); - llvm::Constant *StaticData[] = { - EmitCheckSourceLocation(EndLoc), EmitCheckSourceLocation(AttrLoc), - }; - EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None); + llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)}; + llvm::Value *DynamicData[] = {SLocPtr}; + EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData); - if (requiresReturnValueNullabilityCheck()) - EmitBlock(NoCheck); + EmitBlock(NoCheck); + +#ifndef NDEBUG + // The return location should not be used after the check has been emitted. + ReturnLocation = Address::invalid(); +#endif } static bool isInAllocaArgument(CGCXXABI &ABI, QualType type) { diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 683f366ebe45..a13c38646164 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -1024,6 +1024,18 @@ void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) { /// if the function returns void, or may be missing one if the function returns /// non-void. Fun stuff :). void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { + if (requiresReturnValueCheck()) { + llvm::Constant *SLoc = EmitCheckSourceLocation(S.getLocStart()); + auto *SLocPtr = + new llvm::GlobalVariable(CGM.getModule(), SLoc->getType(), false, + llvm::GlobalVariable::PrivateLinkage, SLoc); + SLocPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); + CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr); + assert(ReturnLocation.isValid() && "No valid return location"); + Builder.CreateStore(Builder.CreateBitCast(SLocPtr, Int8PtrTy), + ReturnLocation); + } + // Returning from an outlined SEH helper is UB, and we already warn on it. if (IsOutlinedSEHHelper) { Builder.CreateUnreachable(); diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 1a7797b37e10..93a4a3866193 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -860,6 +860,13 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, Builder.SetInsertPoint(EntryBB); + // If we're checking the return value, allocate space for a pointer to a + // precise source location of the checked return statement. + if (requiresReturnValueCheck()) { + ReturnLocation = CreateDefaultAlignTempAlloca(Int8PtrTy, "return.sloc.ptr"); + InitTempAlloca(ReturnLocation, llvm::ConstantPointerNull::get(Int8PtrTy)); + } + // Emit subprogram debug descriptor. if (CGDebugInfo *DI = getDebugInfo()) { // Reconstruct the type from the argument list so that implicit parameters, diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 11dce073c994..6785111bd052 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -116,9 +116,9 @@ enum TypeEvaluationKind { SANITIZER_CHECK(MulOverflow, mul_overflow, 0) \ SANITIZER_CHECK(NegateOverflow, negate_overflow, 0) \ SANITIZER_CHECK(NullabilityArg, nullability_arg, 0) \ - SANITIZER_CHECK(NullabilityReturn, nullability_return, 0) \ + SANITIZER_CHECK(NullabilityReturn, nullability_return, 1) \ SANITIZER_CHECK(NonnullArg, nonnull_arg, 0) \ - SANITIZER_CHECK(NonnullReturn, nonnull_return, 0) \ + SANITIZER_CHECK(NonnullReturn, nonnull_return, 1) \ SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0) \ SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0) \ SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \ @@ -1407,6 +1407,17 @@ class CodeGenFunction : public CodeGenTypeCache { return RetValNullabilityPrecondition; } + /// Used to store precise source locations for return statements by the + /// runtime return value checks. + Address ReturnLocation = Address::invalid(); + + /// Check if the return value of this function requires sanitization. + bool requiresReturnValueCheck() const { + return requiresReturnValueNullabilityCheck() || + (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute) && + CurCodeDecl && CurCodeDecl->getAttr()); + } + llvm::BasicBlock *TerminateLandingPad; llvm::BasicBlock *TerminateHandler; llvm::BasicBlock *TrapBB; @@ -1778,7 +1789,7 @@ class CodeGenFunction : public CodeGenTypeCache { SourceLocation EndLoc); /// Emit a test that checks if the return value \p RV is nonnull. - void EmitReturnValueCheck(llvm::Value *RV, SourceLocation EndLoc); + void EmitReturnValueCheck(llvm::Value *RV); /// EmitStartEHSpec - Emit the start of the exception spec. void EmitStartEHSpec(const Decl *D); diff --git a/test/CodeGenObjC/ubsan-nonnull-and-nullability.m b/test/CodeGenObjC/ubsan-nonnull-and-nullability.m index b927f55cd402..db6588dac310 100644 --- a/test/CodeGenObjC/ubsan-nonnull-and-nullability.m +++ b/test/CodeGenObjC/ubsan-nonnull-and-nullability.m @@ -7,16 +7,26 @@ // CHECK-LABEL: define nonnull i32* @f1 __attribute__((returns_nonnull)) int *_Nonnull f1(int *_Nonnull p) { // CHECK: entry: + // CHECK-NEXT: [[SLOC_PTR:%.*]] = alloca i8* // CHECK-NEXT: [[ADDR:%.*]] = alloca i32* + // CHECK-NEXT: store i8* null, i8** [[SLOC_PTR]] // CHECK-NEXT: store i32* [[P:%.*]], i32** [[ADDR]] + // CHECK-NEXT: store {{.*}} [[SLOC_PTR]] // CHECK-NEXT: [[ARG:%.*]] = load i32*, i32** [[ADDR]] + // CHECK-NEXT: [[SLOC:%.*]] = load {{.*}} [[SLOC_PTR]] + // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC]], null + // CHECK-NEXT: br i1 [[SLOC_NONNULL]], label %nullcheck + // + // CHECK: nullcheck: // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* [[ARG]], null, !nosanitize // CHECK-NEXT: br i1 [[ICMP]], label %[[CONT:.+]], label %[[HANDLE:[^,]+]] // CHECK: [[HANDLE]]: - // CHECK-NEXT: call void @__ubsan_handle_nonnull_return_abort + // CHECK: call void @__ubsan_handle_nonnull_return // CHECK-NEXT: unreachable, !nosanitize // CHECK: [[CONT]]: - // CHECK-NEXT: ret i32* + // CHECK-NEXT: br label %no.nullcheck + // CHECK: no.nullcheck: + // CHECK-NEXT: ret i32* [[ARG]] return p; } @@ -29,3 +39,23 @@ void call_f2() { // CHECK-NOT: call void @__ubsan_handle_nonnull_arg_abort f2((void *)0); } + +// If the return value isn't meant to be checked, make sure we don't check it. +// CHECK-LABEL: define i32* @f3 +int *f3(int *p) { + // CHECK-NOT: return.sloc + // CHECK-NOT: call{{.*}}ubsan + return p; +} + +// Check for a valid "return" source location, even when there is no return +// statement, to avoid accidentally calling the runtime. + +// CHECK-LABEL: define nonnull i32* @f4 +__attribute__((returns_nonnull)) int *f4() { + // CHECK: store i8* null, i8** [[SLOC_PTR:%.*]] + // CHECK: [[SLOC:%.*]] = load {{.*}} [[SLOC_PTR]] + // CHECK: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC]], null + // CHECK: br i1 [[SLOC_NONNULL]], label %nullcheck + // CHECK: nullcheck: +} diff --git a/test/CodeGenObjC/ubsan-nullability.m b/test/CodeGenObjC/ubsan-nullability.m index 7f53ea6292ee..eeb24b03c868 100644 --- a/test/CodeGenObjC/ubsan-nullability.m +++ b/test/CodeGenObjC/ubsan-nullability.m @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s // RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s -// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 109, i32 1 {{.*}} i32 100, i32 6 +// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 100, i32 6 // CHECK: [[NONNULL_ARG_LOC:@.*]] = private unnamed_addr global {{.*}} i32 204, i32 15 {{.*}} i32 190, i32 23 // CHECK: [[NONNULL_ASSIGN1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 305, i32 9 // CHECK: [[NONNULL_ASSIGN2_LOC:@.*]] = private unnamed_addr global {{.*}} i32 405, i32 10 @@ -10,7 +10,7 @@ // CHECK: [[NONNULL_INIT1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 604, i32 25 // CHECK: [[NONNULL_INIT2_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 26 // CHECK: [[NONNULL_INIT2_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 29 -// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 817, i32 1 {{.*}} i32 800, i32 6 +// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 800, i32 6 #define NULL ((void *)0) #define INULL ((int *)NULL) @@ -19,14 +19,11 @@ // CHECK-LABEL: define i32* @{{.*}}nonnull_retval1 #line 100 int *_Nonnull nonnull_retval1(int *p) { - // CHECK: br i1 true, label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize - // CHECK: [[NULL]]: // CHECK: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize - // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize + // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize // CHECK: call void @__ubsan_handle_nullability_return{{.*}}[[NONNULL_RV_LOC1]] return p; - // CHECK: [[NONULL]]: - // CHECK-NEXT: ret i32* + // CHECK: ret i32* } #line 190 @@ -108,10 +105,13 @@ void nonnull_init2(int *p) { // CHECK-NEXT: [[DO_RV_CHECK_1:%.*]] = and i1 true, [[ARG1CMP]], !nosanitize // CHECK: [[ARG2CMP:%.*]] = icmp ne i32* %arg2, null, !nosanitize // CHECK-NEXT: [[DO_RV_CHECK_2:%.*]] = and i1 [[DO_RV_CHECK_1]], [[ARG2CMP]] - // CHECK: br i1 [[DO_RV_CHECK_2]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize + // CHECK: [[SLOC_PTR:%.*]] = load i8*, i8** %return.sloc.ptr + // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC_PTR]], null + // CHECK-NEXT: [[DO_RV_CHECK_3:%.*]] = and i1 [[SLOC_NONNULL]], [[DO_RV_CHECK_2]] + // CHECK: br i1 [[DO_RV_CHECK_3]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize // CHECK: [[NULL]]: // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize - // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize + // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize // CHECK: call void @__ubsan_handle_nullability_return{{.*}}[[NONNULL_RV_LOC2]] return arg1; // CHECK: [[NONULL]]: @@ -129,10 +129,13 @@ @implementation A +(int *_Nonnull) objc_clsmethod: (int *_Nonnull) arg1 { // CHECK: [[ARG1CMP:%.*]] = icmp ne i32* %arg1, null, !nosanitize // CHECK-NEXT: [[DO_RV_CHECK:%.*]] = and i1 true, [[ARG1CMP]] - // CHECK: br i1 [[DO_RV_CHECK]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize + // CHECK: [[SLOC_PTR:%.*]] = load i8*, i8** %return.sloc.ptr + // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC_PTR]], null + // CHECK-NEXT: [[DO_RV_CHECK_2:%.*]] = and i1 [[SLOC_NONNULL]], [[DO_RV_CHECK]] + // CHECK: br i1 [[DO_RV_CHECK_2]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize // CHECK: [[NULL]]: // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize - // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize + // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize // CHECK: call void @__ubsan_handle_nullability_return{{.*}} return arg1; // CHECK: [[NONULL]]: @@ -143,10 +146,13 @@ +(int *_Nonnull) objc_clsmethod: (int *_Nonnull) arg1 { -(int *_Nonnull) objc_method: (int *_Nonnull) arg1 { // CHECK: [[ARG1CMP:%.*]] = icmp ne i32* %arg1, null, !nosanitize // CHECK-NEXT: [[DO_RV_CHECK:%.*]] = and i1 true, [[ARG1CMP]] - // CHECK: br i1 [[DO_RV_CHECK]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize + // CHECK: [[SLOC_PTR:%.*]] = load i8*, i8** %return.sloc.ptr + // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC_PTR]], null + // CHECK-NEXT: [[DO_RV_CHECK_2:%.*]] = and i1 [[SLOC_NONNULL]], [[DO_RV_CHECK]] + // CHECK: br i1 [[DO_RV_CHECK_2]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize // CHECK: [[NULL]]: // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize - // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize + // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize // CHECK: call void @__ubsan_handle_nullability_return{{.*}} return arg1; // CHECK: [[NONULL]]: From 856c94c730b141a86cc782d06d44416241686fb0 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 23 Jun 2017 22:39:01 +0000 Subject: [PATCH 057/214] Revert "[MS] Don't statically initialize dllimport member function pointers" This reverts commit r306137. It has problems on code like this: struct __declspec(dllimport) Foo { int a; int get_a() { return a; } }; template struct HasValue { int operator()(Foo *p) { return (p->*Getter)(); } }; int main() { Foo f; f.a = 3; int x = HasValue<&Foo::get_a>()(&f); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306175 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 16 ------ test/CodeGenCXX/dllimport-memptr-global.cpp | 58 --------------------- 2 files changed, 74 deletions(-) delete mode 100644 test/CodeGenCXX/dllimport-memptr-global.cpp diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 60f8143c137d..768947d00ac4 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1665,19 +1665,6 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc, return true; } -/// Member pointers are constant expressions unless they point to a -/// non-virtual dllimport member function. -static bool CheckMemberPointerConstantExpression(EvalInfo &Info, - SourceLocation Loc, - QualType Type, - const APValue &Value) { - const ValueDecl *Member = Value.getMemberPointerDecl(); - const auto *FD = dyn_cast_or_null(Member); - if (!FD) - return true; - return FD->isVirtual() || !FD->hasAttr(); -} - /// Check that this core constant expression is of literal type, and if not, /// produce an appropriate diagnostic. static bool CheckLiteralType(EvalInfo &Info, const Expr *E, @@ -1770,9 +1757,6 @@ static bool CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc, return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal); } - if (Value.isMemberPointer()) - return CheckMemberPointerConstantExpression(Info, DiagLoc, Type, Value); - // Everything else is fine. return true; } diff --git a/test/CodeGenCXX/dllimport-memptr-global.cpp b/test/CodeGenCXX/dllimport-memptr-global.cpp deleted file mode 100644 index e64537b8b9f9..000000000000 --- a/test/CodeGenCXX/dllimport-memptr-global.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Also check that -Wglobal-constructors does the right thing. Strictly -// speaking, this is a Sema test, but this avoids test case duplication. -// RUN: %clang_cc1 -Wglobal-constructors %s -verify -triple i686-windows-msvc -fms-extensions -std=c++11 -// -// RUN: %clang_cc1 %s -emit-llvm -o - -triple i686-windows-msvc -fms-extensions -std=c++11 | FileCheck %s - -struct __declspec(dllimport) Single { - void nonvirt(); - virtual void virt(); -}; - -struct A { int a; }; -struct B { int b; }; -struct __declspec(dllimport) Multi : A, B { - void nonvirt(); - virtual void virt(); -}; - -struct __declspec(dllimport) Virtual : virtual A { - void nonvirt(); - virtual void virt(); -}; - -struct General; -static_assert(sizeof(void (General::*)()) == 16, "force general memptr model"); -struct __declspec(dllimport) General { - void nonvirt(); - virtual void virt(); -}; - -auto mp_single_nv = &Single::nonvirt; // expected-warning {{global constructor}} -auto mp_multi_nv = &Multi::nonvirt; // expected-warning {{global constructor}} -auto mp_virtual_nv = &Virtual::nonvirt; // expected-warning {{global constructor}} -auto mp_general_nv = &General::nonvirt; // expected-warning {{global constructor}} - -auto mp_single_v = &Single::virt; -auto mp_multi_v = &Multi::virt; -auto mp_virtual_v = &Virtual::virt; -auto mp_general_v = &General::virt; - -// All of the non-virtual globals need dynamic initializers. - -// CHECK: @"\01?mp_single_nv@@3P8Single@@AEXXZQ1@" = global i8* null, align 4 -// CHECK: @"\01?mp_multi_nv@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } zeroinitializer, align 4 -// CHECK: @"\01?mp_virtual_nv@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } zeroinitializer, align 4 -// CHECK: @"\01?mp_general_nv@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, i32 } zeroinitializer, align 4 - -// CHECK: @"\01?mp_single_v@@3P8Single@@AEXXZQ1@" = global i8* bitcast (void (%struct.Single*, ...)* @"\01??_9Single@@$BA@AE" to i8*), align 4 -// CHECK: @"\01?mp_multi_v@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } { i8* bitcast (void (%struct.Multi*, ...)* @"\01??_9Multi@@$BA@AE" to i8*), i32 0 }, align 4 -// CHECK: @"\01?mp_virtual_v@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } { i8* bitcast (void (%struct.Virtual*, ...)* @"\01??_9Virtual@@$BA@AE" to i8*), i32 0, i32 0 }, align 4 -// CHECK: @"\01?mp_general_v@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, i32 } { i8* bitcast (void (%struct.General*, ...)* @"\01??_9General@@$BA@AE" to i8*), i32 0, i32 0, i32 0 }, align 4 - -// CHECK: define internal void @_GLOBAL__sub_I{{.*}}() {{.*}} { -// CHECK: call void @"\01??__Emp_single_nv@@YAXXZ"() -// CHECK: call void @"\01??__Emp_multi_nv@@YAXXZ"() -// CHECK: call void @"\01??__Emp_virtual_nv@@YAXXZ"() -// CHECK: call void @"\01??__Emp_general_nv@@YAXXZ"() -// CHECK: } From 6090a3754a1c9c810da526dfa3888decfd4bfb44 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 23 Jun 2017 23:15:24 +0000 Subject: [PATCH 058/214] [ubsan] Disable the object size check at -O0 This check currently isn't able to diagnose any issues at -O0, not is it likely to [1]. Disabling the check at -O0 leads to substantial compile time and binary size savings. [1] [cfe-dev] Disabling ubsan's object size check at -O0 Differential Revision: https://reviews.llvm.org/D34563 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306181 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ lib/Driver/SanitizerArgs.cpp | 18 +++++++++++- test/Driver/fsanitize-object-size.c | 31 ++++++++++++++++++++ test/Driver/fsanitize.c | 20 ++++++------- 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 test/Driver/fsanitize-object-size.c diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 3833f0f28f05..6ee061cca6a2 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -226,6 +226,8 @@ def warn_drv_enabling_rtti_with_exceptions : Warning< def warn_drv_disabling_vptr_no_rtti_default : Warning< "implicitly disabling vptr sanitizer because rtti wasn't enabled">, InGroup>; +def warn_drv_object_size_disabled_O0 : Warning< + "the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">; def note_drv_command_failed_diag_msg : Note< "diagnostic msg: %0">; diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index d6a9c35eda78..3a30f2a289b0 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -208,12 +208,28 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args); SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap; + // The object size sanitizer should not be enabled at -O0. + Arg *OptLevel = Args.getLastArg(options::OPT_O_Group); + bool RemoveObjectSizeAtO0 = + !OptLevel || OptLevel->getOption().matches(options::OPT_O0); + for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend(); I != E; ++I) { const auto *Arg = *I; if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) { Arg->claim(); - SanitizerMask Add = parseArgValues(D, Arg, true); + SanitizerMask Add = parseArgValues(D, Arg, /*AllowGroups=*/true); + + if (RemoveObjectSizeAtO0) { + AllRemove |= SanitizerKind::ObjectSize; + + // The user explicitly enabled the object size sanitizer. Warn that + // that this does nothing at -O0. + if (Add & SanitizerKind::ObjectSize) + D.Diag(diag::warn_drv_object_size_disabled_O0) + << Arg->getAsString(Args); + } + AllAddedKinds |= expandSanitizerGroups(Add); // Avoid diagnosing any sanitizer which is disabled later. diff --git a/test/Driver/fsanitize-object-size.c b/test/Driver/fsanitize-object-size.c new file mode 100644 index 000000000000..b96221e0fd43 --- /dev/null +++ b/test/Driver/fsanitize-object-size.c @@ -0,0 +1,31 @@ +// Check that the object size check is disabled at -O0. +// +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=null,object-size %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE-NO-WARNING + +// Check that the object size check is enabled at other optimization levels. +// +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O2 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O3 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O4 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Ofast %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Os %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Oz %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Og %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE + +// Use of trap mode shouldn't affect the object size check. +// +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE + +// CHECK-HAS-OSIZE-NOT: warning: the object size sanitizer +// CHECK-HAS-OSIZE: -fsanitize={{[^ ]*}}object-size + +// CHECK-NO-OSIZE: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled: -fsanitize={{[^ ]*}}object-size +// CHECK-NO-OSIZE-NOT: -fsanitize={{[^ ]*}}object-size + +// CHECK-NO-OSIZE-NO-WARNING-NOT: -fsanitize={{[^ ]*}}object-size diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index f14459df6391..0752ef6df090 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -3,18 +3,18 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP -// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}} -// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound" -// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound" +// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}} +// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound" +// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound" // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED -// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){20}"}} +// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}} // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN -// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}} +// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}} // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD -// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}} +// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}} // RUN: %clang -target i386-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN --check-prefix=CHECK-UNDEFINED-WIN32 // RUN: %clang -target i386-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN --check-prefix=CHECK-UNDEFINED-WIN32 --check-prefix=CHECK-UNDEFINED-WIN-CXX @@ -23,7 +23,7 @@ // CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib" // CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib" // CHECK-UNDEFINED-WIN-CXX: "--dependent-lib={{[^"]*}}ubsan_standalone_cxx{{[^"]*}}.lib" -// CHECK-UNDEFINED-WIN-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}} +// CHECK-UNDEFINED-WIN-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}} // RUN: %clang -target i386-pc-win32 -fsanitize-coverage=bb %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COVERAGE-WIN32 // CHECK-COVERAGE-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib" @@ -43,7 +43,7 @@ // CHECK-FNO-SANITIZE-ALL: "-fsanitize=thread" // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread,undefined -fno-sanitize=thread -fno-sanitize=float-cast-overflow,vptr,bool,enum %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PARTIAL-UNDEFINED -// CHECK-PARTIAL-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|array-bounds|returns-nonnull-attribute|nonnull-attribute),?){16}"}} +// CHECK-PARTIAL-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|array-bounds|returns-nonnull-attribute|nonnull-attribute),?){15}"}} // RUN: %clang -target x86_64-linux-gnu -fsanitize=shift -fno-sanitize=shift-base %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FSANITIZE-SHIFT-PARTIAL // CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent" @@ -217,11 +217,11 @@ // RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN // RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=thread -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN // RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -fno-sanitize-recover=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN -// CHECK-RECOVER-UBSAN: "-fsanitize-recover={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}} +// CHECK-RECOVER-UBSAN: "-fsanitize-recover={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}} // CHECK-NO-RECOVER-UBSAN-NOT: sanitize-recover // RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=object-size,shift-base -### 2>&1 | FileCheck %s --check-prefix=CHECK-PARTIAL-RECOVER -// CHECK-PARTIAL-RECOVER: "-fsanitize-recover={{((object-size|shift-base),?){2}"}} +// CHECK-PARTIAL-RECOVER: "-fsanitize-recover={{((shift-base),?){1}"}} // RUN: %clang -target x86_64-linux-gnu %s -fsanitize=address -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-ASAN // CHECK-RECOVER-ASAN: "-fsanitize-recover=address" From 283ac36731893129f189c580dbe2b4b1f6e87241 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 23 Jun 2017 23:34:32 +0000 Subject: [PATCH 059/214] Add a warning to a group Add warn_drv_object_size_disabled_O0 to the invalid command line argument group. This should fix some bot failures: lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/13241/steps/test/logs/stdio git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306183 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 6ee061cca6a2..eb6dd37c148d 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -227,7 +227,8 @@ def warn_drv_disabling_vptr_no_rtti_default : Warning< "implicitly disabling vptr sanitizer because rtti wasn't enabled">, InGroup>; def warn_drv_object_size_disabled_O0 : Warning< - "the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">; + "the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">, + InGroup; def note_drv_command_failed_diag_msg : Note< "diagnostic msg: %0">; From 5ffe2de01efe7f79626ff84ba7fca95bbf80e0ab Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sun, 25 Jun 2017 08:29:09 +0000 Subject: [PATCH 060/214] Add support for Ananas platform Ananas is a home-brew operating system, mainly for amd64 machines. After using GCC for quite some time, it has switched to clang and never looked back - yet, having to manually patch things is annoying, so it'd be much nicer if this was in the official tree. More information: https://github.com/zhmu/ananas/ https://rink.nu/projects/ananas.html Submitted by: Rink Springer Differential Revision: https://reviews.llvm.org/D32936 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306239 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 19 +++++ lib/Driver/CMakeLists.txt | 1 + lib/Driver/Driver.cpp | 4 ++ lib/Driver/ToolChains/Ananas.cpp | 120 +++++++++++++++++++++++++++++++ lib/Driver/ToolChains/Ananas.h | 67 +++++++++++++++++ test/Driver/ananas.c | 9 +++ 6 files changed, 220 insertions(+) create mode 100644 lib/Driver/ToolChains/Ananas.cpp create mode 100644 lib/Driver/ToolChains/Ananas.h create mode 100644 test/Driver/ananas.c diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index aee413e95730..c5af99e4b6af 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -111,6 +111,21 @@ class CloudABITargetInfo : public OSTargetInfo { : OSTargetInfo(Triple, Opts) {} }; +// Ananas target +template +class AnanasTargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, + MacroBuilder &Builder) const override { + // Ananas defines + Builder.defineMacro("__Ananas__"); + Builder.defineMacro("__ELF__"); + } +public: + AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) + : OSTargetInfo(Triple, Opts) {} +}; + static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, @@ -9530,6 +9545,8 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple, return new DarwinI386TargetInfo(Triple, Opts); switch (os) { + case llvm::Triple::Ananas: + return new AnanasTargetInfo(Triple, Opts); case llvm::Triple::CloudABI: return new CloudABITargetInfo(Triple, Opts); case llvm::Triple::Linux: { @@ -9585,6 +9602,8 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple, return new DarwinX86_64TargetInfo(Triple, Opts); switch (os) { + case llvm::Triple::Ananas: + return new AnanasTargetInfo(Triple, Opts); case llvm::Triple::CloudABI: return new CloudABITargetInfo(Triple, Opts); case llvm::Triple::Linux: { diff --git a/lib/Driver/CMakeLists.txt b/lib/Driver/CMakeLists.txt index b639927a95b6..c7ca698d95a0 100644 --- a/lib/Driver/CMakeLists.txt +++ b/lib/Driver/CMakeLists.txt @@ -28,6 +28,7 @@ add_clang_library(clangDriver ToolChains/Arch/Sparc.cpp ToolChains/Arch/SystemZ.cpp ToolChains/Arch/X86.cpp + ToolChains/Ananas.cpp ToolChains/AMDGPU.cpp ToolChains/AVR.cpp ToolChains/Bitrig.cpp diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index c8f389bfb0f7..f23975829eaf 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -11,6 +11,7 @@ #include "InputInfo.h" #include "ToolChains/AMDGPU.h" #include "ToolChains/AVR.h" +#include "ToolChains/Ananas.h" #include "ToolChains/Bitrig.h" #include "ToolChains/Clang.h" #include "ToolChains/CloudABI.h" @@ -3749,6 +3750,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::Haiku: TC = llvm::make_unique(*this, Target, Args); break; + case llvm::Triple::Ananas: + TC = llvm::make_unique(*this, Target, Args); + break; case llvm::Triple::CloudABI: TC = llvm::make_unique(*this, Target, Args); break; diff --git a/lib/Driver/ToolChains/Ananas.cpp b/lib/Driver/ToolChains/Ananas.cpp new file mode 100644 index 000000000000..a67e1d2378f5 --- /dev/null +++ b/lib/Driver/ToolChains/Ananas.cpp @@ -0,0 +1,120 @@ +//===--- Ananas.cpp - Ananas ToolChain Implementations ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "Ananas.h" +#include "InputInfo.h" +#include "CommonArgs.h" +#include "clang/Config/config.h" +#include "clang/Driver/Compilation.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/Options.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Support/Path.h" + +using namespace clang::driver; +using namespace clang::driver::tools; +using namespace clang::driver::toolchains; +using namespace clang; +using namespace llvm::opt; + +void ananas::Assembler::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + claimNoWarnArgs(Args); + ArgStringList CmdArgs; + + Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); + + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + + for (const auto &II : Inputs) + CmdArgs.push_back(II.getFilename()); + + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); +} + +void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + const ToolChain &ToolChain = getToolChain(); + const Driver &D = ToolChain.getDriver(); + ArgStringList CmdArgs; + + // Silence warning for "clang -g foo.o -o foo" + Args.ClaimAllArgs(options::OPT_g_Group); + // and "clang -emit-llvm foo.o -o foo" + Args.ClaimAllArgs(options::OPT_emit_llvm); + // and for "clang -w foo.o -o foo". Other warning options are already + // handled somewhere else. + Args.ClaimAllArgs(options::OPT_w); + + if (!D.SysRoot.empty()) + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + + // Ananas only supports static linkage for now. + CmdArgs.push_back("-Bstatic"); + + if (Output.isFilename()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + } else { + assert(Output.isNothing() && "Invalid output."); + } + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); + } + + Args.AddAllArgs(CmdArgs, options::OPT_L); + ToolChain.AddFilePathLibArgs(Args, CmdArgs); + Args.AddAllArgs(CmdArgs, + {options::OPT_T_Group, options::OPT_e, options::OPT_s, + options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); + + if (D.isUsingLTO()) + AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D); + + AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { + if (D.CCCIsCXX()) + ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); + CmdArgs.push_back("-lc"); + } + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); + } + + const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); +} + +// Ananas - Ananas tool chain which can call as(1) and ld(1) directly. + +Ananas::Ananas(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + : Generic_ELF(D, Triple, Args) { + getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); +} + +Tool *Ananas::buildAssembler() const { + return new tools::ananas::Assembler(*this); +} + +Tool *Ananas::buildLinker() const { return new tools::ananas::Linker(*this); } diff --git a/lib/Driver/ToolChains/Ananas.h b/lib/Driver/ToolChains/Ananas.h new file mode 100644 index 000000000000..2563dd2d49a9 --- /dev/null +++ b/lib/Driver/ToolChains/Ananas.h @@ -0,0 +1,67 @@ +//===--- Ananas.h - Ananas ToolChain Implementations --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ANANAS_H +#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ANANAS_H + +#include "Gnu.h" +#include "clang/Driver/Tool.h" +#include "clang/Driver/ToolChain.h" + +namespace clang { +namespace driver { +namespace tools { + +/// ananas -- Directly call GNU Binutils assembler and linker +namespace ananas { +class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { +public: + Assembler(const ToolChain &TC) + : GnuTool("ananas::Assembler", "assembler", TC) {} + + bool hasIntegratedCPP() const override { return false; } + + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; + +class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { +public: + Linker(const ToolChain &TC) : GnuTool("ananas::Linker", "linker", TC) {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; +} // end namespace ananas +} // end namespace tools + +namespace toolchains { + +class LLVM_LIBRARY_VISIBILITY Ananas : public Generic_ELF { +public: + Ananas(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); + +protected: + Tool *buildAssembler() const override; + Tool *buildLinker() const override; +}; + +} // end namespace toolchains +} // end namespace driver +} // end namespace clang + +#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ANANAS_H diff --git a/test/Driver/ananas.c b/test/Driver/ananas.c new file mode 100644 index 000000000000..2a5b35ed6cec --- /dev/null +++ b/test/Driver/ananas.c @@ -0,0 +1,9 @@ +// RUN: %clang -no-canonical-prefixes -target x86_64-unknown-ananas -static %s \ +// RUN: --sysroot=%S/Inputs/ananas-tree -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-STATIC %s +// CHECK-STATIC: ld{{.*}}" "-Bstatic" +// CHECK-STATIC: crt0.o +// CHECK-STATIC: crti.o +// CHECK-STATIC: crtbegin.o +// CHECK-STATIC: crtend.o +// CHECK-STATIC: crtn.o From 908e5ec11c303467432993194bb8edbc97b22863 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Mon, 26 Jun 2017 00:35:36 +0000 Subject: [PATCH 061/214] [bash-autocompletion] Delete space after flags which has '=' prefix Summary: This is patch for bash completion for clang project. We don't need space when completing options like "-stdlib=". Differential Revision: https://reviews.llvm.org/D34594 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306258 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/bash-autocomplete.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index 3e9f65f10db2..ba908bcc0bc3 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -22,16 +22,17 @@ _clang() elif [[ "$w2" == -* && "$w1" == '=' ]]; then # -foo=bar arg="$w2=,$cur" - else - _filedir fi local flags=$( clang --autocomplete="$arg" ) - if [[ "$cur" == "=" ]]; then + if [[ "$cur" == '=' ]]; then COMPREPLY=( $( compgen -W "$flags" -- "") ) - elif [[ "$flags" == "" ]]; then + elif [[ "$flags" == "" || "$arg" == "" ]]; then _filedir else + # Bash automatically appends a space after '=' by default. + # Disable it so that it works nicely for options in the form of -foo=bar. + [[ "${flags: -1}" == '=' ]] && compopt -o nospace COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) ) fi } From 6bbba4bc2ddadfc90dd125c380f036533182b35c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 26 Jun 2017 02:45:08 +0000 Subject: [PATCH 062/214] Fix a typo git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306261 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/MemorySanitizer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/MemorySanitizer.rst b/docs/MemorySanitizer.rst index 8088ecdf561f..5bb19ed8a509 100644 --- a/docs/MemorySanitizer.rst +++ b/docs/MemorySanitizer.rst @@ -27,7 +27,7 @@ executable, so make sure to use ``clang`` (not ``ld``) for the final link step. When linking shared libraries, the MemorySanitizer run-time is not linked, so ``-Wl,-z,defs`` may cause link errors (don't use it with MemorySanitizer). To get a reasonable performance add ``-O1`` or -higher. To get meaninful stack traces in error messages add +higher. To get meaningful stack traces in error messages add ``-fno-omit-frame-pointer``. To get perfect stack traces you may need to disable inlining (just use ``-O1``) and tail call elimination (``-fno-optimize-sibling-calls``). From 9aa5da98fa039407661e61e35538bee210f4c278 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 26 Jun 2017 03:19:05 +0000 Subject: [PATCH 063/214] clang-format - Also reference the list of style option of clang-format in Libformat git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306266 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LibFormat.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/LibFormat.rst b/docs/LibFormat.rst index eacdc1614567..086a52827d8c 100644 --- a/docs/LibFormat.rst +++ b/docs/LibFormat.rst @@ -28,7 +28,9 @@ The core routine of LibFormat is ``reformat()``: This reads a token stream out of the lexer ``Lex`` and reformats all the code ranges in ``Ranges``. The ``FormatStyle`` controls basic decisions made during -formatting. A list of options can be found under :ref:`style-options`. +formatting. A list of options can be found under :ref:`style-options`. + +The style options are described in :doc:`ClangFormatStyleOptions`. .. _style-options: From 5e20da547e5b423629b840120dd79bedd858a37b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 26 Jun 2017 04:41:22 +0000 Subject: [PATCH 064/214] Testcase missed from r306075. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306270 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Modules/interface-visibility.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/Modules/interface-visibility.m diff --git a/test/Modules/interface-visibility.m b/test/Modules/interface-visibility.m new file mode 100644 index 000000000000..2bb124ce0956 --- /dev/null +++ b/test/Modules/interface-visibility.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fmodules -fobjc-arc -x objective-c-module-map %s -fmodule-name=Foo -verify + +module Foo {} + +#pragma clang module contents +#pragma clang module begin Foo + +// expected-no-diagnostics + +#pragma clang module build Foundation +module Foundation {} +#pragma clang module contents +#pragma clang module begin Foundation +@interface NSIndexSet +@end +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module import Foundation + +@interface NSIndexSet (Testing) +- (int)foo; +@end + +static inline int test(NSIndexSet *obj) { + return [obj foo]; +} + +#pragma clang module end From 703b84157fe3879c4dc8f5c1e5838b4efefdd70f Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Mon, 26 Jun 2017 09:58:01 +0000 Subject: [PATCH 065/214] [mips] Enable IAS by default for Android 64-bit MIPS target (N64) IAS is already used for MIPS64 in majority of Android projects. Android MIPS64 uses N64 ABI. Set IAS as a default now. Differential Revision: https://reviews.llvm.org/D34514 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306280 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Gnu.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp index c9d15ea00d8e..bca5d3a3f28b 100644 --- a/lib/Driver/ToolChains/Gnu.cpp +++ b/lib/Driver/ToolChains/Gnu.cpp @@ -2338,9 +2338,11 @@ bool Generic_GCC::IsIntegratedAssemblerDefault() const { return true; case llvm::Triple::mips64: case llvm::Triple::mips64el: - // Enabled for Debian mips64/mips64el only. Other targets are unable to - // distinguish N32 from N64. - if (getTriple().getEnvironment() == llvm::Triple::GNUABI64) + // Enabled for Debian and Android mips64/mipsel, as they can precisely + // identify the ABI in use (Debian) or only use N64 for MIPS64 (Android). + // Other targets are unable to distinguish N32 from N64. + if (getTriple().getEnvironment() == llvm::Triple::GNUABI64 || + getTriple().isAndroid()) return true; return false; default: From 5a9269f4b211afe37cae3c9f59d0c8f21db1d1dc Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Mon, 26 Jun 2017 15:06:40 +0000 Subject: [PATCH 066/214] Improve const-correctness. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306291 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index a51d3a51d435..2373f1048fe0 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -604,7 +604,7 @@ class Parser : public CodeCompletionHandler { } /// getTypeAnnotation - Read a parsed type out of an annotation token. - static ParsedType getTypeAnnotation(Token &Tok) { + static ParsedType getTypeAnnotation(const Token &Tok) { return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); } @@ -615,7 +615,7 @@ class Parser : public CodeCompletionHandler { /// \brief Read an already-translated primary expression out of an annotation /// token. - static ExprResult getExprAnnotation(Token &Tok) { + static ExprResult getExprAnnotation(const Token &Tok) { return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); } From 0adbf0f7a59c7f701fb1aca07d0a57b317374b88 Mon Sep 17 00:00:00 2001 From: Marina Yatsina Date: Mon, 26 Jun 2017 15:55:51 +0000 Subject: [PATCH 067/214] [inline asm][gcc-compatiblity] "=i" output constraint support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore ‘i’,’n’,’E’,’F’ as output constraints in inline assembly (gcc compatibility) Differential Revision: https://reviews.llvm.org/D31383 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306297 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/TargetInfo.cpp | 5 +++++ test/Sema/asm.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 8cfd8bde9cbb..4bcebadf458f 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -507,6 +507,11 @@ bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const { case '?': // Disparage slightly code. case '!': // Disparage severely. case '*': // Ignore for choosing register preferences. + case 'i': // Ignore i,n,E,F as output constraints (match from the other + // chars) + case 'n': + case 'E': + case 'F': break; // Pass them. } diff --git a/test/Sema/asm.c b/test/Sema/asm.c index e49a1663a896..04b7cb19eb83 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -160,6 +160,41 @@ double test15() { return ret; } +void iOutputConstraint(int x){ + __asm ("nop" : "=ir" (x) : :); // no-error + __asm ("nop" : "=ri" (x) : :); // no-error + __asm ("nop" : "=ig" (x) : :); // no-error + __asm ("nop" : "=im" (x) : :); // no-error + __asm ("nop" : "=imr" (x) : :); // no-error + __asm ("nop" : "=i" (x) : :); // expected-error{{invalid output constraint '=i' in asm}} + __asm ("nop" : "+i" (x) : :); // expected-error{{invalid output constraint '+i' in asm}} + __asm ("nop" : "=ii" (x) : :); // expected-error{{invalid output constraint '=ii' in asm}} + __asm ("nop" : "=nr" (x) : :); // no-error + __asm ("nop" : "=rn" (x) : :); // no-error + __asm ("nop" : "=ng" (x) : :); // no-error + __asm ("nop" : "=nm" (x) : :); // no-error + __asm ("nop" : "=nmr" (x) : :); // no-error + __asm ("nop" : "=n" (x) : :); // expected-error{{invalid output constraint '=n' in asm}} + __asm ("nop" : "+n" (x) : :); // expected-error{{invalid output constraint '+n' in asm}} + __asm ("nop" : "=nn" (x) : :); // expected-error{{invalid output constraint '=nn' in asm}} + __asm ("nop" : "=Fr" (x) : :); // no-error + __asm ("nop" : "=rF" (x) : :); // no-error + __asm ("nop" : "=Fg" (x) : :); // no-error + __asm ("nop" : "=Fm" (x) : :); // no-error + __asm ("nop" : "=Fmr" (x) : :); // no-error + __asm ("nop" : "=F" (x) : :); // expected-error{{invalid output constraint '=F' in asm}} + __asm ("nop" : "+F" (x) : :); // expected-error{{invalid output constraint '+F' in asm}} + __asm ("nop" : "=FF" (x) : :); // expected-error{{invalid output constraint '=FF' in asm}} + __asm ("nop" : "=Er" (x) : :); // no-error + __asm ("nop" : "=rE" (x) : :); // no-error + __asm ("nop" : "=Eg" (x) : :); // no-error + __asm ("nop" : "=Em" (x) : :); // no-error + __asm ("nop" : "=Emr" (x) : :); // no-error + __asm ("nop" : "=E" (x) : :); // expected-error{{invalid output constraint '=E' in asm}} + __asm ("nop" : "+E" (x) : :); // expected-error{{invalid output constraint '+E' in asm}} + __asm ("nop" : "=EE" (x) : :); // expected-error{{invalid output constraint '=EE' in asm}} +} + // PR19837 struct foo { int a; From 042612410244160e40f3cfd952500e2f8cffa31d Mon Sep 17 00:00:00 2001 From: Marina Yatsina Date: Mon, 26 Jun 2017 16:09:55 +0000 Subject: [PATCH 068/214] [inline asm] dot operator while using imm generates wrong ir + asm - clang part Inline asm dot operator while using imm generates wrong ir and asm This is the test for the llvm changes committed in revision 306300 This also fixes bugzilla 32987: https://bugs.llvm.org//show_bug.cgi?id=32987 The llvm part of the review that contains the test can be found here: https://reviews.llvm.org/D33039 commit on behald of zizhar Differential Revision: https://reviews.llvm.org/D33040 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306301 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/ms-inline-asm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/CodeGen/ms-inline-asm.c b/test/CodeGen/ms-inline-asm.c index 5182d7f2e81a..d26a660c9b0a 100644 --- a/test/CodeGen/ms-inline-asm.c +++ b/test/CodeGen/ms-inline-asm.c @@ -627,6 +627,12 @@ void t43() { // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) } +void dot_operator(){ +// CHECK-LABEL: define void @dot_operator + __asm { mov eax, 3[ebx]A.b} +// CHECK: call void asm sideeffect inteldialect "mov eax, $$3[ebx].4", "~{eax},~{dirflag},~{fpsr},~{flags}" +} + void call_clobber() { __asm call t41 // CHECK-LABEL: define void @call_clobber From b6301cec3e28f62507f4ef5e6ea8f2e289e6f423 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Mon, 26 Jun 2017 18:46:12 +0000 Subject: [PATCH 069/214] [Sema] Fix a crash-on-invalid when a template parameter list has a class definition or non-reference class type. The crash occurs when there is a template parameter list in a class that is missing the closing angle bracket followed by a definition of a struct. For example: class C0 { public: template) {} S0 *m; }; This happens because the parsed struct is added to the scope of the enclosing class without having its access specifier set, which results in an assertion failure in SemaAccess.cpp later. This commit fixes the crash by adding the parsed struct to the enclosing file scope and marking structs as invalid if they are defined in template parameter lists. rdar://problem/31783961 rdar://problem/19570630 Differential Revision: https://reviews.llvm.org/D33606 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306317 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 3 +++ include/clang/Sema/Sema.h | 3 ++- lib/Parse/ParseDecl.cpp | 6 +++++- lib/Parse/ParseDeclCXX.cpp | 3 ++- lib/Parse/ParseTemplate.cpp | 3 ++- lib/Sema/SemaDecl.cpp | 10 ++++++---- lib/Sema/SemaDeclCXX.cpp | 3 ++- lib/Sema/SemaTemplate.cpp | 3 ++- test/SemaCXX/PR16677.cpp | 5 ++--- test/SemaCXX/invalid-template-params.cpp | 23 +++++++++++++++++++++++ 10 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 test/SemaCXX/invalid-template-params.cpp diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 2373f1048fe0..21d699ec402e 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1852,6 +1852,7 @@ class Parser : public CodeCompletionHandler { DSC_trailing, // C++11 trailing-type-specifier in a trailing return type DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration DSC_top_level, // top-level/namespace declaration context + DSC_template_param, // template parameter context DSC_template_type_arg, // template type argument context DSC_objc_method_result, // ObjC method result context, enables 'instancetype' DSC_condition // condition declaration context @@ -1862,6 +1863,7 @@ class Parser : public CodeCompletionHandler { static bool isTypeSpecifier(DeclSpecContext DSC) { switch (DSC) { case DSC_normal: + case DSC_template_param: case DSC_class: case DSC_top_level: case DSC_objc_method_result: @@ -1882,6 +1884,7 @@ class Parser : public CodeCompletionHandler { static bool isClassTemplateDeductionContext(DeclSpecContext DSC) { switch (DSC) { case DSC_normal: + case DSC_template_param: case DSC_class: case DSC_top_level: case DSC_condition: diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 1dedf4ba24ce..02c133d1c4fc 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2153,7 +2153,8 @@ class Sema { bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, - bool IsTypeSpecifier, SkipBodyInfo *SkipBody = nullptr); + bool IsTypeSpecifier, bool IsTemplateParamOrArg, + SkipBodyInfo *SkipBody = nullptr); Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, unsigned TagSpec, SourceLocation TagLoc, diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 22696a957a10..d0ce9fc89583 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2629,6 +2629,8 @@ Parser::getDeclSpecContextFromDeclaratorContext(unsigned Context) { return DSC_class; if (Context == Declarator::FileContext) return DSC_top_level; + if (Context == Declarator::TemplateParamContext) + return DSC_template_param; if (Context == Declarator::TemplateTypeArgContext) return DSC_template_type_arg; if (Context == Declarator::TrailingReturnContext) @@ -4261,7 +4263,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, AS, DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent, ScopedEnumKWLoc, IsScopedUsingClassTag, BaseType, - DSC == DSC_type_specifier, &SkipBody); + DSC == DSC_type_specifier, + DSC == DSC_template_param || + DSC == DSC_template_type_arg, &SkipBody); if (SkipBody.ShouldSkip) { assert(TUK == Sema::TUK_Definition && "can only skip a definition"); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 1a4607a84cff..a724fa242268 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1887,7 +1887,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation(), false, clang::TypeResult(), DSC == DSC_type_specifier, - &SkipBody); + DSC == DSC_template_param || + DSC == DSC_template_type_arg, &SkipBody); // If ActOnTag said the type was dependent, try again with the // less common call. diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 37c80fe5e520..944cd775d52a 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -674,7 +674,8 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { // FIXME: The type should probably be restricted in some way... Not all // declarators (parts of declarators?) are accepted for parameters. DeclSpec DS(AttrFactory); - ParseDeclarationSpecifiers(DS); + ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none, + DSC_template_param); // Parse this as a typename. Declarator ParamDecl(DS, Declarator::TemplateParamContext); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b94b8d9e4c1c..e340456bc6da 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -13090,7 +13090,8 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, - bool IsTypeSpecifier, SkipBodyInfo *SkipBody) { + bool IsTypeSpecifier, bool IsTemplateParamOrArg, + SkipBodyInfo *SkipBody) { // If this is not a definition, it must have a name. IdentifierInfo *OrigName = Name; assert((Name != nullptr || TUK == TUK_Definition) && @@ -13360,11 +13361,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // also need to do a redeclaration lookup there, just in case // there's a shadow friend decl. if (Name && Previous.empty() && - (TUK == TUK_Reference || TUK == TUK_Friend)) { + (TUK == TUK_Reference || TUK == TUK_Friend || IsTemplateParamOrArg)) { if (Invalid) goto CreateNewDecl; assert(SS.isEmpty()); - if (TUK == TUK_Reference) { + if (TUK == TUK_Reference || IsTemplateParamOrArg) { // C++ [basic.scope.pdecl]p5: // -- for an elaborated-type-specifier of the form // @@ -13797,7 +13798,8 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // C++11 [dcl.type]p3: // A type-specifier-seq shall not define a class or enumeration [...]. - if (getLangOpts().CPlusPlus && IsTypeSpecifier && TUK == TUK_Definition) { + if (getLangOpts().CPlusPlus && (IsTypeSpecifier || IsTemplateParamOrArg) && + TUK == TUK_Definition) { Diag(New->getLocation(), diag::err_type_defined_in_type_specifier) << Context.getTagDeclType(New); Invalid = true; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0b46e15bb0a3..453ece9d9c4d 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -13394,7 +13394,8 @@ Decl *Sema::ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, /*ScopedEnumKWLoc=*/SourceLocation(), /*ScopedEnumUsesClassTag=*/false, /*UnderlyingType=*/TypeResult(), - /*IsTypeSpecifier=*/false); + /*IsTypeSpecifier=*/false, + /*IsTemplateParamOrArg=*/false); } NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context); diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 1eea151a4ec8..a8923ce9e27d 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -8612,7 +8612,8 @@ Sema::ActOnExplicitInstantiation(Scope *S, /*ModulePrivateLoc=*/SourceLocation(), MultiTemplateParamsArg(), Owned, IsDependent, SourceLocation(), false, TypeResult(), - /*IsTypeSpecifier*/false); + /*IsTypeSpecifier*/false, + /*IsTemplateParamOrArg*/false); assert(!IsDependent && "explicit instantiation of dependent name not yet handled"); if (!TagD) diff --git a/test/SemaCXX/PR16677.cpp b/test/SemaCXX/PR16677.cpp index 7140ac79f089..efa4faaacd69 100644 --- a/test/SemaCXX/PR16677.cpp +++ b/test/SemaCXX/PR16677.cpp @@ -10,7 +10,6 @@ class Base { }; template { // expected-error{{'Derived' cannot be defined in a type specifier}} Class_With_Destructor member; -}; // expected-error{{a non-type template parameter cannot have type 'class Derived'}} - // expected-error@-1{{expected ',' or '>' in template-parameter-list}} - // expected-warning@-2{{declaration does not declare anything}} +}; // expected-error{{expected ',' or '>' in template-parameter-list}} + // expected-warning@-1{{declaration does not declare anything}} diff --git a/test/SemaCXX/invalid-template-params.cpp b/test/SemaCXX/invalid-template-params.cpp new file mode 100644 index 000000000000..0c463fe13d5b --- /dev/null +++ b/test/SemaCXX/invalid-template-params.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +template class Foo { + template' in template-parameter-list}} + // expected-warning@-2 {{declaration does not declare anything}} +}; + +Foo::UBar g1; // expected-error {{no type named 'UBar' in 'Foo'}} + +class C0 { +public: + template' in template-parameter-list}} + // expected-warning@-3 {{declaration does not declare anything}} + C0() : m(new S0) {} // expected-error {{expected '(' for function-style cast or type construction}} + // expected-error@-1 {{expected expression}} + S0 *m; // expected-error {{expected member name or ';' after declaration specifiers}} +}; From 9e788cd10aedd63e5efd1246c0949a5d18ec9f41 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 26 Jun 2017 19:39:25 +0000 Subject: [PATCH 070/214] When preprocessing with -frewrite-imports and -fmodule-file=, do not pass all modules to preprocessing of nested .pcm files. Making those module files available results in loading more .pcm files than necessary, and potentially in misbehavior if a module makes itself visible during its own compilation (as parts of that module that have not yet been processed would then become visible). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306320 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/Rewrite/FrontendActions.cpp | 2 + test/Modules/Inputs/preprocess/file.h | 6 +++ test/Modules/Inputs/preprocess/fwd.h | 1 + .../Inputs/preprocess/module.modulemap | 2 +- test/Modules/Inputs/preprocess/other.h | 1 + test/Modules/preprocess-module.cpp | 44 ++++++++++++------- 6 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 test/Modules/Inputs/preprocess/other.h diff --git a/lib/Frontend/Rewrite/FrontendActions.cpp b/lib/Frontend/Rewrite/FrontendActions.cpp index f64fbdafd597..e93f737c47fd 100644 --- a/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/lib/Frontend/Rewrite/FrontendActions.cpp @@ -247,6 +247,8 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener { Instance.getFrontendOpts().Inputs.clear(); Instance.getFrontendOpts().Inputs.emplace_back( Filename, InputKind(InputKind::Unknown, InputKind::Precompiled)); + Instance.getFrontendOpts().ModuleFiles.clear(); + Instance.getFrontendOpts().ModuleMapFiles.clear(); // Don't recursively rewrite imports. We handle them all at the top level. Instance.getPreprocessorOutputOpts().RewriteImports = false; diff --git a/test/Modules/Inputs/preprocess/file.h b/test/Modules/Inputs/preprocess/file.h index 808ade5768b1..84cf22a33740 100644 --- a/test/Modules/Inputs/preprocess/file.h +++ b/test/Modules/Inputs/preprocess/file.h @@ -1,3 +1,9 @@ +#include "other.h" + +#ifndef FILE_H +#define FILE_H struct __FILE; #include "fwd.h" typedef struct __FILE FILE; +typedef foo bar; +#endif diff --git a/test/Modules/Inputs/preprocess/fwd.h b/test/Modules/Inputs/preprocess/fwd.h index 4a19c6d0c057..f6de1800c000 100644 --- a/test/Modules/Inputs/preprocess/fwd.h +++ b/test/Modules/Inputs/preprocess/fwd.h @@ -1 +1,2 @@ +typedef struct foo foo; struct __FILE; diff --git a/test/Modules/Inputs/preprocess/module.modulemap b/test/Modules/Inputs/preprocess/module.modulemap index f700db03beac..5be2e5c4ff98 100644 --- a/test/Modules/Inputs/preprocess/module.modulemap +++ b/test/Modules/Inputs/preprocess/module.modulemap @@ -1,5 +1,5 @@ module fwd { header "fwd.h" export * } -module file { header "file.h" header "file2.h" export * } +module file { header "file.h" header "file2.h" header "other.h" export * } module nested { module a { header "a.h" } module b { header "b.h" } diff --git a/test/Modules/Inputs/preprocess/other.h b/test/Modules/Inputs/preprocess/other.h new file mode 100644 index 000000000000..84c4d1d5eb23 --- /dev/null +++ b/test/Modules/Inputs/preprocess/other.h @@ -0,0 +1 @@ +// other.h: empty diff --git a/test/Modules/preprocess-module.cpp b/test/Modules/preprocess-module.cpp index 000290fc971b..b0cbac18e780 100644 --- a/test/Modules/preprocess-module.cpp +++ b/test/Modules/preprocess-module.cpp @@ -29,15 +29,15 @@ // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess // Now try building the module when the header files are missing. -// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t +// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%t -x c++-module-map %t/module.modulemap -E -frewrite-includes -o %t/copy.ii -// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap +// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/copy.ii -emit-module -o %t/copy.pcm // Check that our module contains correct mapping information for the headers. -// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t +// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t // RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE -// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap +// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap // Check that we can preprocess from a .pcm file and that we get the same result as preprocessing from the original sources. // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -emit-module -o %t/file.pcm @@ -50,6 +50,10 @@ // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE -DINCLUDE -I%S/Inputs/preprocess // +// Check that we can preprocess this user of the .pcm file. +// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E -frewrite-imports -o %t/preprocess-module.ii +// RUN: %clang_cc1 -fmodules %t/preprocess-module.ii -verify -fno-modules-error-recovery -DFILE_REWRITE_FULL +// // Check that language / header search options are ignored when preprocessing from a .pcm file. // RUN: %clang_cc1 %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii.2 // RUN: cmp %t/file.rewrite.ii %t/file.rewrite.ii.2 @@ -78,12 +82,15 @@ // REWRITE: #pragma clang module begin file // CHECK: # 1 "{{.*}}file.h" 1 // NO-REWRITE: #pragma clang module begin file -// NO-REWRITE: # 1 "{{.*}}file.h"{{$}} // -// CHECK: struct __FILE; +// REWRITE: #ifndef FILE_H +// REWRITE: #define FILE_H +// // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import // CHECK: typedef struct __FILE FILE; // +// REWRITE: #endif +// // REWRITE: #pragma clang module end // CHECK: # 2 "" 2 // NO-REWRITE: #pragma clang module end @@ -105,11 +112,16 @@ // REWRITE: #pragma clang module begin file // CHECK: # 1 "{{.*}}file.h" 1 // NO-REWRITE: #pragma clang module begin file -// NO-REWRITE: # 1 "{{.*}}file.h"{{$}} // -// CHECK: struct __FILE; -// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import -// CHECK: typedef struct __FILE FILE; +// REWRITE: #ifndef FILE_H +// REWRITE: #define FILE_H +// REWRITE: #if 0 +// REWRITE: #include "fwd.h" +// REWRITE: #endif +// REWRITE-NOT: #pragma clang module import fwd +// REWRITE: #endif +// +// NO-REWRITE-NOT: struct __FILE; // // REWRITE: #pragma clang module end // CHECK: # 2 "{{.*}}file2.h" 2 @@ -124,15 +136,17 @@ // NO-REWRITE: #pragma clang module end -__FILE *a; // expected-error {{declaration of '__FILE' must be imported}} +__FILE *a; // expected-error-re {{{{declaration of '__FILE' must be imported|unknown type name '__FILE'}}}} #if FILE_REWRITE -// expected-note@file.rewrite.ii:1 {{here}} +// expected-note@file.rewrite.ii:* {{here}} +#elif FILE_REWRITE_FULL +// No note diagnostic at all in this case: we've built the 'file' module but not loaded it into this compilation yet. #elif REWRITE -// expected-note@rewrite.ii:1 {{here}} +// expected-note@rewrite.ii:* {{here}} #elif COPY -// expected-note@copy.ii:1 {{here}} +// expected-note@copy.ii:* {{here}} #else -// expected-note@no-rewrite.ii:1 {{here}} +// expected-note@no-rewrite.ii:* {{here}} #endif #ifdef INCLUDE From f2468c5d9d036f29b7dae03c6753e8474f5cffff Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 26 Jun 2017 20:15:21 +0000 Subject: [PATCH 071/214] Remove some redundant setup when preprocessing .pcm files. Both of these steps are immediately overwritten by the FrontendAction setup. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306325 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/SourceManager.cpp | 9 --------- lib/Frontend/FrontendAction.cpp | 1 - 2 files changed, 10 deletions(-) diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index fc4c6d303801..3936afab21a4 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -359,15 +359,6 @@ void SourceManager::initializeForReplay(const SourceManager &Old) { return Clone; }; - // Set up our main file ID as a copy of the old source manager's main file. - const SLocEntry &OldMainFile = Old.getSLocEntry(Old.getMainFileID()); - assert(OldMainFile.isFile() && "main file is macro expansion?"); - auto *MainCC = CloneContentCache(OldMainFile.getFile().getContentCache()); - MemBufferInfos.push_back(MainCC); - setMainFileID(createFileID(MainCC, SourceLocation(), - OldMainFile.getFile().getFileCharacteristic(), - 0, 0)); - // Ensure all SLocEntries are loaded from the external source. for (unsigned I = 0, N = Old.LoadedSLocEntryTable.size(); I != N; ++I) if (!Old.SLocEntryLoaded[I]) diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 7c0b854648bd..f81a06b31869 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -561,7 +561,6 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, CI.setFileManager(&AST->getFileManager()); CI.createSourceManager(CI.getFileManager()); CI.getSourceManager().initializeForReplay(AST->getSourceManager()); - CI.createPreprocessor(getTranslationUnitKind()); // Set up the input file for replay purposes. auto Kind = AST->getInputKind(); From 6cfb5bf41823be28bca09fe72dd3d4b83f4e1be8 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 26 Jun 2017 20:33:42 +0000 Subject: [PATCH 072/214] Check that the initializer of a non-dependent constexpr variable is constant even within templates. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306327 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 4 +--- test/SemaCXX/constant-expression-cxx11.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e340456bc6da..71f4d069b804 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11100,9 +11100,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { bool IsGlobal = GlobalStorage && !var->isStaticLocal(); QualType baseType = Context.getBaseElementType(type); - if (!var->getDeclContext()->isDependentContext() && - Init && !Init->isValueDependent()) { - + if (Init && !Init->isValueDependent()) { if (var->isConstexpr()) { SmallVector Notes; if (!var->evaluateValue(Notes) || !var->isInitICE()) { diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 4abbc8e92847..3fda2d0a7fd0 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -608,7 +608,7 @@ namespace DependentValues { struct I { int n; typedef I V[10]; }; I::V x, y; -int g(); +int g(); // expected-note {{declared here}} template struct S : T { int k; void f() { @@ -616,13 +616,23 @@ template struct S : T { I &i = cells[k]; switch (i.n) {} - // FIXME: We should be able to diagnose this. - constexpr int n = g(); + constexpr int n = g(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'g'}} constexpr int m = this->g(); // ok, could be constexpr } }; +extern const int n; +template void f() { + // This is ill-formed, because a hypothetical instantiation at the point of + // template definition would be ill-formed due to a construct that does not + // depend on a template parameter. + constexpr int k = n; // expected-error {{must be initialized by a constant expression}} +} +// It doesn't matter that the instantiation could later become valid: +constexpr int n = 4; +template void f(); + } namespace Class { From 3cbedc8c4aaccac10f1256db4f49d7f5cd27327e Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Mon, 26 Jun 2017 23:02:27 +0000 Subject: [PATCH 073/214] [clang] Enable printf check for CFIndex According to https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html CFIndex and NSInteger should be treated the same way (see the section Platform Dependencies). This diff changes the function shouldNotPrintDirectly in SemaChecking.cpp accordingly and adds tests for the "fixit" and the warning. Differential revision: https://reviews.llvm.org/D34496 Test plan: make check-all git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306343 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 1 + test/FixIt/fixit-format-darwin.m | 10 ++++++++++ test/FixIt/format-darwin.m | 23 ++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index b794628db738..5201796adbbc 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -6000,6 +6000,7 @@ shouldNotPrintDirectly(const ASTContext &Context, while (const TypedefType *UserTy = TyTy->getAs()) { StringRef Name = UserTy->getDecl()->getName(); QualType CastTy = llvm::StringSwitch(Name) + .Case("CFIndex", Context.LongTy) .Case("NSInteger", Context.LongTy) .Case("NSUInteger", Context.UnsignedLongTy) .Case("SInt32", Context.IntTy) diff --git a/test/FixIt/fixit-format-darwin.m b/test/FixIt/fixit-format-darwin.m index 077cc0cf21bc..54d25d92c2b3 100644 --- a/test/FixIt/fixit-format-darwin.m +++ b/test/FixIt/fixit-format-darwin.m @@ -8,12 +8,15 @@ int printf(const char * restrict, ...); #if __LP64__ +typedef long CFIndex; typedef long NSInteger; typedef unsigned long NSUInteger; #else +typedef int CFIndex; typedef int NSInteger; typedef unsigned int NSUInteger; #endif +CFIndex getCFIndex(); NSInteger getNSInteger(); NSUInteger getNSUInteger(); @@ -74,3 +77,10 @@ void bug33447() { Outer2("test 9: %s %s", getNSInteger(), getNSInteger()); // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger()); } + +void testCFIndex() { + printf("test 10: %s", getCFIndex()); + // CHECK: printf("test 10: %ld", (long)getCFIndex()); + printf("test 11: %s %s", getCFIndex(), getCFIndex()); + // CHECK: printf("test 11: %ld %ld", (long)getCFIndex(), (long)getCFIndex()); +} diff --git a/test/FixIt/format-darwin.m b/test/FixIt/format-darwin.m index 170bb09fb904..fcc81036fcf3 100644 --- a/test/FixIt/format-darwin.m +++ b/test/FixIt/format-darwin.m @@ -7,13 +7,14 @@ int printf(const char * restrict, ...); #if __LP64__ +typedef long CFIndex; typedef long NSInteger; typedef unsigned long NSUInteger; typedef int SInt32; typedef unsigned int UInt32; #else - +typedef int CFIndex; typedef int NSInteger; typedef unsigned int NSUInteger; typedef long SInt32; @@ -27,6 +28,7 @@ EnumValueB } NSIntegerEnum; +CFIndex getCFIndex(); NSInteger getNSInteger(); NSUInteger getNSUInteger(); SInt32 getSInt32(); @@ -55,6 +57,11 @@ void testCorrectionInAllCases() { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" + + printf("%s", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" } @interface Foo { @@ -120,6 +127,11 @@ void testWarn() { // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" + + printf("%d", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" } void testPreserveHex() { @@ -167,6 +179,10 @@ void testWarn() { printf("%ld", getNSIntegerEnum()); // expected-warning{{enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)" + + printf("%ld", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)" } void testPreserveHex() { @@ -218,6 +234,11 @@ void testCasts() { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:31}:"(long)" + + printf("%s", (CFIndex)0); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:25}:"(long)" } void testCapitals() { From 74dbb6c51a6706c959ed323673a7d1a9269720e0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 26 Jun 2017 23:19:32 +0000 Subject: [PATCH 074/214] Revert r301742, which caused us to try to evaluate all full-expressions. Also add testcases for a bunch of expression forms that cause our evaluator to crash. See PR33140 and PR32864 for crashes that this was causing. This reverts r305287, which reverted r305239, which reverted r301742. The previous revert claimed that buildbots were broken, but did not add any testcases and the buildbots have lost all memory of what was wrong here. Changes to test/OpenMP are not reverted; another change has triggered those tests to change their output in the same way that r301742 did. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306346 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 1 + lib/AST/ExprConstant.cpp | 13 +++----- lib/Sema/SemaChecking.cpp | 24 ++++++++++++++- test/Sema/integer-overflow.c | 8 +---- test/SemaCXX/eval-crashes.cpp | 56 +++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 test/SemaCXX/eval-crashes.cpp diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 02c133d1c4fc..ef33712d4f47 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -10276,6 +10276,7 @@ class Sema { void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); void CheckBoolLikeConversion(Expr *E, SourceLocation CC); + void CheckForIntOverflow(Expr *E); void CheckUnsequencedOperations(Expr *E); /// \brief Perform semantic checks on a completed expression. This will either diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 768947d00ac4..e836135cf2f9 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -6226,10 +6226,6 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) { // the initializer list. ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType()); const Expr *Init = HaveInit ? E->getInit(ElementNo++) : &VIE; - if (Init->isValueDependent()) { - Success = false; - continue; - } // Temporarily override This, in case there's a CXXDefaultInitExpr in here. ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This, @@ -9940,8 +9936,7 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) { } static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result, - const ASTContext &Ctx, bool &IsConst, - bool IsCheckingForOverflow) { + const ASTContext &Ctx, bool &IsConst) { // Fast-path evaluations of integer literals, since we sometimes see files // containing vast quantities of these. if (const IntegerLiteral *L = dyn_cast(Exp)) { @@ -9962,7 +9957,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result, // performance problems. Only do so in C++11 for now. if (Exp->isRValue() && (Exp->getType()->isArrayType() || Exp->getType()->isRecordType()) && - !Ctx.getLangOpts().CPlusPlus11 && !IsCheckingForOverflow) { + !Ctx.getLangOpts().CPlusPlus11) { IsConst = false; return true; } @@ -9977,7 +9972,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result, /// will be applied to the result. bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const { bool IsConst; - if (FastEvaluateAsRValue(this, Result, Ctx, IsConst, false)) + if (FastEvaluateAsRValue(this, Result, Ctx, IsConst)) return IsConst; EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects); @@ -10102,7 +10097,7 @@ APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx, void Expr::EvaluateForOverflow(const ASTContext &Ctx) const { bool IsConst; EvalResult EvalResult; - if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst, true)) { + if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) { EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow); (void)::EvaluateAsRValue(Info, this, EvalResult.Val); } diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 5201796adbbc..845c4bf61b7a 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -9936,6 +9936,28 @@ void Sema::CheckBoolLikeConversion(Expr *E, SourceLocation CC) { ::CheckBoolLikeConversion(*this, E, CC); } +/// Diagnose when expression is an integer constant expression and its evaluation +/// results in integer overflow +void Sema::CheckForIntOverflow (Expr *E) { + // Use a work list to deal with nested struct initializers. + SmallVector Exprs(1, E); + + do { + Expr *E = Exprs.pop_back_val(); + + if (isa(E->IgnoreParenCasts())) { + E->IgnoreParenCasts()->EvaluateForOverflow(Context); + continue; + } + + if (auto InitList = dyn_cast(E)) + Exprs.append(InitList->inits().begin(), InitList->inits().end()); + + if (isa(E)) + E->IgnoreParenCasts()->EvaluateForOverflow(Context); + } while (!Exprs.empty()); +} + namespace { /// \brief Visitor for expressions which looks for unsequenced operations on the /// same object. @@ -10437,7 +10459,7 @@ void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc, if (!E->isInstantiationDependent()) CheckUnsequencedOperations(E); if (!IsConstexpr && !E->isValueDependent()) - E->EvaluateForOverflow(Context); + CheckForIntOverflow(E); DiagnoseMisalignedMembers(); } diff --git a/test/Sema/integer-overflow.c b/test/Sema/integer-overflow.c index 62ee33e3d181..44c2629ebf7b 100644 --- a/test/Sema/integer-overflow.c +++ b/test/Sema/integer-overflow.c @@ -152,13 +152,7 @@ uint64_t check_integer_overflows(int i) { uint64_t b2 = b[4608 * 1024 * 1024] + 1; // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}} - int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024); - -// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} - int j2 = -(4608 * 1024 * 1024); - -// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} - uint64_t j3 = b[4608 * 1024 * 1024]; + (void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1); // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}} return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024))); diff --git a/test/SemaCXX/eval-crashes.cpp b/test/SemaCXX/eval-crashes.cpp new file mode 100644 index 000000000000..23946845d8ed --- /dev/null +++ b/test/SemaCXX/eval-crashes.cpp @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -std=c++1z -verify %s + +namespace pr32864_0 { + struct transfer_t { + void *fctx; + }; + template class record { + void run() { + transfer_t t; + Ctx from{t.fctx}; + } + }; +} + +namespace pr33140_0a { + struct S { + constexpr S(const int &a = 0) {} + }; + void foo(void) { S s[2] = {}; } +} + +namespace pr33140_0b { + bool bar(float const &f = 0); + bool foo() { return bar() && bar(); } +} + +namespace pr33140_2 { + // FIXME: The declaration of 'b' below should lifetime-extend two int + // temporaries, invalidating this warning to some extent. + struct A { int &&r = 0; }; // expected-warning {{binding reference member 'r' to a temporary}} expected-note {{here}} + struct B { A x, y; }; + B b = {}; +} + +namespace pr33140_3 { + typedef struct Y { unsigned int c; } Y_t; + struct X { + Y_t a; + }; + struct X foo[2] = {[0 ... 1] = {.a = (Y_t){.c = 0}}}; +} + +namespace pr33140_6 { + struct Y { unsigned int c; }; + struct X { struct Y *p; }; + int f() { + // FIXME: This causes clang to crash. + //return (struct X[2]){ [0 ... 1] = { .p = &(struct Y&)(struct Y&&)(struct Y){0} } }[0].p->c; + return 0; + } +} + +namespace pr33140_10 { + int a(const int &n = 0); + bool b() { return a() == a(); } +} From 6eb5127d539c30f8096ad4b181ccffc72243e80d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 26 Jun 2017 23:28:42 +0000 Subject: [PATCH 075/214] AST: enhance mangling for blocks with MS ABI When generating the decorated name for a static variable inside a BlockDecl, construct a scope for the block invocation function that homes the parameter. This allows for arbitrary nesting of the blocks even if the variables are shadowed. Furthermore, using this for the name allows for undname to properly undecorated the name for us. It shows up as the synthetic __block_invocation function that the compiler emitted in the local scope. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306347 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 75 +++++++++++++++++--- test/CodeGenCXX/msabi-blocks.cpp | 113 +++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 10 deletions(-) create mode 100644 test/CodeGenCXX/msabi-blocks.cpp diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index cc7a6941f63a..3a899bdbb6d2 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -966,16 +966,71 @@ void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) { } if (const BlockDecl *BD = dyn_cast(DC)) { - DiagnosticsEngine &Diags = Context.getDiags(); - unsigned DiagID = - Diags.getCustomDiagID(DiagnosticsEngine::Error, - "cannot mangle a local inside this block yet"); - Diags.Report(BD->getLocation(), DiagID); - - // FIXME: This is completely, utterly, wrong; see ItaniumMangle - // for how this should be done. - Out << "__block_invoke" << Context.getBlockId(BD, false); - Out << '@'; + auto Discriminate = + [](StringRef Name, const unsigned Discriminator, + const unsigned ParameterDiscriminator) -> std::string { + std::string Buffer; + llvm::raw_string_ostream Stream(Buffer); + Stream << Name; + if (Discriminator) + Stream << '_' << Discriminator; + if (ParameterDiscriminator) + Stream << '_' << ParameterDiscriminator; + return Stream.str(); + }; + + unsigned Discriminator = BD->getBlockManglingNumber(); + if (!Discriminator) + Discriminator = Context.getBlockId(BD, /*Local=*/false); + + // Mangle the parameter position as a discriminator to deal with unnamed + // parameters. Rather than mangling the unqualified parameter name, + // always use the position to give a uniform mangling. + unsigned ParameterDiscriminator = 0; + if (const auto *MC = BD->getBlockManglingContextDecl()) + if (const auto *P = dyn_cast(MC)) + if (const auto *F = dyn_cast(P->getDeclContext())) + ParameterDiscriminator = + F->getNumParams() - P->getFunctionScopeIndex(); + + DC = getEffectiveDeclContext(BD); + + Out << '?'; + mangleSourceName(Discriminate("_block_invoke", Discriminator, + ParameterDiscriminator)); + // If we have a block mangling context, encode that now. This allows us + // to discriminate between named static data initializers in the same + // scope. This is handled differently from parameters, which use + // positions to discriminate between multiple instances. + if (const auto *MC = BD->getBlockManglingContextDecl()) + if (!isa(MC)) + if (const auto *ND = dyn_cast(MC)) + mangleUnqualifiedName(ND); + // MS ABI and Itanium manglings are in inverted scopes. In the case of a + // RecordDecl, mangle the entire scope hierachy at this point rather than + // just the unqualified name to get the ordering correct. + if (const auto *RD = dyn_cast(DC)) + mangleName(RD); + else + Out << '@'; + // void __cdecl + Out << "YAX"; + // struct __block_literal * + Out << 'P'; + // __ptr64 + if (PointersAre64Bit) + Out << 'E'; + Out << 'A'; + mangleArtificalTagType(TTK_Struct, + Discriminate("__block_literal", Discriminator, + ParameterDiscriminator)); + Out << "@Z"; + + // If the effective context was a Record, we have fully mangled the + // qualified name and do not need to continue. + if (isa(DC)) + break; + continue; } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) { mangleObjCMethodName(Method); } else if (isa(DC)) { diff --git a/test/CodeGenCXX/msabi-blocks.cpp b/test/CodeGenCXX/msabi-blocks.cpp new file mode 100644 index 000000000000..bee59d9ed535 --- /dev/null +++ b/test/CodeGenCXX/msabi-blocks.cpp @@ -0,0 +1,113 @@ +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -std=c++11 -fblocks -S -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-X86 +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++11 -fblocks -S -o - -emit-llvm %s | FileCheck %s -check-prefix CHECK-X64 + +extern int e(void); + +void (^b)() = ^{ + static int i = 0; +}; + +// CHECK-X86-DAG: @"\01?i@?1??_block_invoke@@YAXPAU__block_literal@@@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?1??_block_invoke@@YAXPEAU__block_literal@@@Z@4HA" ={{.*}} global i32 0 + +void f(void) { + static int i = 0; + ^{ static int i = e(); }(); + +// CHECK-X86-DAG: @"\01?i@?1??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?1??_block_invoke_1@@YAXPEAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 + + ^{ static int i = e(); }(); + +// CHECK-X86-DAG: @"\01?i@?1??_block_invoke_2@@YAXPAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?1??_block_invoke_2@@YAXPEAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 + + ^{ ^{ static int i = e(); }(); }(); + +// CHECK-X86-DAG: @"\01?i@?1??_block_invoke_3@@YAXPAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?1??_block_invoke_3@@YAXPEAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPEAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0 +} + + +template +void g(void) { + ^{ static int i = e(); }(); +} + +template void g(void); + +// CHECK-X86-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2???$g@D@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?2??_block_invoke_1@@YAXPEAU__block_literal_1@@@Z?2???$g@D@@YAXXZ@4HA" ={{.*}} global i32 0 + +template void g(void); + +// CHECK-X86-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2???$g@H@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?2??_block_invoke_1@@YAXPEAU__block_literal_1@@@Z?2???$g@H@@YAXXZ@4HA" ={{.*}} global i32 0 + +inline void h(void) { + ^{ static int i = e(); }(); +} + +// CHECK-X86-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2??h@@YAXXZ@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?2??_block_invoke_1@@YAXPEAU__block_literal_1@@@Z?2??h@@YAXXZ@4HA" ={{.*}} global i32 0 + +struct s { + int i = ^{ static int i = e(); return ++i; }(); + +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1@0s@@YAXPAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1@0s@@YAXPEAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 + + int j = ^{ static int i = e(); return ++i; }(); + +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1@j@s@@YAXPAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1@j@s@@YAXPEAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 + + void m(int i = ^{ static int i = e(); return ++i; }(), + int j = ^{ static int i = e(); return ++i; }()) {} + +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1_1@@YAXPAU__block_literal_1_1@@@Z?0??m@s@@QAEXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1_2@@YAXPAU__block_literal_1_2@@@Z?0??m@s@@QAEXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1_1@@YAXPEAU__block_literal_1_1@@@Z?0??m@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1_2@@YAXPEAU__block_literal_1_2@@@Z?0??m@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0 + + void n(int = ^{ static int i = e(); return ++i; }(), + int = ^{ static int i = e(); return ++i; }()) {} + +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1_1@@YAXPAU__block_literal_1_1@@@Z?0??n@s@@QAEXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1_2@@YAXPAU__block_literal_1_2@@@Z?0??n@s@@QAEXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1_1@@YAXPEAU__block_literal_1_1@@@Z?0??n@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1_2@@YAXPEAU__block_literal_1_2@@@Z?0??n@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0 + +}; + +struct t { + struct u { + int i = ^{ static int i = e(); return ++i; }(); + +// CHECK-X86-DAG: @"\01?i@?0??_block_invoke_1@0u@t@@YAXPAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 +// CHECK-X64-DAG: @"\01?i@?0??_block_invoke_1@0u@t@@YAXPEAU__block_literal_1@@@Z@4HA" ={{.*}} global i32 0 + + }; +}; + +void j(void) { + h(); + struct s s; + s.m(); + s.n(); + struct t::u t; +} + +#if 0 +template +struct v { + static T i; +}; + +template +T v::i = ^{ static T i = T(); return i; }(); + +template class v; +template class v; +#endif + From af487b8dcec98f9011f131d9b77ba722bd69f808 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 27 Jun 2017 00:22:07 +0000 Subject: [PATCH 076/214] Fix this test to use a construct that actually forces struct layout to happen when testing -Wpadded. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306349 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Modules/diag-flags.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Modules/diag-flags.cpp b/test/Modules/diag-flags.cpp index 31d2fe4439b8..ada90d24b791 100644 --- a/test/Modules/diag-flags.cpp +++ b/test/Modules/diag-flags.cpp @@ -41,4 +41,4 @@ import diag_flags; #else // expected-no-diagnostics #endif -unsigned n = sizeof(Padded); +int arr[sizeof(Padded)]; From 0113b11a31ef34a6dab42b988e6019dd9660a5c1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 27 Jun 2017 00:29:32 +0000 Subject: [PATCH 077/214] Remove redundant check. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306350 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReader.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index ef2841849ff6..7c9ff0912578 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -3455,12 +3455,6 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, unsigned Idx = 0; F.ModuleMapPath = ReadPath(F, Record, Idx); - if (F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule) { - // For an explicitly-loaded module, we don't care whether the original - // module map file exists or matches. - return Success; - } - // Try to resolve ModuleName in the current header search context and // verify that it is found in the same module map file as we saved. If the // top-level AST file is a main file, skip this check because there is no From 11150dad8c242355c230f1a2da0ac37b7df59ffa Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 27 Jun 2017 04:34:04 +0000 Subject: [PATCH 078/214] [CodeGen][ObjC] Fix GNU's encoding of bit-field ivars. According to the documentation, when encoding a bit-field, GNU runtime needs its starting position in addition to its type and size. https://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html Prior to r297702, the starting position information was not being encoded, which is incorrect, and after r297702, an assertion started to fail because an ObjCIvarDecl was being passed to a function expecting a FieldDecl. This commit moves LookupFieldBitOffset to ASTContext and uses the function to encode the starting position of bit-fields. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306364 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 5 +++ lib/AST/ASTContext.cpp | 16 +++++++-- lib/AST/RecordLayoutBuilder.cpp | 35 ++++++++++++++++++ lib/CodeGen/CGObjCRuntime.cpp | 51 +++++---------------------- test/CodeGenObjC/ivar-type-encoding.m | 16 +++++++++ 5 files changed, 78 insertions(+), 45 deletions(-) diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 4c379620ab2d..3b46d31458ce 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -2050,6 +2050,11 @@ class ASTContext : public RefCountedBase { /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits. uint64_t getFieldOffset(const ValueDecl *FD) const; + /// Get the offset of an ObjCIvarDecl in bits. + uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID, + const ObjCImplementationDecl *ID, + const ObjCIvarDecl *Ivar) const; + bool isNearlyEmpty(const CXXRecordDecl *RD) const; VTableContextBase *getVTableContext(); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index fabfdc9ef7e5..a2ff176df11f 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -5990,9 +5990,19 @@ static void EncodeBitField(const ASTContext *Ctx, std::string& S, // compatibility with GCC, although providing it breaks anything that // actually uses runtime introspection and wants to work on both runtimes... if (Ctx->getLangOpts().ObjCRuntime.isGNUFamily()) { - const RecordDecl *RD = FD->getParent(); - const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); - S += llvm::utostr(RL.getFieldOffset(FD->getFieldIndex())); + uint64_t Offset; + + if (const auto *IVD = dyn_cast(FD)) { + Offset = Ctx->lookupFieldBitOffset(IVD->getContainingInterface(), nullptr, + IVD); + } else { + const RecordDecl *RD = FD->getParent(); + const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); + Offset = RL.getFieldOffset(FD->getFieldIndex()); + } + + S += llvm::utostr(Offset); + if (const EnumType *ET = T->getAs()) S += ObjCEncodingForEnumType(Ctx, ET); else { diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index cf981be0a4dd..c0b9cadca422 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -3073,6 +3073,41 @@ uint64_t ASTContext::getFieldOffset(const ValueDecl *VD) const { return OffsetInBits; } +uint64_t ASTContext::lookupFieldBitOffset(const ObjCInterfaceDecl *OID, + const ObjCImplementationDecl *ID, + const ObjCIvarDecl *Ivar) const { + const ObjCInterfaceDecl *Container = Ivar->getContainingInterface(); + + // FIXME: We should eliminate the need to have ObjCImplementationDecl passed + // in here; it should never be necessary because that should be the lexical + // decl context for the ivar. + + // If we know have an implementation (and the ivar is in it) then + // look up in the implementation layout. + const ASTRecordLayout *RL; + if (ID && declaresSameEntity(ID->getClassInterface(), Container)) + RL = &getASTObjCImplementationLayout(ID); + else + RL = &getASTObjCInterfaceLayout(Container); + + // Compute field index. + // + // FIXME: The index here is closely tied to how ASTContext::getObjCLayout is + // implemented. This should be fixed to get the information from the layout + // directly. + unsigned Index = 0; + + for (const ObjCIvarDecl *IVD = Container->all_declared_ivar_begin(); + IVD; IVD = IVD->getNextIvar()) { + if (Ivar == IVD) + break; + ++Index; + } + assert(Index < RL->getFieldCount() && "Ivar is not inside record layout!"); + + return RL->getFieldOffset(Index); +} + /// getObjCLayout - Get or compute information about the layout of the /// given interface. /// diff --git a/lib/CodeGen/CGObjCRuntime.cpp b/lib/CodeGen/CGObjCRuntime.cpp index b5599dad3096..4cfddcb107cb 100644 --- a/lib/CodeGen/CGObjCRuntime.cpp +++ b/lib/CodeGen/CGObjCRuntime.cpp @@ -26,61 +26,27 @@ using namespace clang; using namespace CodeGen; -static uint64_t LookupFieldBitOffset(CodeGen::CodeGenModule &CGM, - const ObjCInterfaceDecl *OID, - const ObjCImplementationDecl *ID, - const ObjCIvarDecl *Ivar) { - const ObjCInterfaceDecl *Container = Ivar->getContainingInterface(); - - // FIXME: We should eliminate the need to have ObjCImplementationDecl passed - // in here; it should never be necessary because that should be the lexical - // decl context for the ivar. - - // If we know have an implementation (and the ivar is in it) then - // look up in the implementation layout. - const ASTRecordLayout *RL; - if (ID && declaresSameEntity(ID->getClassInterface(), Container)) - RL = &CGM.getContext().getASTObjCImplementationLayout(ID); - else - RL = &CGM.getContext().getASTObjCInterfaceLayout(Container); - - // Compute field index. - // - // FIXME: The index here is closely tied to how ASTContext::getObjCLayout is - // implemented. This should be fixed to get the information from the layout - // directly. - unsigned Index = 0; - - for (const ObjCIvarDecl *IVD = Container->all_declared_ivar_begin(); - IVD; IVD = IVD->getNextIvar()) { - if (Ivar == IVD) - break; - ++Index; - } - assert(Index < RL->getFieldCount() && "Ivar is not inside record layout!"); - - return RL->getFieldOffset(Index); -} - uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *OID, const ObjCIvarDecl *Ivar) { - return LookupFieldBitOffset(CGM, OID, nullptr, Ivar) / - CGM.getContext().getCharWidth(); + return CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar) / + CGM.getContext().getCharWidth(); } uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM, const ObjCImplementationDecl *OID, const ObjCIvarDecl *Ivar) { - return LookupFieldBitOffset(CGM, OID->getClassInterface(), OID, Ivar) / - CGM.getContext().getCharWidth(); + return CGM.getContext().lookupFieldBitOffset(OID->getClassInterface(), OID, + Ivar) / + CGM.getContext().getCharWidth(); } unsigned CGObjCRuntime::ComputeBitfieldBitOffset( CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *ID, const ObjCIvarDecl *Ivar) { - return LookupFieldBitOffset(CGM, ID, ID->getImplementation(), Ivar); + return CGM.getContext().lookupFieldBitOffset(ID, ID->getImplementation(), + Ivar); } LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, @@ -119,7 +85,8 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, // Note, there is a subtle invariant here: we can only call this routine on // non-synthesized ivars but we may be called for synthesized ivars. However, // a synthesized ivar can never be a bit-field, so this is safe. - uint64_t FieldBitOffset = LookupFieldBitOffset(CGF.CGM, OID, nullptr, Ivar); + uint64_t FieldBitOffset = + CGF.CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar); uint64_t BitOffset = FieldBitOffset % CGF.CGM.getContext().getCharWidth(); uint64_t AlignmentBits = CGF.CGM.getTarget().getCharAlign(); uint64_t BitFieldSize = Ivar->getBitWidthValue(CGF.getContext()); diff --git a/test/CodeGenObjC/ivar-type-encoding.m b/test/CodeGenObjC/ivar-type-encoding.m index ffa5e0d7af0d..d3afdc5f1188 100644 --- a/test/CodeGenObjC/ivar-type-encoding.m +++ b/test/CodeGenObjC/ivar-type-encoding.m @@ -33,3 +33,19 @@ int main() { // CHECK: @1 = private unnamed_addr constant [12 x i8] c"@\22NSString\22\00" // CHECK: @2 = private unnamed_addr constant [9 x i8] c"_intIvar\00" // CHECK: @3 = private unnamed_addr constant [2 x i8] c"i\00" + +@interface Class1 { + int : 3; + short : 2; + long long ll; + char : 1; +} +@end + +@implementation Class1 +@end + +// CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b0i3\00" +// CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b3s2\00" +// CHECK: @{{.*}} = private unnamed_addr constant [2 x i8] c"q\00" +// CHECK: @{{.*}} = private unnamed_addr constant [7 x i8] c"b128c1\00" From 0cf2d68b92fe25b9509f16006241925c92cc93ab Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Tue, 27 Jun 2017 07:40:47 +0000 Subject: [PATCH 079/214] clang/test/CodeGenObjC/ivar-type-encoding.m: Tweak to satisfy -m32. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306372 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGenObjC/ivar-type-encoding.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CodeGenObjC/ivar-type-encoding.m b/test/CodeGenObjC/ivar-type-encoding.m index d3afdc5f1188..2fd962cf07bb 100644 --- a/test/CodeGenObjC/ivar-type-encoding.m +++ b/test/CodeGenObjC/ivar-type-encoding.m @@ -48,4 +48,4 @@ @implementation Class1 // CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b0i3\00" // CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b3s2\00" // CHECK: @{{.*}} = private unnamed_addr constant [2 x i8] c"q\00" -// CHECK: @{{.*}} = private unnamed_addr constant [7 x i8] c"b128c1\00" +// CHECK: @{{.*}} = private unnamed_addr constant [{{7|6}} x i8] c"b{{128|96}}c1\00" From 30b455166181c96427d9d464f3bbebc5fcba2410 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Jun 2017 07:59:56 +0000 Subject: [PATCH 080/214] Switch TestVisitor to Lang_C via -x c ...instead of -std=c99, as the latter lead to error: invalid argument '-std=c99' not allowed with 'C++' complaints in test logs Differential Revision: https://reviews.llvm.org/D34417 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306373 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Tooling/TestVisitor.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h index a762ec8b1453..adfd3ef60f50 100644 --- a/unittests/Tooling/TestVisitor.h +++ b/unittests/Tooling/TestVisitor.h @@ -53,7 +53,10 @@ class TestVisitor : public RecursiveASTVisitor { bool runOver(StringRef Code, Language L = Lang_CXX) { std::vector Args; switch (L) { - case Lang_C: Args.push_back("-std=c99"); break; + case Lang_C: + Args.push_back("-x"); + Args.push_back("c"); + break; case Lang_CXX98: Args.push_back("-std=c++98"); break; case Lang_CXX11: Args.push_back("-std=c++11"); break; case Lang_CXX14: Args.push_back("-std=c++14"); break; From 1c3de69555dec079e21aa5b223f7117add0719f4 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Jun 2017 08:04:08 +0000 Subject: [PATCH 081/214] Make sure TraverseInitListExpr visits InitListExpr exactly twice ... once each for the syntactic and semantic form. Without this fix, behavior of the newly added tests would have been InitListExprIsPreOrderVisitedTwice: syntactic: 1 semantic: 2 InitListExprIsPostOrderVisitedTwice: syntactic: 0 semantic: 1 InitListExprIsPreOrderNoQueueVisitedTwice: syntactic: 1 semantic: 2 InitListExprIsPostOrderNoQueueVisitedTwice: syntactic: 0 semantic: 2 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306374 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/RecursiveASTVisitor.h | 18 +++- unittests/Tooling/RecursiveASTVisitorTest.cpp | 86 +++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index ad3f40d0d3f6..152e05bca740 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -593,6 +593,16 @@ bool RecursiveASTVisitor::PostVisitStmt(Stmt *S) { #define STMT(CLASS, PARENT) \ case Stmt::CLASS##Class: \ TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break; +#define INITLISTEXPR(CLASS, PARENT) \ + case Stmt::CLASS##Class: \ + { \ + auto ILE = static_cast(S); \ + if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \ + TRY_TO(WalkUpFrom##CLASS(Syn)); \ + if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \ + TRY_TO(WalkUpFrom##CLASS(Sem)); \ + break; \ + } #include "clang/AST/StmtNodes.inc" } @@ -2220,13 +2230,15 @@ bool RecursiveASTVisitor::TraverseSynOrSemInitListExpr( // the syntactic and the semantic form. // // There is no guarantee about which form \p S takes when this method is called. -DEF_TRAVERSE_STMT(InitListExpr, { +template +bool RecursiveASTVisitor::TraverseInitListExpr( + InitListExpr *S, DataRecursionQueue *Queue) { TRY_TO(TraverseSynOrSemInitListExpr( S->isSemanticForm() ? S->getSyntacticForm() : S, Queue)); TRY_TO(TraverseSynOrSemInitListExpr( S->isSemanticForm() ? S : S->getSemanticForm(), Queue)); - ShouldVisitChildren = false; -}) + return true; +} // GenericSelectionExpr is a special case because the types and expressions // are interleaved. We also need to watch out for null types (default diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp index 269bdbb34ab1..74c9c3db34d8 100644 --- a/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -158,4 +158,90 @@ TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) { "static int k = f();\n")); } +// Check to ensure that InitListExpr is visited twice, once each for the +// syntactic and semantic form. +class InitListExprPreOrderVisitor + : public ExpectedLocationVisitor { +public: + bool VisitInitListExpr(InitListExpr *ILE) { + Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart()); + return true; + } +}; + +class InitListExprPostOrderVisitor + : public ExpectedLocationVisitor { +public: + bool shouldTraversePostOrder() const { return true; } + + bool VisitInitListExpr(InitListExpr *ILE) { + Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart()); + return true; + } +}; + +class InitListExprPreOrderNoQueueVisitor + : public ExpectedLocationVisitor { +public: + bool TraverseInitListExpr(InitListExpr *ILE) { + return ExpectedLocationVisitor::TraverseInitListExpr(ILE); + } + + bool VisitInitListExpr(InitListExpr *ILE) { + Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart()); + return true; + } +}; + +class InitListExprPostOrderNoQueueVisitor + : public ExpectedLocationVisitor { +public: + bool shouldTraversePostOrder() const { return true; } + + bool TraverseInitListExpr(InitListExpr *ILE) { + return ExpectedLocationVisitor::TraverseInitListExpr(ILE); + } + + bool VisitInitListExpr(InitListExpr *ILE) { + Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart()); + return true; + } +}; + +TEST(RecursiveASTVisitor, InitListExprIsPreOrderVisitedTwice) { + InitListExprPreOrderVisitor Visitor; + Visitor.ExpectMatch("syntactic", 2, 21); + Visitor.ExpectMatch("semantic", 2, 21); + EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n" + "static struct S s = {.x = 0};\n", + InitListExprPreOrderVisitor::Lang_C)); +} + +TEST(RecursiveASTVisitor, InitListExprIsPostOrderVisitedTwice) { + InitListExprPostOrderVisitor Visitor; + Visitor.ExpectMatch("syntactic", 2, 21); + Visitor.ExpectMatch("semantic", 2, 21); + EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n" + "static struct S s = {.x = 0};\n", + InitListExprPostOrderVisitor::Lang_C)); +} + +TEST(RecursiveASTVisitor, InitListExprIsPreOrderNoQueueVisitedTwice) { + InitListExprPreOrderNoQueueVisitor Visitor; + Visitor.ExpectMatch("syntactic", 2, 21); + Visitor.ExpectMatch("semantic", 2, 21); + EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n" + "static struct S s = {.x = 0};\n", + InitListExprPreOrderNoQueueVisitor::Lang_C)); +} + +TEST(RecursiveASTVisitor, InitListExprIsPostOrderNoQueueVisitedTwice) { + InitListExprPostOrderNoQueueVisitor Visitor; + Visitor.ExpectMatch("syntactic", 2, 21); + Visitor.ExpectMatch("semantic", 2, 21); + EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n" + "static struct S s = {.x = 0};\n", + InitListExprPostOrderNoQueueVisitor::Lang_C)); +} + } // end anonymous namespace From ee9a82d871679246ce50f35373428367ad86d9ed Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Jun 2017 08:19:09 +0000 Subject: [PATCH 082/214] Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion With struct S1 {}; struct S2 { operator S1(); }; S1 f(S2 s) { return static_cast(s); } the static_cast expr is CXXStaticCastExpr 0x... 'struct S1' static_cast `-CXXConstructExpr 0x... 'struct S1' 'void (struct S1 &&) noexcept' elidable `-MaterializeTemporaryExpr 0x... 'struct S1' xvalue `-ImplicitCastExpr 0x... 'struct S1' `-CXXMemberCallExpr 0x... 'struct S1' `-MemberExpr 0x... '' .operator S1 0x... `-DeclRefExpr 0x... 'struct S2' lvalue ParmVar 0x... 's' 'struct S2' getSubExprAsWritten used to return the MaterializeTemporaryExpr (of type S1) under the CXXConstructExpr, instead of unwinding further to the DeclRefExpr (of type S2) at the bottom. Differential Revision: https://reviews.llvm.org/D22128 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306377 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 29 ++++++++++++++--------- unittests/Tooling/CMakeLists.txt | 1 + unittests/Tooling/CastExprTest.cpp | 38 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 unittests/Tooling/CastExprTest.cpp diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index c21cd3f65bd4..afc7fa8ea094 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1641,25 +1641,32 @@ const char *CastExpr::getCastKindName() const { llvm_unreachable("Unhandled cast kind!"); } +namespace { + Expr *skipImplicitTemporary(Expr *expr) { + // Skip through reference binding to temporary. + if (MaterializeTemporaryExpr *Materialize + = dyn_cast(expr)) + expr = Materialize->GetTemporaryExpr(); + + // Skip any temporary bindings; they're implicit. + if (CXXBindTemporaryExpr *Binder = dyn_cast(expr)) + expr = Binder->getSubExpr(); + + return expr; + } +} + Expr *CastExpr::getSubExprAsWritten() { Expr *SubExpr = nullptr; CastExpr *E = this; do { - SubExpr = E->getSubExpr(); + SubExpr = skipImplicitTemporary(E->getSubExpr()); - // Skip through reference binding to temporary. - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(SubExpr)) - SubExpr = Materialize->GetTemporaryExpr(); - - // Skip any temporary bindings; they're implicit. - if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr)) - SubExpr = Binder->getSubExpr(); - // Conversions by constructor and conversion functions have a // subexpression describing the call; strip it off. if (E->getCastKind() == CK_ConstructorConversion) - SubExpr = cast(SubExpr)->getArg(0); + SubExpr = + skipImplicitTemporary(cast(SubExpr)->getArg(0)); else if (E->getCastKind() == CK_UserDefinedConversion) { assert((isa(SubExpr) || isa(SubExpr)) && diff --git a/unittests/Tooling/CMakeLists.txt b/unittests/Tooling/CMakeLists.txt index b5af99bdfd6d..8ed35480cb88 100644 --- a/unittests/Tooling/CMakeLists.txt +++ b/unittests/Tooling/CMakeLists.txt @@ -11,6 +11,7 @@ if (MSVC) endif() add_clang_unittest(ToolingTests + CastExprTest.cpp CommentHandlerTest.cpp CompilationDatabaseTest.cpp FixItTest.cpp diff --git a/unittests/Tooling/CastExprTest.cpp b/unittests/Tooling/CastExprTest.cpp new file mode 100644 index 000000000000..5310c2125472 --- /dev/null +++ b/unittests/Tooling/CastExprTest.cpp @@ -0,0 +1,38 @@ +//===- unittest/Tooling/CastExprTest.cpp ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "TestVisitor.h" + +using namespace clang; + +namespace { + +struct CastExprVisitor : TestVisitor { + std::function OnExplicitCast; + + bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) { + if (OnExplicitCast) + OnExplicitCast(Expr); + return true; + } +}; + +TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) { + CastExprVisitor Visitor; + Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) { + auto Sub = Expr->getSubExprAsWritten(); + EXPECT_TRUE(isa(Sub)) + << "Expected DeclRefExpr, but saw " << Sub->getStmtClassName(); + }; + Visitor.runOver("struct S1 {};\n" + "struct S2 { operator S1(); };\n" + "S1 f(S2 s) { return static_cast(s); }\n"); +} + +} From 701e513011cbfa9004b16038f3b72bef1bdc6dd2 Mon Sep 17 00:00:00 2001 From: Nikolai Bozhenov Date: Tue, 27 Jun 2017 09:48:24 +0000 Subject: [PATCH 083/214] Reapply "Frontend support for Nios2 target" Summary: - Implements TargetInfo class for Nios2 target. - Enables handling of -march and -mcpu options for Nios2 target. - Definition of Nios2 builtin functions. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D33356 Author: belickim git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306383 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/BuiltinsNios2.def | 70 +++++++++++++ include/clang/Basic/TargetBuiltins.h | 10 ++ include/clang/module.modulemap | 1 + lib/Basic/Targets.cpp | 145 ++++++++++++++++++++++++++ lib/Driver/ToolChains/CommonArgs.cpp | 19 ++++ test/Driver/nios2-cpu.c | 26 +++++ 6 files changed, 271 insertions(+) create mode 100644 include/clang/Basic/BuiltinsNios2.def create mode 100644 test/Driver/nios2-cpu.c diff --git a/include/clang/Basic/BuiltinsNios2.def b/include/clang/Basic/BuiltinsNios2.def new file mode 100644 index 000000000000..d9697e795c44 --- /dev/null +++ b/include/clang/Basic/BuiltinsNios2.def @@ -0,0 +1,70 @@ +//===-- BuiltinsNios2.def - Nios2 Builtin function database --------*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the Nios2-specific builtin function database. Users of +// this file must define the BUILTIN macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +// The format of this database matches clang/Basic/Builtins.def. + +#if defined(BUILTIN) && !defined(TARGET_BUILTIN) +# define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) +#endif + +// Nios2 R1 builtins: + +//int __builtin_ldbio(volatile const void *); +BUILTIN(__builtin_ldbio, "ivDC*", "") +//int __builtin_ldbuio(volatile const void *); +BUILTIN(__builtin_ldbuio, "ivDC*", "") +//int __builtin_ldhio(volatile const void *); +BUILTIN(__builtin_ldhio, "ivDC*", "") +//int __builtin_ldhuio(volatile const void *); +BUILTIN(__builtin_ldhuio, "ivDC*", "") +//int __builtin_ldwio(volatile const void *); +BUILTIN(__builtin_ldwio, "ivDC*", "") +//int __builtin_ldwuio(int); +BUILTIN(__builtin_ldwuio, "ii", "") +// int __builtin_rdctl(int); +BUILTIN(__builtin_rdctl, "iIi", "") +// void __builtin_wrctl(int, int); +BUILTIN(__builtin_wrctl, "vIii", "") +// int __builtin_rdprs(int, int); +BUILTIN(__builtin_rdprs, "iii", "") +//void __builtin_stbio(volatile void *, int); +BUILTIN(__builtin_stbio, "vvD*i", "") +//void __builtin_sthio(volatile void *, int); +BUILTIN(__builtin_sthio, "vvD*i", "") +//void __builtin_stwio(volatile void *, int); +BUILTIN(__builtin_stwio, "vvD*i", "") +//void __builtin_sync(void); +BUILTIN(__builtin_sync, "v", "") +// void __builtin_flushd(volatile void *); +BUILTIN(__builtin_flushd, "vvD*", "") +// void __builtin_flushda(volatile void *); +BUILTIN(__builtin_flushda, "vvD*", "") + +// Nios2 R2 builtins: + +// int __builtin_wrpie(int); +TARGET_BUILTIN(__builtin_wrpie, "ii", "", "nios2r2mandatory") +// void __builtin_eni(int); +TARGET_BUILTIN(__builtin_eni, "vi", "", "nios2r2mandatory") +// int __builtin_ldex(volatile const void *); +TARGET_BUILTIN(__builtin_ldex, "ivDC*", "", "nios2r2mandatory") +// int __builtin_stex(volatile void *, int); +TARGET_BUILTIN(__builtin_stex, "ivD*i", "", "nios2r2mandatory") +// int __builtin_ldsex(volatile const void *); +TARGET_BUILTIN(__builtin_ldsex, "ivDC*", "", "nios2r2mpx") +// int __builtin_stsex(volatile void *, int); +TARGET_BUILTIN(__builtin_stsex, "ivDC*i", "", "nios2r2mpx") + +#undef BUILTIN +#undef TARGET_BUILTIN diff --git a/include/clang/Basic/TargetBuiltins.h b/include/clang/Basic/TargetBuiltins.h index 5d45e162d9f6..8f4f5e9a74dd 100644 --- a/include/clang/Basic/TargetBuiltins.h +++ b/include/clang/Basic/TargetBuiltins.h @@ -150,6 +150,16 @@ namespace clang { }; } + /// \brief Nios2 builtins + namespace Nios2 { + enum { + LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, +#define BUILTIN(ID, TYPE, ATTRS) BI##ID, +#include "clang/Basic/BuiltinsNios2.def" + LastTSBuiltin + }; + } + /// \brief MIPS builtins namespace Mips { enum { diff --git a/include/clang/module.modulemap b/include/clang/module.modulemap index 3b4238110026..282c567c6e51 100644 --- a/include/clang/module.modulemap +++ b/include/clang/module.modulemap @@ -33,6 +33,7 @@ module Clang_Basic { textual header "Basic/BuiltinsLe64.def" textual header "Basic/BuiltinsMips.def" textual header "Basic/BuiltinsNEON.def" + textual header "Basic/BuiltinsNios2.def" textual header "Basic/BuiltinsNVPTX.def" textual header "Basic/BuiltinsPPC.def" textual header "Basic/BuiltinsSystemZ.def" diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index c5af99e4b6af..b9d8dc04b326 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -7727,6 +7727,148 @@ class BPFTargetInfo : public TargetInfo { } }; +class Nios2TargetInfo : public TargetInfo { + void setDataLayout() { + if (BigEndian) + resetDataLayout("E-p:32:32:32-i8:8:32-i16:16:32-n32"); + else + resetDataLayout("e-p:32:32:32-i8:8:32-i16:16:32-n32"); + } + + static const Builtin::Info BuiltinInfo[]; + std::string CPU; + std::string ABI; + +public: + Nios2TargetInfo(const llvm::Triple &triple, const TargetOptions &opts) + : TargetInfo(triple), CPU(opts.CPU), ABI(opts.ABI) { + SizeType = UnsignedInt; + PtrDiffType = SignedInt; + MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32; + setDataLayout(); + } + + StringRef getABI() const override { return ABI; } + bool setABI(const std::string &Name) override { + if (Name == "o32" || Name == "eabi") { + ABI = Name; + return true; + } + return false; + } + + bool setCPU(const std::string &Name) override { + if (Name == "nios2r1" || Name == "nios2r2") { + CPU = Name; + return true; + } + return false; + } + + void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const override { + DefineStd(Builder, "nios2", Opts); + DefineStd(Builder, "NIOS2", Opts); + + Builder.defineMacro("__nios2"); + Builder.defineMacro("__NIOS2"); + Builder.defineMacro("__nios2__"); + Builder.defineMacro("__NIOS2__"); + } + + ArrayRef getTargetBuiltins() const override { + return llvm::makeArrayRef(BuiltinInfo, clang::Nios2::LastTSBuiltin - + Builtin::FirstTSBuiltin); + } + + bool isFeatureSupportedByCPU(StringRef Feature, StringRef CPU) const { + const bool isR2 = CPU == "nios2r2"; + return llvm::StringSwitch(Feature) + .Case("nios2r2mandatory", isR2) + .Case("nios2r2bmx", isR2) + .Case("nios2r2mpx", isR2) + .Case("nios2r2cdx", isR2) + .Default(false); + } + + bool initFeatureMap(llvm::StringMap &Features, + DiagnosticsEngine &Diags, StringRef CPU, + const std::vector &FeatureVec) const override { + static const char *allFeatures[] = { + "nios2r2mandatory", "nios2r2bmx", "nios2r2mpx", "nios2r2cdx" + }; + for (const char *feature : allFeatures) { + Features[feature] = isFeatureSupportedByCPU(feature, CPU); + } + return true; + } + + bool hasFeature(StringRef Feature) const override { + return isFeatureSupportedByCPU(Feature, CPU); + } + + BuiltinVaListKind getBuiltinVaListKind() const override { + return TargetInfo::VoidPtrBuiltinVaList; + } + + ArrayRef getGCCRegNames() const override { + static const char *const GCCRegNames[] = { + // CPU register names + // Must match second column of GCCRegAliases + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", + "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", + "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", + "r31", + // Floating point register names + "ctl0", "ctl1", "ctl2", "ctl3", "ctl4", "ctl5", "ctl6", "ctl7", "ctl8", + "ctl9", "ctl10", "ctl11", "ctl12", "ctl13", "ctl14", "ctl15" + }; + return llvm::makeArrayRef(GCCRegNames); + } + + bool validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &Info) const override { + switch (*Name) { + default: + return false; + + case 'r': // CPU registers. + case 'd': // Equivalent to "r" unless generating MIPS16 code. + case 'y': // Equivalent to "r", backwards compatibility only. + case 'f': // floating-point registers. + case 'c': // $25 for indirect jumps + case 'l': // lo register + case 'x': // hilo register pair + Info.setAllowsRegister(); + return true; + } + } + + const char *getClobbers() const override { return ""; } + + ArrayRef getGCCRegAliases() const override { + static const TargetInfo::GCCRegAlias aliases[] = { + {{"zero"}, "r0"}, {{"at"}, "r1"}, {{"et"}, "r24"}, + {{"bt"}, "r25"}, {{"gp"}, "r26"}, {{"sp"}, "r27"}, + {{"fp"}, "r28"}, {{"ea"}, "r29"}, {{"ba"}, "r30"}, + {{"ra"}, "r31"}, {{"status"}, "ctl0"}, {{"estatus"}, "ctl1"}, + {{"bstatus"}, "ctl2"}, {{"ienable"}, "ctl3"}, {{"ipending"}, "ctl4"}, + {{"cpuid"}, "ctl5"}, {{"exception"}, "ctl7"}, {{"pteaddr"}, "ctl8"}, + {{"tlbacc"}, "ctl9"}, {{"tlbmisc"}, "ctl10"}, {{"badaddr"}, "ctl12"}, + {{"config"}, "ctl13"}, {{"mpubase"}, "ctl14"}, {{"mpuacc"}, "ctl15"}, + }; + return llvm::makeArrayRef(aliases); + } +}; + +const Builtin::Info Nios2TargetInfo::BuiltinInfo[] = { +#define BUILTIN(ID, TYPE, ATTRS) \ + {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ + {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, +#include "clang/Basic/BuiltinsNios2.def" +}; + class MipsTargetInfo : public TargetInfo { void setDataLayout() { StringRef Layout; @@ -9353,6 +9495,9 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::msp430: return new MSP430TargetInfo(Triple, Opts); + case llvm::Triple::nios2: + return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::mips: switch (os) { case llvm::Triple::Linux: diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index 5e360f62e21a..1991b2ecd8fa 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -215,6 +215,21 @@ static std::string getR600TargetGPU(const ArgList &Args) { return ""; } +static std::string getNios2TargetCPU(const ArgList &Args) { + Arg *A = Args.getLastArg(options::OPT_mcpu_EQ); + if (!A) + A = Args.getLastArg(options::OPT_march_EQ); + + if (!A) + return ""; + + const char *name = A->getValue(); + return llvm::StringSwitch(name) + .Case("r1", "nios2r1") + .Case("r2", "nios2r2") + .Default(name); +} + static std::string getLanaiTargetCPU(const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { return A->getValue(); @@ -267,6 +282,10 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T, return A->getValue(); return ""; + case llvm::Triple::nios2: { + return getNios2TargetCPU(Args); + } + case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: diff --git a/test/Driver/nios2-cpu.c b/test/Driver/nios2-cpu.c new file mode 100644 index 000000000000..d98f0384a66d --- /dev/null +++ b/test/Driver/nios2-cpu.c @@ -0,0 +1,26 @@ +// RUN: %clang -target nios2--- %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck %s + +// RUN: %clang -target nios2--- -mcpu=r1 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R1 %s +// RUN: %clang -target nios2--- -mcpu=nios2r1 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R1 %s +// RUN: %clang -target nios2--- -march=r1 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R1 %s +// RUN: %clang -target nios2--- -march=nios2r1 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R1 %s + +// RUN: %clang -target nios2--- -mcpu=r2 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R2 %s +// RUN: %clang -target nios2--- -mcpu=nios2r2 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R2 %s +// RUN: %clang -target nios2--- -march=r2 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R2 %s +// RUN: %clang -target nios2--- -march=nios2r2 %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R2 %s + +// CHECK: "-triple" "nios2---" +// CHECK-R1: "-triple" "nios2---" +// CHECK-R1: "-target-cpu" "nios2r1" +// CHECK-R2: "-triple" "nios2---" +// CHECK-R2: "-target-cpu" "nios2r2" From 8aeb339f3264950654be882dbcf83ad0d47e5ffa Mon Sep 17 00:00:00 2001 From: Christof Douma Date: Tue, 27 Jun 2017 09:50:38 +0000 Subject: [PATCH 084/214] Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"" This reverts commit r305688 meaning it reintroduces r305684. To repeat: [NFC] Refactor DiagnosticRenderer to use FullSourceLoc Move the DiagnosticRenderer and its dependents to using FullSourceLocs instead of a SourceLocation and SourceManager pointer. The changeset is rather large but entirely mechanical. This is step one to allow DiagnosticRenderer to take either llvm::SMLocs or clang::SourceLocations. This breaks clang-tidy and clng-query which will be fixed in a commit soon after. Patch by Sanne Wouda Differential Revision: https://reviews.llvm.org/D31709 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306384 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceLocation.h | 122 +++++++----- include/clang/Frontend/DiagnosticRenderer.h | 81 ++++---- include/clang/Frontend/TextDiagnostic.h | 43 ++-- lib/Basic/SourceLocation.cpp | 70 +++++++ lib/Frontend/DiagnosticRenderer.cpp | 196 ++++++++----------- lib/Frontend/SerializedDiagnosticPrinter.cpp | 106 ++++------ lib/Frontend/TextDiagnostic.cpp | 85 ++++---- lib/Frontend/TextDiagnosticPrinter.cpp | 7 +- tools/libclang/CIndexDiagnostic.cpp | 30 ++- 9 files changed, 377 insertions(+), 363 deletions(-) diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index f0fe4c27062e..12aa0e4f5717 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -262,6 +262,65 @@ class CharSourceRange { bool isInvalid() const { return !isValid(); } }; +/// \brief Represents an unpacked "presumed" location which can be presented +/// to the user. +/// +/// A 'presumed' location can be modified by \#line and GNU line marker +/// directives and is always the expansion point of a normal location. +/// +/// You can get a PresumedLoc from a SourceLocation with SourceManager. +class PresumedLoc { + const char *Filename; + unsigned Line, Col; + SourceLocation IncludeLoc; + +public: + PresumedLoc() : Filename(nullptr) {} + PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) + : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {} + + /// \brief Return true if this object is invalid or uninitialized. + /// + /// This occurs when created with invalid source locations or when walking + /// off the top of a \#include stack. + bool isInvalid() const { return Filename == nullptr; } + bool isValid() const { return Filename != nullptr; } + + /// \brief Return the presumed filename of this location. + /// + /// This can be affected by \#line etc. + const char *getFilename() const { + assert(isValid()); + return Filename; + } + + /// \brief Return the presumed line number of this location. + /// + /// This can be affected by \#line etc. + unsigned getLine() const { + assert(isValid()); + return Line; + } + + /// \brief Return the presumed column number of this location. + /// + /// This cannot be affected by \#line, but is packaged here for convenience. + unsigned getColumn() const { + assert(isValid()); + return Col; + } + + /// \brief Return the presumed include location of this location. + /// + /// This can be affected by GNU linemarker directives. + SourceLocation getIncludeLoc() const { + assert(isValid()); + return IncludeLoc; + } +}; + +class FileEntry; + /// \brief A SourceLocation and its associated SourceManager. /// /// This is useful for argument passing to functions that expect both objects. @@ -274,6 +333,12 @@ class FullSourceLoc : public SourceLocation { explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM) : SourceLocation(Loc), SrcMgr(&SM) {} + bool hasManager() const { + bool hasSrcMgr = SrcMgr != nullptr; + assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no manager"); + return hasSrcMgr; + } + /// \pre This FullSourceLoc has an associated SourceManager. const SourceManager &getManager() const { assert(SrcMgr && "SourceManager is NULL."); @@ -284,6 +349,13 @@ class FullSourceLoc : public SourceLocation { FullSourceLoc getExpansionLoc() const; FullSourceLoc getSpellingLoc() const; + FullSourceLoc getFileLoc() const; + std::pair getImmediateExpansionRange() const; + PresumedLoc getPresumedLoc(bool UseLineDirectives = true) const; + bool isMacroArgExpansion(FullSourceLoc *StartLoc = nullptr) const; + FullSourceLoc getImmediateMacroCallerLoc() const; + std::pair getModuleImportLoc() const; + unsigned getFileOffset() const; unsigned getExpansionLineNumber(bool *Invalid = nullptr) const; unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const; @@ -293,6 +365,12 @@ class FullSourceLoc : public SourceLocation { const char *getCharacterData(bool *Invalid = nullptr) const; + unsigned getLineNumber(bool *Invalid = nullptr) const; + unsigned getColumnNumber(bool *Invalid = nullptr) const; + + std::pair getExpansionRange() const; + + const FileEntry *getFileEntry() const; /// \brief Return a StringRef to the source buffer data for the /// specified FileID. @@ -345,50 +423,6 @@ class FullSourceLoc : public SourceLocation { }; -/// \brief Represents an unpacked "presumed" location which can be presented -/// to the user. -/// -/// A 'presumed' location can be modified by \#line and GNU line marker -/// directives and is always the expansion point of a normal location. -/// -/// You can get a PresumedLoc from a SourceLocation with SourceManager. -class PresumedLoc { - const char *Filename; - unsigned Line, Col; - SourceLocation IncludeLoc; -public: - PresumedLoc() : Filename(nullptr) {} - PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) - : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) { - } - - /// \brief Return true if this object is invalid or uninitialized. - /// - /// This occurs when created with invalid source locations or when walking - /// off the top of a \#include stack. - bool isInvalid() const { return Filename == nullptr; } - bool isValid() const { return Filename != nullptr; } - - /// \brief Return the presumed filename of this location. - /// - /// This can be affected by \#line etc. - const char *getFilename() const { assert(isValid()); return Filename; } - - /// \brief Return the presumed line number of this location. - /// - /// This can be affected by \#line etc. - unsigned getLine() const { assert(isValid()); return Line; } - - /// \brief Return the presumed column number of this location. - /// - /// This cannot be affected by \#line, but is packaged here for convenience. - unsigned getColumn() const { assert(isValid()); return Col; } - - /// \brief Return the presumed include location of this location. - /// - /// This can be affected by GNU linemarker directives. - SourceLocation getIncludeLoc() const { assert(isValid()); return IncludeLoc; } -}; } // end namespace clang diff --git a/include/clang/Frontend/DiagnosticRenderer.h b/include/clang/Frontend/DiagnosticRenderer.h index 2588feb2b87d..54a3d692b3cc 100644 --- a/include/clang/Frontend/DiagnosticRenderer.h +++ b/include/clang/Frontend/DiagnosticRenderer.h @@ -70,33 +70,27 @@ class DiagnosticRenderer { DiagnosticOptions *DiagOpts); virtual ~DiagnosticRenderer(); - - virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, + + virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, - const SourceManager *SM, DiagOrStoredDiag Info) = 0; - - virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, + + virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) = 0; + ArrayRef Ranges) = 0; - virtual void emitCodeContext(SourceLocation Loc, + virtual void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) = 0; - - virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, - const SourceManager &SM) = 0; - virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) = 0; - virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) = 0; + SmallVectorImpl &Ranges, + ArrayRef Hints) = 0; + + virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0; + virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) = 0; + virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) = 0; virtual void beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) {} @@ -106,25 +100,21 @@ class DiagnosticRenderer { private: void emitBasicNote(StringRef Message); - void emitIncludeStack(SourceLocation Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level, const SourceManager &SM); - void emitIncludeStackRecursively(SourceLocation Loc, const SourceManager &SM); - void emitImportStack(SourceLocation Loc, const SourceManager &SM); - void emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName, - const SourceManager &SM); + void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level); + void emitIncludeStackRecursively(FullSourceLoc Loc); + void emitImportStack(FullSourceLoc Loc); + void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName); void emitModuleBuildStack(const SourceManager &SM); - void emitCaret(SourceLocation Loc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, ArrayRef Hints, - const SourceManager &SM); - void emitSingleMacroExpansion(SourceLocation Loc, + void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + ArrayRef Ranges, ArrayRef Hints); + void emitSingleMacroExpansion(FullSourceLoc Loc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM); - void emitMacroExpansions(SourceLocation Loc, - DiagnosticsEngine::Level Level, + ArrayRef Ranges); + void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level, ArrayRef Ranges, - ArrayRef Hints, - const SourceManager &SM); + ArrayRef Hints); + public: /// \brief Emit a diagnostic. /// @@ -140,10 +130,9 @@ class DiagnosticRenderer { /// \param FixItHints The FixIt hints active for this diagnostic. /// \param SM The SourceManager; will be null if the diagnostic came from the /// frontend, thus \p Loc will be invalid. - void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level, + void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, ArrayRef FixItHints, - const SourceManager *SM, DiagOrStoredDiag D = (Diagnostic *)nullptr); void emitStoredDiagnostic(StoredDiagnostic &Diag); @@ -159,19 +148,15 @@ class DiagnosticNoteRenderer : public DiagnosticRenderer { ~DiagnosticNoteRenderer() override; - void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, - const SourceManager &SM) override; + void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; - void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) override; + void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) override; - void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) override; + void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) override; - virtual void emitNote(SourceLocation Loc, StringRef Message, - const SourceManager *SM) = 0; + virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0; }; } // end clang namespace #endif diff --git a/include/clang/Frontend/TextDiagnostic.h b/include/clang/Frontend/TextDiagnostic.h index 9b108c28bd1c..1bbfe9fa02e3 100644 --- a/include/clang/Frontend/TextDiagnostic.h +++ b/include/clang/Frontend/TextDiagnostic.h @@ -75,44 +75,35 @@ class TextDiagnostic : public DiagnosticRenderer { unsigned Columns, bool ShowColors); protected: - void emitDiagnosticMessage(SourceLocation Loc,PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, + void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, - const SourceManager *SM, DiagOrStoredDiag D) override; - void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, + void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) override; - - void emitCodeContext(SourceLocation Loc, - DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) override { - emitSnippetAndCaret(Loc, Level, Ranges, Hints, SM); + ArrayRef Ranges) override; + + void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl &Ranges, + ArrayRef Hints) override { + emitSnippetAndCaret(Loc, Level, Ranges, Hints); } - void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, - const SourceManager &SM) override; + void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; - void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) override; + void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) override; - void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) override; + void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) override; private: void emitFilename(StringRef Filename, const SourceManager &SM); - void emitSnippetAndCaret(SourceLocation Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM); + void emitSnippetAndCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl &Ranges, + ArrayRef Hints); void emitSnippet(StringRef SourceLine); diff --git a/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp index a58d0465a6f4..89ddbc946a49 100644 --- a/lib/Basic/SourceLocation.cpp +++ b/lib/Basic/SourceLocation.cpp @@ -92,6 +92,76 @@ FullSourceLoc FullSourceLoc::getSpellingLoc() const { return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr); } +FullSourceLoc FullSourceLoc::getFileLoc() const { + assert(isValid()); + return FullSourceLoc(SrcMgr->getFileLoc(*this), *SrcMgr); +} + +std::pair +FullSourceLoc::getImmediateExpansionRange() const { + assert(isValid()); + std::pair Range = + SrcMgr->getImmediateExpansionRange(*this); + return std::make_pair(FullSourceLoc(Range.first, *SrcMgr), + FullSourceLoc(Range.second, *SrcMgr)); +} + +PresumedLoc FullSourceLoc::getPresumedLoc(bool UseLineDirectives) const { + if (!isValid()) + return PresumedLoc(); + + return SrcMgr->getPresumedLoc(*this, UseLineDirectives); +} + +bool FullSourceLoc::isMacroArgExpansion(FullSourceLoc *StartLoc) const { + assert(isValid()); + return SrcMgr->isMacroArgExpansion(*this, StartLoc); +} + +FullSourceLoc FullSourceLoc::getImmediateMacroCallerLoc() const { + assert(isValid()); + return FullSourceLoc(SrcMgr->getImmediateMacroCallerLoc(*this), *SrcMgr); +} + +std::pair FullSourceLoc::getModuleImportLoc() const { + if (!isValid()) + return std::make_pair(FullSourceLoc(), StringRef()); + + std::pair ImportLoc = + SrcMgr->getModuleImportLoc(*this); + return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr), + ImportLoc.second); +} + +unsigned FullSourceLoc::getFileOffset() const { + assert(isValid()); + return SrcMgr->getFileOffset(*this); +} + +unsigned FullSourceLoc::getLineNumber(bool *Invalid) const { + assert(isValid()); + return SrcMgr->getLineNumber(getFileID(), getFileOffset(), Invalid); +} + +unsigned FullSourceLoc::getColumnNumber(bool *Invalid) const { + assert(isValid()); + return SrcMgr->getColumnNumber(getFileID(), getFileOffset(), Invalid); +} + +std::pair +FullSourceLoc::getExpansionRange() const { + assert(isValid()); + std::pair Range = + SrcMgr->getExpansionRange(*this); + return std::make_pair(FullSourceLoc(Range.first, *SrcMgr), + FullSourceLoc(Range.second, *SrcMgr)); +} + +const FileEntry *FullSourceLoc::getFileEntry() const { + assert(isValid()); + return SrcMgr->getFileEntryForID(getFileID()); +} + unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const { assert(isValid()); return SrcMgr->getExpansionLineNumber(*this, Invalid); diff --git a/lib/Frontend/DiagnosticRenderer.cpp b/lib/Frontend/DiagnosticRenderer.cpp index 177feac97441..e3263843e29b 100644 --- a/lib/Frontend/DiagnosticRenderer.cpp +++ b/lib/Frontend/DiagnosticRenderer.cpp @@ -76,20 +76,19 @@ static void mergeFixits(ArrayRef FixItHints, } } -void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, +void DiagnosticRenderer::emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, ArrayRef FixItHints, - const SourceManager *SM, DiagOrStoredDiag D) { - assert(SM || Loc.isInvalid()); + assert(Loc.hasManager() || Loc.isInvalid()); beginDiagnostic(D, Level); if (!Loc.isValid()) // If we have no source location, just emit the diagnostic message. - emitDiagnosticMessage(Loc, PresumedLoc(), Level, Message, Ranges, SM, D); + emitDiagnosticMessage(Loc, PresumedLoc(), Level, Message, Ranges, D); else { // Get the ranges into a local array we can hack on. SmallVector MutableRanges(Ranges.begin(), @@ -97,7 +96,7 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, SmallVector MergedFixits; if (!FixItHints.empty()) { - mergeFixits(FixItHints, *SM, LangOpts, MergedFixits); + mergeFixits(FixItHints, Loc.getManager(), LangOpts, MergedFixits); FixItHints = MergedFixits; } @@ -107,25 +106,25 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, if (I->RemoveRange.isValid()) MutableRanges.push_back(I->RemoveRange); - SourceLocation UnexpandedLoc = Loc; + FullSourceLoc UnexpandedLoc = Loc; // Find the ultimate expansion location for the diagnostic. - Loc = SM->getFileLoc(Loc); + Loc = Loc.getFileLoc(); - PresumedLoc PLoc = SM->getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); + PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc); // First, if this diagnostic is not in the main file, print out the // "included from" lines. - emitIncludeStack(Loc, PLoc, Level, *SM); + emitIncludeStack(Loc, PLoc, Level); // Next, emit the actual diagnostic message and caret. - emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, SM, D); - emitCaret(Loc, Level, MutableRanges, FixItHints, *SM); + emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, D); + emitCaret(Loc, Level, MutableRanges, FixItHints); // If this location is within a macro, walk from UnexpandedLoc up to Loc // and produce a macro backtrace. if (UnexpandedLoc.isValid() && UnexpandedLoc.isMacroID()) { - emitMacroExpansions(UnexpandedLoc, Level, MutableRanges, FixItHints, *SM); + emitMacroExpansions(UnexpandedLoc, Level, MutableRanges, FixItHints); } } @@ -139,15 +138,12 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, void DiagnosticRenderer::emitStoredDiagnostic(StoredDiagnostic &Diag) { emitDiagnostic(Diag.getLocation(), Diag.getLevel(), Diag.getMessage(), Diag.getRanges(), Diag.getFixIts(), - Diag.getLocation().isValid() ? &Diag.getLocation().getManager() - : nullptr, &Diag); } void DiagnosticRenderer::emitBasicNote(StringRef Message) { - emitDiagnosticMessage( - SourceLocation(), PresumedLoc(), DiagnosticsEngine::Note, Message, - None, nullptr, DiagOrStoredDiag()); + emitDiagnosticMessage(FullSourceLoc(), PresumedLoc(), DiagnosticsEngine::Note, + Message, None, DiagOrStoredDiag()); } /// \brief Prints an include stack when appropriate for a particular @@ -161,12 +157,11 @@ void DiagnosticRenderer::emitBasicNote(StringRef Message) { /// \param Loc The diagnostic location. /// \param PLoc The presumed location of the diagnostic location. /// \param Level The diagnostic level of the message this stack pertains to. -void DiagnosticRenderer::emitIncludeStack(SourceLocation Loc, - PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - const SourceManager &SM) { - SourceLocation IncludeLoc = - PLoc.isInvalid() ? SourceLocation() : PLoc.getIncludeLoc(); +void DiagnosticRenderer::emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level) { + FullSourceLoc IncludeLoc = + PLoc.isInvalid() ? FullSourceLoc() + : FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager()); // Skip redundant include stacks altogether. if (LastIncludeLoc == IncludeLoc) @@ -178,74 +173,70 @@ void DiagnosticRenderer::emitIncludeStack(SourceLocation Loc, return; if (IncludeLoc.isValid()) - emitIncludeStackRecursively(IncludeLoc, SM); + emitIncludeStackRecursively(IncludeLoc); else { - emitModuleBuildStack(SM); - emitImportStack(Loc, SM); + emitModuleBuildStack(Loc.getManager()); + emitImportStack(Loc); } } /// \brief Helper to recursivly walk up the include stack and print each layer /// on the way back down. -void DiagnosticRenderer::emitIncludeStackRecursively(SourceLocation Loc, - const SourceManager &SM) { +void DiagnosticRenderer::emitIncludeStackRecursively(FullSourceLoc Loc) { if (Loc.isInvalid()) { - emitModuleBuildStack(SM); + emitModuleBuildStack(Loc.getManager()); return; } - - PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); + + PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc); if (PLoc.isInvalid()) return; // If this source location was imported from a module, print the module // import stack rather than the // FIXME: We want submodule granularity here. - std::pair Imported = SM.getModuleImportLoc(Loc); + std::pair Imported = Loc.getModuleImportLoc(); if (!Imported.second.empty()) { // This location was imported by a module. Emit the module import stack. - emitImportStackRecursively(Imported.first, Imported.second, SM); + emitImportStackRecursively(Imported.first, Imported.second); return; } // Emit the other include frames first. - emitIncludeStackRecursively(PLoc.getIncludeLoc(), SM); - + emitIncludeStackRecursively( + FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager())); + // Emit the inclusion text/note. - emitIncludeLocation(Loc, PLoc, SM); + emitIncludeLocation(Loc, PLoc); } /// \brief Emit the module import stack associated with the current location. -void DiagnosticRenderer::emitImportStack(SourceLocation Loc, - const SourceManager &SM) { +void DiagnosticRenderer::emitImportStack(FullSourceLoc Loc) { if (Loc.isInvalid()) { - emitModuleBuildStack(SM); + emitModuleBuildStack(Loc.getManager()); return; } - std::pair NextImportLoc - = SM.getModuleImportLoc(Loc); - emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM); + std::pair NextImportLoc = Loc.getModuleImportLoc(); + emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second); } /// \brief Helper to recursivly walk up the import stack and print each layer /// on the way back down. -void DiagnosticRenderer::emitImportStackRecursively(SourceLocation Loc, - StringRef ModuleName, - const SourceManager &SM) { +void DiagnosticRenderer::emitImportStackRecursively(FullSourceLoc Loc, + StringRef ModuleName) { if (ModuleName.empty()) { return; } - PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); + PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc); // Emit the other import frames first. - std::pair NextImportLoc - = SM.getModuleImportLoc(Loc); - emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM); + std::pair NextImportLoc = Loc.getModuleImportLoc(); + emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second); // Emit the inclusion text/note. - emitImportLocation(Loc, PLoc, ModuleName, SM); + emitImportLocation(Loc, PLoc, ModuleName); } /// \brief Emit the module build stack, for cases where a module is (re-)built @@ -253,13 +244,9 @@ void DiagnosticRenderer::emitImportStackRecursively(SourceLocation Loc, void DiagnosticRenderer::emitModuleBuildStack(const SourceManager &SM) { ModuleBuildStack Stack = SM.getModuleBuildStack(); for (unsigned I = 0, N = Stack.size(); I != N; ++I) { - const SourceManager &CurSM = Stack[I].second.getManager(); - SourceLocation CurLoc = Stack[I].second; - emitBuildingModuleLocation(CurLoc, - CurSM.getPresumedLoc(CurLoc, + emitBuildingModuleLocation(Stack[I].second, Stack[I].second.getPresumedLoc( DiagOpts->ShowPresumedLoc), - Stack[I].first, - CurSM); + Stack[I].first); } } @@ -348,12 +335,12 @@ static void computeCommonMacroArgExpansionFileIDs( // in the same expansion as the caret; otherwise, we crawl to the top of // each chain. Two locations are part of the same macro expansion // iff the FileID is the same. -static void mapDiagnosticRanges( - SourceLocation CaretLoc, - ArrayRef Ranges, - SmallVectorImpl &SpellingRanges, - const SourceManager *SM) { - FileID CaretLocFileID = SM->getFileID(CaretLoc); +static void +mapDiagnosticRanges(FullSourceLoc CaretLoc, ArrayRef Ranges, + SmallVectorImpl &SpellingRanges) { + FileID CaretLocFileID = CaretLoc.getFileID(); + + const SourceManager *SM = &CaretLoc.getManager(); for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { if (I->isInvalid()) continue; @@ -404,42 +391,39 @@ static void mapDiagnosticRanges( } } -void DiagnosticRenderer::emitCaret(SourceLocation Loc, +void DiagnosticRenderer::emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, ArrayRef Ranges, - ArrayRef Hints, - const SourceManager &SM) { + ArrayRef Hints) { SmallVector SpellingRanges; - mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM); - emitCodeContext(Loc, Level, SpellingRanges, Hints, SM); + mapDiagnosticRanges(Loc, Ranges, SpellingRanges); + emitCodeContext(Loc, Level, SpellingRanges, Hints); } /// \brief A helper function for emitMacroExpansion to print the /// macro expansion message void DiagnosticRenderer::emitSingleMacroExpansion( - SourceLocation Loc, - DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) { + FullSourceLoc Loc, DiagnosticsEngine::Level Level, + ArrayRef Ranges) { // Find the spelling location for the macro definition. We must use the // spelling location here to avoid emitting a macro backtrace for the note. - SourceLocation SpellingLoc = SM.getSpellingLoc(Loc); + FullSourceLoc SpellingLoc = Loc.getSpellingLoc(); // Map the ranges into the FileID of the diagnostic location. SmallVector SpellingRanges; - mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM); + mapDiagnosticRanges(Loc, Ranges, SpellingRanges); SmallString<100> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); - StringRef MacroName = - Lexer::getImmediateMacroNameForDiagnostics(Loc, SM, LangOpts); + StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics( + Loc, Loc.getManager(), LangOpts); if (MacroName.empty()) Message << "expanded from here"; else Message << "expanded from macro '" << MacroName << "'"; emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note, Message.str(), - SpellingRanges, None, &SM); + SpellingRanges, None); } /// Check that the macro argument location of Loc starts with ArgumentLoc. @@ -473,13 +457,12 @@ static bool checkRangeForMacroArgExpansion(CharSourceRange Range, /// A helper function to check if the current ranges are all inside the same /// macro argument expansion as Loc. -static bool checkRangesForMacroArgExpansion(SourceLocation Loc, - ArrayRef Ranges, - const SourceManager &SM) { +static bool checkRangesForMacroArgExpansion(FullSourceLoc Loc, + ArrayRef Ranges) { assert(Loc.isMacroID() && "Must be a macro expansion!"); SmallVector SpellingRanges; - mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM); + mapDiagnosticRanges(Loc, Ranges, SpellingRanges); /// Count all valid ranges. unsigned ValidCount = 0; @@ -490,15 +473,15 @@ static bool checkRangesForMacroArgExpansion(SourceLocation Loc, return false; /// To store the source location of the argument location. - SourceLocation ArgumentLoc; + FullSourceLoc ArgumentLoc; /// Set the ArgumentLoc to the beginning location of the expansion of Loc /// so to check if the ranges expands to the same beginning location. - if (!SM.isMacroArgExpansion(Loc,&ArgumentLoc)) + if (!Loc.isMacroArgExpansion(&ArgumentLoc)) return false; for (auto I = SpellingRanges.begin(), E = SpellingRanges.end(); I != E; ++I) { - if (!checkRangeForMacroArgExpansion(*I, SM, ArgumentLoc)) + if (!checkRangeForMacroArgExpansion(*I, Loc.getManager(), ArgumentLoc)) return false; } @@ -516,34 +499,33 @@ static bool checkRangesForMacroArgExpansion(SourceLocation Loc, /// \param Level The diagnostic level currently being emitted. /// \param Ranges The underlined ranges for this code snippet. /// \param Hints The FixIt hints active for this diagnostic. -void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc, +void DiagnosticRenderer::emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level, ArrayRef Ranges, - ArrayRef Hints, - const SourceManager &SM) { + ArrayRef Hints) { assert(Loc.isValid() && "must have a valid source location here"); // Produce a stack of macro backtraces. - SmallVector LocationStack; + SmallVector LocationStack; unsigned IgnoredEnd = 0; while (Loc.isMacroID()) { // If this is the expansion of a macro argument, point the caret at the // use of the argument in the definition of the macro, not the expansion. - if (SM.isMacroArgExpansion(Loc)) - LocationStack.push_back(SM.getImmediateExpansionRange(Loc).first); + if (Loc.isMacroArgExpansion()) + LocationStack.push_back(Loc.getImmediateExpansionRange().first); else LocationStack.push_back(Loc); - if (checkRangesForMacroArgExpansion(Loc, Ranges, SM)) + if (checkRangesForMacroArgExpansion(Loc, Ranges)) IgnoredEnd = LocationStack.size(); - Loc = SM.getImmediateMacroCallerLoc(Loc); + Loc = Loc.getImmediateMacroCallerLoc(); // Once the location no longer points into a macro, try stepping through // the last found location. This sometimes produces additional useful // backtraces. if (Loc.isFileID()) - Loc = SM.getImmediateMacroCallerLoc(LocationStack.back()); + Loc = LocationStack.back().getImmediateMacroCallerLoc(); assert(Loc.isValid() && "must have a valid source location here"); } @@ -555,7 +537,7 @@ void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc, if (MacroDepth <= MacroLimit || MacroLimit == 0) { for (auto I = LocationStack.rbegin(), E = LocationStack.rend(); I != E; ++I) - emitSingleMacroExpansion(*I, Level, Ranges, SM); + emitSingleMacroExpansion(*I, Level, Ranges); return; } @@ -565,7 +547,7 @@ void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc, for (auto I = LocationStack.rbegin(), E = LocationStack.rbegin() + MacroStartMessages; I != E; ++I) - emitSingleMacroExpansion(*I, Level, Ranges, SM); + emitSingleMacroExpansion(*I, Level, Ranges); SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); @@ -577,26 +559,24 @@ void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc, for (auto I = LocationStack.rend() - MacroEndMessages, E = LocationStack.rend(); I != E; ++I) - emitSingleMacroExpansion(*I, Level, Ranges, SM); + emitSingleMacroExpansion(*I, Level, Ranges); } DiagnosticNoteRenderer::~DiagnosticNoteRenderer() {} -void DiagnosticNoteRenderer::emitIncludeLocation(SourceLocation Loc, - PresumedLoc PLoc, - const SourceManager &SM) { +void DiagnosticNoteRenderer::emitIncludeLocation(FullSourceLoc Loc, + PresumedLoc PLoc) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); Message << "in file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; - emitNote(Loc, Message.str(), &SM); + emitNote(Loc, Message.str()); } -void DiagnosticNoteRenderer::emitImportLocation(SourceLocation Loc, +void DiagnosticNoteRenderer::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) { + StringRef ModuleName) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); @@ -605,14 +585,12 @@ void DiagnosticNoteRenderer::emitImportLocation(SourceLocation Loc, Message << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine(); Message << ":"; - emitNote(Loc, Message.str(), &SM); + emitNote(Loc, Message.str()); } -void -DiagnosticNoteRenderer::emitBuildingModuleLocation(SourceLocation Loc, - PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) { +void DiagnosticNoteRenderer::emitBuildingModuleLocation(FullSourceLoc Loc, + PresumedLoc PLoc, + StringRef ModuleName) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); @@ -621,5 +599,5 @@ DiagnosticNoteRenderer::emitBuildingModuleLocation(SourceLocation Loc, << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; else Message << "while building module '" << ModuleName << "':"; - emitNote(Loc, Message.str(), &SM); + emitNote(Loc, Message.str()); } diff --git a/lib/Frontend/SerializedDiagnosticPrinter.cpp b/lib/Frontend/SerializedDiagnosticPrinter.cpp index b5a5acd8ad9a..7666fe10b381 100644 --- a/lib/Frontend/SerializedDiagnosticPrinter.cpp +++ b/lib/Frontend/SerializedDiagnosticPrinter.cpp @@ -63,27 +63,20 @@ class SDiagsRenderer : public DiagnosticNoteRenderer { ~SDiagsRenderer() override {} protected: - void emitDiagnosticMessage(SourceLocation Loc, - PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, + void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, - const SourceManager *SM, DiagOrStoredDiag D) override; - void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, + void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) override {} + ArrayRef Ranges) override {} - void emitNote(SourceLocation Loc, StringRef Message, - const SourceManager *SM) override; + void emitNote(FullSourceLoc Loc, StringRef Message) override; - void emitCodeContext(SourceLocation Loc, - DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) override; + void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl &Ranges, + ArrayRef Hints) override; void beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) override; @@ -193,11 +186,8 @@ class SDiagsWriter : public DiagnosticConsumer { void ExitDiagBlock(); /// \brief Emit a DIAG record. - void EmitDiagnosticMessage(SourceLocation Loc, - PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, - const SourceManager *SM, + void EmitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, StringRef Message, DiagOrStoredDiag D); /// \brief Emit FIXIT and SOURCE_RANGE records for a diagnostic. @@ -220,16 +210,14 @@ class SDiagsWriter : public DiagnosticConsumer { /// \brief Emit (lazily) the file string and retrieved the file identifier. unsigned getEmitFile(const char *Filename); - /// \brief Add SourceLocation information the specified record. - void AddLocToRecord(SourceLocation Loc, const SourceManager *SM, - PresumedLoc PLoc, RecordDataImpl &Record, - unsigned TokSize = 0); + /// \brief Add SourceLocation information the specified record. + void AddLocToRecord(FullSourceLoc Loc, PresumedLoc PLoc, + RecordDataImpl &Record, unsigned TokSize = 0); /// \brief Add SourceLocation information the specified record. - void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record, - const SourceManager *SM, + void AddLocToRecord(FullSourceLoc Loc, RecordDataImpl &Record, unsigned TokSize = 0) { - AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(), + AddLocToRecord(Loc, Loc.hasManager() ? Loc.getPresumedLoc() : PresumedLoc(), Record, TokSize); } @@ -350,11 +338,8 @@ static void EmitRecordID(unsigned ID, const char *Name, Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); } -void SDiagsWriter::AddLocToRecord(SourceLocation Loc, - const SourceManager *SM, - PresumedLoc PLoc, - RecordDataImpl &Record, - unsigned TokSize) { +void SDiagsWriter::AddLocToRecord(FullSourceLoc Loc, PresumedLoc PLoc, + RecordDataImpl &Record, unsigned TokSize) { if (PLoc.isInvalid()) { // Emit a "sentinel" location. Record.push_back((unsigned)0); // File. @@ -367,19 +352,19 @@ void SDiagsWriter::AddLocToRecord(SourceLocation Loc, Record.push_back(getEmitFile(PLoc.getFilename())); Record.push_back(PLoc.getLine()); Record.push_back(PLoc.getColumn()+TokSize); - Record.push_back(SM->getFileOffset(Loc)); + Record.push_back(Loc.getFileOffset()); } void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range, RecordDataImpl &Record, const SourceManager &SM) { - AddLocToRecord(Range.getBegin(), Record, &SM); + AddLocToRecord(FullSourceLoc(Range.getBegin(), SM), Record); unsigned TokSize = 0; if (Range.isTokenRange()) TokSize = Lexer::MeasureTokenLength(Range.getEnd(), SM, *LangOpts); - - AddLocToRecord(Range.getEnd(), Record, &SM, TokSize); + + AddLocToRecord(FullSourceLoc(Range.getEnd(), SM), Record, TokSize); } unsigned SDiagsWriter::getEmitFile(const char *FileName){ @@ -606,8 +591,8 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, if (DiagLevel == DiagnosticsEngine::Note) EnterDiagBlock(); - EmitDiagnosticMessage(SourceLocation(), PresumedLoc(), DiagLevel, - State->diagBuf, nullptr, &Info); + EmitDiagnosticMessage(FullSourceLoc(), PresumedLoc(), DiagLevel, + State->diagBuf, &Info); if (DiagLevel == DiagnosticsEngine::Note) ExitDiagBlock(); @@ -618,12 +603,9 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, assert(Info.hasSourceManager() && LangOpts && "Unexpected diagnostic with valid location outside of a source file"); SDiagsRenderer Renderer(*this, *LangOpts, &*State->DiagOpts); - Renderer.emitDiagnostic(Info.getLocation(), DiagLevel, - State->diagBuf, - Info.getRanges(), - Info.getFixItHints(), - &Info.getSourceManager(), - &Info); + Renderer.emitDiagnostic( + FullSourceLoc(Info.getLocation(), Info.getSourceManager()), DiagLevel, + State->diagBuf, Info.getRanges(), Info.getFixItHints(), &Info); } static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) { @@ -641,11 +623,9 @@ static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) { llvm_unreachable("invalid diagnostic level"); } -void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc, - PresumedLoc PLoc, +void SDiagsWriter::EmitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, - const SourceManager *SM, DiagOrStoredDiag D) { llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; @@ -655,7 +635,7 @@ void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc, Record.clear(); Record.push_back(RECORD_DIAG); Record.push_back(getStableLevel(Level)); - AddLocToRecord(Loc, SM, PLoc, Record); + AddLocToRecord(Loc, PLoc, Record); if (const Diagnostic *Info = D.dyn_cast()) { // Emit the category string lazily and get the category ID. @@ -672,15 +652,11 @@ void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc, Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Message); } -void -SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc, - PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, - ArrayRef Ranges, - const SourceManager *SM, - DiagOrStoredDiag D) { - Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, SM, D); +void SDiagsRenderer::emitDiagnosticMessage( + FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, + StringRef Message, ArrayRef Ranges, + DiagOrStoredDiag D) { + Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, D); } void SDiagsWriter::EnterDiagBlock() { @@ -733,20 +709,18 @@ void SDiagsWriter::EmitCodeContext(SmallVectorImpl &Ranges, } } -void SDiagsRenderer::emitCodeContext(SourceLocation Loc, +void SDiagsRenderer::emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl &Ranges, - ArrayRef Hints, - const SourceManager &SM) { - Writer.EmitCodeContext(Ranges, Hints, SM); + ArrayRef Hints) { + Writer.EmitCodeContext(Ranges, Hints, Loc.getManager()); } -void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message, - const SourceManager *SM) { +void SDiagsRenderer::emitNote(FullSourceLoc Loc, StringRef Message) { Writer.EnterDiagBlock(); - PresumedLoc PLoc = SM ? SM->getPresumedLoc(Loc) : PresumedLoc(); - Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note, - Message, SM, DiagOrStoredDiag()); + PresumedLoc PLoc = Loc.hasManager() ? Loc.getPresumedLoc() : PresumedLoc(); + Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note, Message, + DiagOrStoredDiag()); Writer.ExitDiagBlock(); } diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index a24d5768f558..1e12ea5e597a 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -672,20 +672,16 @@ TextDiagnostic::TextDiagnostic(raw_ostream &OS, TextDiagnostic::~TextDiagnostic() {} -void -TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc, - PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, - ArrayRef Ranges, - const SourceManager *SM, - DiagOrStoredDiag D) { +void TextDiagnostic::emitDiagnosticMessage( + FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, + StringRef Message, ArrayRef Ranges, + DiagOrStoredDiag D) { uint64_t StartOfLocationInfo = OS.tell(); // Emit the location of this particular diagnostic. if (Loc.isValid()) - emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM); - + emitDiagnosticLoc(Loc, PLoc, Level, Ranges); + if (DiagOpts->ShowColors) OS.resetColor(); @@ -787,17 +783,16 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) { /// This includes extracting as much location information as is present for /// the diagnostic and printing it, as well as any include stack or source /// ranges necessary. -void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, +void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) { + ArrayRef Ranges) { if (PLoc.isInvalid()) { // At least print the file name if available: - FileID FID = SM.getFileID(Loc); + FileID FID = Loc.getFileID(); if (FID.isValid()) { - const FileEntry* FE = SM.getFileEntryForID(FID); + const FileEntry *FE = Loc.getFileEntry(); if (FE && FE->isValid()) { - emitFilename(FE->getName(), SM); + emitFilename(FE->getName(), Loc.getManager()); if (FE->isInPCH()) OS << " (in PCH)"; OS << ": "; @@ -813,7 +808,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, if (DiagOpts->ShowColors) OS.changeColor(savedColor, true); - emitFilename(PLoc.getFilename(), SM); + emitFilename(PLoc.getFilename(), Loc.getManager()); switch (DiagOpts->getFormat()) { case DiagnosticOptions::Clang: OS << ':' << LineNo; break; case DiagnosticOptions::MSVC: OS << '(' << LineNo; break; @@ -848,8 +843,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, } if (DiagOpts->ShowSourceRanges && !Ranges.empty()) { - FileID CaretFileID = - SM.getFileID(SM.getExpansionLoc(Loc)); + FileID CaretFileID = Loc.getExpansionLoc().getFileID(); bool PrintedRange = false; for (ArrayRef::const_iterator RI = Ranges.begin(), @@ -858,8 +852,10 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, // Ignore invalid ranges. if (!RI->isValid()) continue; - SourceLocation B = SM.getExpansionLoc(RI->getBegin()); - SourceLocation E = SM.getExpansionLoc(RI->getEnd()); + FullSourceLoc B = + FullSourceLoc(RI->getBegin(), Loc.getManager()).getExpansionLoc(); + FullSourceLoc E = + FullSourceLoc(RI->getEnd(), Loc.getManager()).getExpansionLoc(); // If the End location and the start location are the same and are a // macro location, then the range was something that came from a @@ -867,10 +863,12 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, // best we can do is to highlight the range. If this is a // function-like macro, we'd also like to highlight the arguments. if (B == E && RI->getEnd().isMacroID()) - E = SM.getExpansionRange(RI->getEnd()).second; + E = FullSourceLoc(RI->getEnd(), Loc.getManager()) + .getExpansionRange() + .second; - std::pair BInfo = SM.getDecomposedLoc(B); - std::pair EInfo = SM.getDecomposedLoc(E); + std::pair BInfo = B.getDecomposedLoc(); + std::pair EInfo = E.getDecomposedLoc(); // If the start or end of the range is in another file, just discard // it. @@ -881,13 +879,10 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, // tokens. unsigned TokSize = 0; if (RI->isTokenRange()) - TokSize = Lexer::MeasureTokenLength(E, SM, LangOpts); + TokSize = Lexer::MeasureTokenLength(E, E.getManager(), LangOpts); - OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':' - << SM.getColumnNumber(BInfo.first, BInfo.second) << '-' - << SM.getLineNumber(EInfo.first, EInfo.second) << ':' - << (SM.getColumnNumber(EInfo.first, EInfo.second)+TokSize) - << '}'; + OS << '{' << B.getLineNumber() << ':' << B.getColumnNumber() << '-' + << E.getLineNumber() << ':' << (E.getColumnNumber() + TokSize) << '}'; PrintedRange = true; } @@ -897,9 +892,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, OS << ' '; } -void TextDiagnostic::emitIncludeLocation(SourceLocation Loc, - PresumedLoc PLoc, - const SourceManager &SM) { +void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) { if (DiagOpts->ShowLocation && PLoc.isValid()) OS << "In file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; @@ -907,9 +900,8 @@ void TextDiagnostic::emitIncludeLocation(SourceLocation Loc, OS << "In included file:\n"; } -void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) { +void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, + StringRef ModuleName) { if (DiagOpts->ShowLocation && PLoc.isValid()) OS << "In module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; @@ -917,10 +909,9 @@ void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, OS << "In module '" << ModuleName << "':\n"; } -void TextDiagnostic::emitBuildingModuleLocation(SourceLocation Loc, +void TextDiagnostic::emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName, - const SourceManager &SM) { + StringRef ModuleName) { if (DiagOpts->ShowLocation && PLoc.isValid()) OS << "While building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; @@ -1134,10 +1125,8 @@ static std::string buildFixItInsertionLine(unsigned LineNo, /// \param Ranges The underlined ranges for this code snippet. /// \param Hints The FixIt hints active for this diagnostic. void TextDiagnostic::emitSnippetAndCaret( - SourceLocation Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) { + FullSourceLoc Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl &Ranges, ArrayRef Hints) { assert(Loc.isValid() && "must have a valid source location here"); assert(Loc.isFileID() && "must have a file location here"); @@ -1154,18 +1143,18 @@ void TextDiagnostic::emitSnippetAndCaret( return; // Decompose the location into a FID/Offset pair. - std::pair LocInfo = SM.getDecomposedLoc(Loc); + std::pair LocInfo = Loc.getDecomposedLoc(); FileID FID = LocInfo.first; - unsigned CaretFileOffset = LocInfo.second; + const SourceManager &SM = Loc.getManager(); // Get information about the buffer it points into. bool Invalid = false; - StringRef BufData = SM.getBufferData(FID, &Invalid); + StringRef BufData = Loc.getBufferData(&Invalid); if (Invalid) return; - unsigned CaretLineNo = SM.getLineNumber(FID, CaretFileOffset); - unsigned CaretColNo = SM.getColumnNumber(FID, CaretFileOffset); + unsigned CaretLineNo = Loc.getLineNumber(); + unsigned CaretColNo = Loc.getColumnNumber(); // Arbitrarily stop showing snippets when the line is too long. static const size_t MaxLineLengthToPrint = 4096; diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 17646b48e23d..5dd3252d5b1e 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -150,10 +150,9 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, "Unexpected diagnostic with no source manager"); assert(TextDiag && "Unexpected diagnostic outside source file processing"); - TextDiag->emitDiagnostic(Info.getLocation(), Level, DiagMessageStream.str(), - Info.getRanges(), - Info.getFixItHints(), - &Info.getSourceManager()); + TextDiag->emitDiagnostic( + FullSourceLoc(Info.getLocation(), Info.getSourceManager()), Level, + DiagMessageStream.str(), Info.getRanges(), Info.getFixItHints()); OS.flush(); } diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp index de223d3043a3..4e47b25a4bf0 100644 --- a/tools/libclang/CIndexDiagnostic.cpp +++ b/tools/libclang/CIndexDiagnostic.cpp @@ -110,40 +110,34 @@ class CXDiagnosticRenderer : public DiagnosticNoteRenderer { CurrentSet = &CD.getChildDiagnostics(); } - void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, + void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, - const SourceManager *SM, DiagOrStoredDiag D) override { if (!D.isNull()) return; CXSourceLocation L; - if (SM) - L = translateSourceLocation(*SM, LangOpts, Loc); + if (Loc.hasManager()) + L = translateSourceLocation(Loc.getManager(), LangOpts, Loc); else L = clang_getNullLocation(); CurrentSet->appendDiagnostic( llvm::make_unique(Message, L)); } - void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, + void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) override {} + ArrayRef Ranges) override {} - void emitCodeContext(SourceLocation Loc, - DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) override {} + void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl &Ranges, + ArrayRef Hints) override {} - void emitNote(SourceLocation Loc, StringRef Message, - const SourceManager *SM) override { + void emitNote(FullSourceLoc Loc, StringRef Message) override { CXSourceLocation L; - if (SM) - L = translateSourceLocation(*SM, LangOpts, Loc); + if (Loc.hasManager()) + L = translateSourceLocation(Loc.getManager(), LangOpts, Loc); else L = clang_getNullLocation(); CurrentSet->appendDiagnostic( From 8be210b0a28c079aa07ffdb46d8e274bc9e4be70 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 27 Jun 2017 10:06:40 +0000 Subject: [PATCH 085/214] [clang-format] Add a test for associative map proto buffer fields Summary: The test suite was missing a test about associative maps: https://developers.google.com/protocol-buffers/docs/proto3#maps Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34623 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306386 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Format/FormatTestProto.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index d174c65a1f32..3f690c369bab 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -61,6 +61,29 @@ TEST_F(FormatTestProto, FormatsMessages) { " really.really.long.qualified.type.aaa.aaaaaaa.aaaaaaaa\n" " another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n" "}"); + verifyFormat("message SomeMessage {\n" + " map projects = 1;\n" + " optional map size_projects = 2;\n" + " map\n" + " projects = 3;\n" + " map projects = 4;\n" + " map\n" + " projects = 5;\n" + " map\n" + " longlonglonglonglonglonglonglonglonglongonglon = 6;\n" + " map projects = 7;\n" + " map\n" + " releleallyreallyreallyreallyreallyreallyreallylongnam =\n" + " 8;\n" + " map projects = 9;\n" + "}"); } TEST_F(FormatTestProto, KeywordsInOtherLanguages) { From 2d10542533756f8346b0d925f4af29e7d065c572 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 27 Jun 2017 10:35:30 +0000 Subject: [PATCH 086/214] Recommit r306103: PR26195: Set correct NestedNameSpecifierLoc for the dependent initializer This commit fixes incorrect source positions of dependent c'tor initializers like in the following code: template struct Derived: MyBase::InnerIterator { Derived() : MyBase::InnerIterator() {} /// This line is problematic: all positions point to InnerIterator and nothing points to MyBase }; Patch by Serge Preis! Differential Revision: https://reviews.llvm.org/D32439 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306392 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 9 +++ test/Index/ctor-init-source-loc.cpp | 117 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 test/Index/ctor-init-source-loc.cpp diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 453ece9d9c4d..e9070881afe4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3778,6 +3778,15 @@ Sema::BuildMemInitializer(Decl *ConstructorD, if (BaseType.isNull()) return true; + TInfo = Context.CreateTypeSourceInfo(BaseType); + DependentNameTypeLoc TL = + TInfo->getTypeLoc().castAs(); + if (!TL.isNull()) { + TL.setNameLoc(IdLoc); + TL.setElaboratedKeywordLoc(SourceLocation()); + TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } + R.clear(); R.setLookupName(MemberOrBase); } diff --git a/test/Index/ctor-init-source-loc.cpp b/test/Index/ctor-init-source-loc.cpp new file mode 100644 index 000000000000..ff93e58092da --- /dev/null +++ b/test/Index/ctor-init-source-loc.cpp @@ -0,0 +1,117 @@ +// RUN: c-index-test -test-load-source all %s -fno-delayed-template-parsing | FileCheck %s +template +struct Derived: MyBase::InnerIterator +{ + Derived() : MyBase::InnerIterator() {} +// CHECK: TypeRef=MyBase:2:19 Extent=[5:17 - 5:23] +}; + +template +struct Derived2: MyBase::Deeper::InnerIterator +{ + Derived2() : MyBase::Deeper::InnerIterator() {} +// CHECK: TypeRef=MyBase:9:19 Extent=[12:18 - 12:24] +}; + +template +struct Templ; + +template +struct Derived3: Templ::InnerIterator +{ + Derived3() : Templ::InnerIterator() {} +// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23] +// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30] +}; + + +struct Outer { + template + struct Inner { + typedef Q Parm; + }; +}; + +template +struct Derived4: Outer::Inner::Parm +{ + Derived4() : Outer::Inner::Parm() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30] +// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32] +}; + +template +struct Derived5: Outer::Inner::Parm::InnerIterator +{ + Derived5() : Outer::Inner::Parm::InnerIterator() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30] +// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32] +}; + +template +struct Derived6: Outer::Inner +{ + Derived6() : Outer::Inner() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30] +// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32] +}; + +struct Base {}; + +struct Derived7: Outer::Inner::Parm +{ + Derived7() : Outer::Inner::Parm() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30] +// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35] +}; + +struct Derived8: Outer::Inner +{ + Derived8() : Outer::Inner() {} +// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23] +// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30] +// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35] +}; + +namespace Namespace { + template struct Templ; + + struct Outer { + template + struct Inner { + typedef Q Parm; + }; + }; +} + +template +struct Derived9: Namespace::Templ::InnerIterator +{ + Derived9() : Namespace::Templ::InnerIterator() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27] +// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34] +// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41] +}; + +template +struct Derived10: Namespace::Templ +{ + Derived10() : Namespace::Templ() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28] +// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35] +// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42] +}; + +template +struct Derived11: Namespace::Outer::Inner::Parm +{ + Derived11() : Namespace::Outer::Inner::Parm() {} +// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28] +// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35] +// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42] +// CHECK: TypeRef=MyBase:109:19 Extent=[112:43 - 112:49] +}; From 7a2b28407501faafdbd0c3c6785895e49d13d514 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 27 Jun 2017 11:14:39 +0000 Subject: [PATCH 087/214] [analyzer] Move zero-size allocation checks to optin.portability. This is a new checker package. It contains checkers that highlight well-documented implementation-defined behavior. Such checkers are only useful to developers that intend to write portable code. Code that is only compiled for a single platform should be allowed to rely on this platform's specific documented behavior. rdar://problem/30545046 Differential Revision: https://reviews.llvm.org/D34102 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306396 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/StaticAnalyzer/Checkers/Checkers.td | 18 +++++- .../Checkers/UnixAPIChecker.cpp | 55 ++++++++++++------- test/Analysis/malloc-overflow2.c | 6 +- test/Analysis/unix-fns.c | 4 +- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/include/clang/StaticAnalyzer/Checkers/Checkers.td b/include/clang/StaticAnalyzer/Checkers/Checkers.td index 4171c685cb98..82ab720af8dc 100644 --- a/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -38,6 +38,11 @@ def CoreAlpha : Package<"core">, InPackage, Hidden; // default. Such checkers belong in the alpha package. def OptIn : Package<"optin">; +// In the Portability package reside checkers for finding code that relies on +// implementation-defined behavior. Such checks are wanted for cross-platform +// development, but unwanted for developers who target only a single platform. +def PortabilityOptIn : Package<"portability">, InPackage; + def Nullability : Package<"nullability">; def Cplusplus : Package<"cplusplus">; @@ -416,7 +421,7 @@ def GenericTaintChecker : Checker<"TaintPropagation">, let ParentPackage = Unix in { -def UnixAPIChecker : Checker<"API">, +def UnixAPIMisuseChecker : Checker<"API">, HelpText<"Check calls to various UNIX/Posix functions">, DescFile<"UnixAPIChecker.cpp">; @@ -754,3 +759,14 @@ def CloneChecker : Checker<"CloneChecker">, } // end "clone" +//===----------------------------------------------------------------------===// +// Portability checkers. +//===----------------------------------------------------------------------===// + +let ParentPackage = PortabilityOptIn in { + +def UnixAPIPortabilityChecker : Checker<"UnixAPI">, + HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">, + DescFile<"UnixAPIChecker.cpp">; + +} // end optin.portability diff --git a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp index 26bf597bd950..7f9a00ff876d 100644 --- a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp @@ -45,6 +45,8 @@ class UnixAPIChecker : public Checker< check::PreStmt > { mutable Optional Val_O_CREAT; public: + DefaultBool CheckMisuse, CheckPortability; + void checkPreStmt(const CallExpr *CE, CheckerContext &C) const; void CheckOpen(CheckerContext &C, const CallExpr *CE) const; @@ -437,29 +439,42 @@ void UnixAPIChecker::checkPreStmt(const CallExpr *CE, if (FName.empty()) return; - SubChecker SC = - llvm::StringSwitch(FName) - .Case("open", &UnixAPIChecker::CheckOpen) - .Case("openat", &UnixAPIChecker::CheckOpenAt) - .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce) - .Case("calloc", &UnixAPIChecker::CheckCallocZero) - .Case("malloc", &UnixAPIChecker::CheckMallocZero) - .Case("realloc", &UnixAPIChecker::CheckReallocZero) - .Case("reallocf", &UnixAPIChecker::CheckReallocfZero) - .Cases("alloca", "__builtin_alloca", &UnixAPIChecker::CheckAllocaZero) - .Case("__builtin_alloca_with_align", - &UnixAPIChecker::CheckAllocaWithAlignZero) - .Case("valloc", &UnixAPIChecker::CheckVallocZero) - .Default(nullptr); - - if (SC) - (this->*SC)(C, CE); + if (CheckMisuse) { + if (SubChecker SC = + llvm::StringSwitch(FName) + .Case("open", &UnixAPIChecker::CheckOpen) + .Case("openat", &UnixAPIChecker::CheckOpenAt) + .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce) + .Default(nullptr)) { + (this->*SC)(C, CE); + } + } + if (CheckPortability) { + if (SubChecker SC = + llvm::StringSwitch(FName) + .Case("calloc", &UnixAPIChecker::CheckCallocZero) + .Case("malloc", &UnixAPIChecker::CheckMallocZero) + .Case("realloc", &UnixAPIChecker::CheckReallocZero) + .Case("reallocf", &UnixAPIChecker::CheckReallocfZero) + .Cases("alloca", "__builtin_alloca", + &UnixAPIChecker::CheckAllocaZero) + .Case("__builtin_alloca_with_align", + &UnixAPIChecker::CheckAllocaWithAlignZero) + .Case("valloc", &UnixAPIChecker::CheckVallocZero) + .Default(nullptr)) { + (this->*SC)(C, CE); + } + } } //===----------------------------------------------------------------------===// // Registration. //===----------------------------------------------------------------------===// -void ento::registerUnixAPIChecker(CheckerManager &mgr) { - mgr.registerChecker(); -} +#define REGISTER_CHECKER(Name) \ + void ento::registerUnixAPI##Name##Checker(CheckerManager &mgr) { \ + mgr.registerChecker()->Check##Name = true; \ + } + +REGISTER_CHECKER(Misuse) +REGISTER_CHECKER(Portability) diff --git a/test/Analysis/malloc-overflow2.c b/test/Analysis/malloc-overflow2.c index 2e1b1d4d2b24..7c580602e682 100644 --- a/test/Analysis/malloc-overflow2.c +++ b/test/Analysis/malloc-overflow2.c @@ -1,4 +1,5 @@ // RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix -verify %s +// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix,optin.portability -DPORTABILITY -verify %s typedef __typeof__(sizeof(int)) size_t; extern void *malloc(size_t); @@ -32,5 +33,8 @@ static int table_build_1(struct table *t) { } void *f(int n) { - return malloc(n * 0 * sizeof(int)); // expected-warning {{Call to 'malloc' has an allocation size of 0 bytes}} + return malloc(n * 0 * sizeof(int)); +#ifdef PORTABILITY + // expected-warning@-2{{Call to 'malloc' has an allocation size of 0 bytes}} +#endif } diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c index 3eccd51d2c60..481f545e28bc 100644 --- a/test/Analysis/unix-fns.c +++ b/test/Analysis/unix-fns.c @@ -1,7 +1,7 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,unix.API,osx.API %s -analyzer-store=region -analyzer-output=plist -analyzer-eagerly-assume -analyzer-config faux-bodies=true -analyzer-config path-diagnostics-alternate=false -fblocks -verify -o %t.plist +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,unix.API,osx.API,optin.portability %s -analyzer-store=region -analyzer-output=plist -analyzer-eagerly-assume -analyzer-config faux-bodies=true -analyzer-config path-diagnostics-alternate=false -fblocks -verify -o %t.plist // RUN: FileCheck --input-file=%t.plist %s // RUN: mkdir -p %t.dir -// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API,osx.API -analyzer-output=html -analyzer-config faux-bodies=true -fblocks -o %t.dir %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API,osx.API,optin.portability -analyzer-output=html -analyzer-config faux-bodies=true -fblocks -o %t.dir %s // RUN: rm -fR %t.dir struct _opaque_pthread_once_t { long __sig; From ace84ec3ef5538e6249e57961324448552b80f40 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 27 Jun 2017 13:43:07 +0000 Subject: [PATCH 088/214] [clang-format] Support <>-style proto message fields Summary: This patch adds support for <>-style proto message fields inside proto options. Previously these were wrongly treated as binary operators and as such were working only by chance for a limited number of cases. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34621 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306406 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 20 +++- lib/Format/FormatToken.h | 3 +- lib/Format/TokenAnnotator.cpp | 25 ++++- lib/Format/UnwrappedLineParser.cpp | 16 ++-- lib/Format/UnwrappedLineParser.h | 3 +- unittests/Format/FormatTestProto.cpp | 136 +++++++++++++++++++++++++++ 6 files changed, 188 insertions(+), 15 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index cca773cfe3cb..92c8ad835adc 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -56,6 +56,8 @@ static bool startsNextParameter(const FormatToken &Current, if (Current.is(TT_CtorInitializerComma) && Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) return true; + if (Style.Language == FormatStyle::LK_Proto && Current.is(TT_SelectorName)) + return true; return Previous.is(tok::comma) && !Current.isTrailingComment() && ((Previous.isNot(TT_CtorInitializerComma) || Style.BreakConstructorInitializers != @@ -499,6 +501,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, } } +static bool lessOpensProtoMessageField(const FormatToken &LessTok, + const LineState &State) { + assert(LessTok.is(tok::less)); + return LessTok.NestingLevel > 0 || + (LessTok.Previous && LessTok.Previous->is(tok::equal)); +} + unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, bool DryRun) { FormatToken &Current = *State.NextToken; @@ -641,6 +650,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, // before the corresponding } or ]. if (PreviousNonComment && (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || + (Style.Language == FormatStyle::LK_Proto && + PreviousNonComment->is(tok::less) && + lessOpensProtoMessageField(*PreviousNonComment, State)) || (PreviousNonComment->is(TT_TemplateString) && PreviousNonComment->opensScope()))) State.Stack.back().BreakBeforeClosingBrace = true; @@ -682,7 +694,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == BK_Block) return Current.NestingLevel == 0 ? State.FirstIndent : State.Stack.back().Indent; - if (Current.isOneOf(tok::r_brace, tok::r_square) && State.Stack.size() > 1) { + if ((Current.isOneOf(tok::r_brace, tok::r_square) || + (Current.is(tok::greater) && Style.Language == FormatStyle::LK_Proto)) && + State.Stack.size() > 1) { if (Current.closesBlockOrBlockTypeList(Style)) return State.Stack[State.Stack.size() - 2].NestedBlockIndent; if (Current.MatchingParen && @@ -1035,7 +1049,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, bool BreakBeforeParameter = false; unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall, State.Stack.back().NestedBlockIndent); - if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) { + if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || + (Style.Language == FormatStyle::LK_Proto && Current.is(tok::less) && + lessOpensProtoMessageField(Current, State))) { if (Current.opensBlockOrBlockTypeList(Style)) { NewIndent = Style.IndentWidth + std::min(State.Column, State.Stack.back().NestedBlockIndent); diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index c5bf48cdcc06..ddec578f89ae 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -465,7 +465,8 @@ struct FormatToken { return is(TT_ArrayInitializerLSquare) || (is(tok::l_brace) && (BlockKind == BK_Block || is(TT_DictLiteral) || - (!Style.Cpp11BracedListStyle && NestingLevel == 0))); + (!Style.Cpp11BracedListStyle && NestingLevel == 0))) || + (is(tok::less) && Style.Language == FormatStyle::LK_Proto); } /// \brief Same as opensBlockOrBlockTypeList, but for the closing token. diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 505f42ec9a06..767096b60ef2 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -89,7 +89,8 @@ class AnnotatingParser { continue; } if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace) || - (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext)) + (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext && + Style.Language != FormatStyle::LK_Proto)) return false; // If a && or || is found and interpreted as a binary operator, this set // of angles is likely part of something like "a < b && c > d". If the @@ -103,6 +104,14 @@ class AnnotatingParser { !Line.startsWith(tok::kw_template)) return false; updateParameterCount(Left, CurrentToken); + if (Style.Language == FormatStyle::LK_Proto) { + if (FormatToken *Previous = CurrentToken->getPreviousNonComment()) { + if (CurrentToken->is(tok::colon) || + (CurrentToken->isOneOf(tok::l_brace, tok::less) && + Previous->isNot(tok::colon))) + Previous->Type = TT_SelectorName; + } + } if (!consumeToken()) return false; } @@ -440,7 +449,7 @@ class AnnotatingParser { if (CurrentToken->isOneOf(tok::r_paren, tok::r_square)) return false; updateParameterCount(Left, CurrentToken); - if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) { + if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) { FormatToken *Previous = CurrentToken->getPreviousNonComment(); if (((CurrentToken->is(tok::colon) && (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) || @@ -2549,10 +2558,16 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, // deliberate choice and might have aligned the contents of the string // literal accordingly. Thus, we try keep existing line breaks. return Right.NewlinesBefore > 0; - if (Right.Previous->is(tok::l_brace) && Right.NestingLevel == 1 && - Style.Language == FormatStyle::LK_Proto) - // Don't put enums onto single lines in protocol buffers. + if ((Right.Previous->is(tok::l_brace) || + (Right.Previous->is(tok::less) && + Right.Previous->Previous && + Right.Previous->Previous->is(tok::equal)) + ) && + Right.NestingLevel == 1 && Style.Language == FormatStyle::LK_Proto) { + // Don't put enums or option definitions onto single lines in protocol + // buffers. return true; + } if (Right.is(TT_InlineASMBrace)) return Right.HasUnescapedNewline; if (isAllmanBrace(Left) || isAllmanBrace(Right)) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index f7678bb6b2a5..261ae3030d9a 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1176,9 +1176,11 @@ void UnwrappedLineParser::parseStructuralElement() { } nextToken(); - if (FormatTok->Tok.is(tok::l_brace)) { + if (FormatTok->Tok.is(tok::l_brace)) parseBracedList(); - } + else if (Style.Language == FormatStyle::LK_Proto && + FormatTok->Tok.is(tok::less)) + parseBracedList(/*ClosingBraceKind=*/tok::greater); break; case tok::l_square: parseSquare(); @@ -1346,7 +1348,8 @@ bool UnwrappedLineParser::tryToParseBracedList() { return true; } -bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { +bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons, + tok::TokenKind ClosingBraceKind) { bool HasError = false; nextToken(); @@ -1375,6 +1378,10 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { parseChildBlock(); } } + if (FormatTok->Tok.getKind() == ClosingBraceKind) { + nextToken(); + return !HasError; + } switch (FormatTok->Tok.getKind()) { case tok::caret: nextToken(); @@ -1401,9 +1408,6 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { FormatTok->BlockKind = BK_BracedInit; parseBracedList(); break; - case tok::r_brace: - nextToken(); - return !HasError; case tok::semi: // JavaScript (or more precisely TypeScript) can have semicolons in braced // lists (in so-called TypeMemberLists). Thus, the semicolon cannot be diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index 15d1d9cda7a2..a2aa2f006728 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -93,7 +93,8 @@ class UnwrappedLineParser { void readTokenWithJavaScriptASI(); void parseStructuralElement(); bool tryToParseBracedList(); - bool parseBracedList(bool ContinueOnSemicolons = false); + bool parseBracedList(bool ContinueOnSemicolons = false, + tok::TokenKind ClosingBraceKind = tok::r_brace); void parseParens(); void parseSquare(); void parseIfThenElse(); diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 3f690c369bab..0b052bd4c649 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -207,6 +207,142 @@ TEST_F(FormatTestProto, FormatsOptions) { " field_c: \"OK\",\n" " msg_field: \n" "};"); + + verifyFormat("option (MyProto.options) = {\n" + " msg_field: <>\n" + " field_c: \"OK\",\n" + " msg_field: \n" + " field_e: OK\n" + " msg_field: \n" + "};"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: OK\n" + " field_b: \"OK\"\n" + " field_c: 1\n" + " field_d: 12.5\n" + " field_e: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: OK,\n" + " field_b: \"OK\",\n" + " field_c: 1,\n" + " field_d: 12.5,\n" + " field_e: OK,\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field: {field_b: OK}\n" + " field_g: OK\n" + " field_g: OK\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field<\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " >\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field<\n" + " field_b: OK,\n" + " field_c: OK,\n" + " field_d: OK,\n" + " field_e: OK,\n" + " field_f: OK\n" + " >\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field: <\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " >\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field: {\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " }\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field{\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " }\n" + " field_g: OK\n" + ">;"); + + verifyFormat("option (MyProto.options) = {\n" + " field_a: \"OK\"\n" + " msg_field<\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " >\n" + " field_g: OK\n" + "};"); + + verifyFormat("option (MyProto.options) = {\n" + " field_a: \"OK\"\n" + " msg_field: <\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " field_e: OK\n" + " field_f: OK\n" + " >\n" + " field_g: OK\n" + "};"); + + verifyFormat("option (MyProto.options) = <\n" + " field_a: \"OK\"\n" + " msg_field{\n" + " field_b: OK\n" + " field_c: OK\n" + " field_d: OK\n" + " msg_field<\n" + " field_A: 1\n" + " field_B: 2\n" + " field_C: 3\n" + " field_D: 4\n" + " field_E: 5\n" + " >\n" + " msg_field\n" + " field_e: OK\n" + " field_f: OK\n" + " }\n" + " field_g: OK\n" + ">;"); } TEST_F(FormatTestProto, FormatsService) { From 2f35ace32588a824d065275d7774ffac1d9b91ea Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 27 Jun 2017 13:58:41 +0000 Subject: [PATCH 089/214] [clang-format] Fix a buildbot failure after r306406 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306408 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 261ae3030d9a..ba3a4c17ee12 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1180,7 +1180,8 @@ void UnwrappedLineParser::parseStructuralElement() { parseBracedList(); else if (Style.Language == FormatStyle::LK_Proto && FormatTok->Tok.is(tok::less)) - parseBracedList(/*ClosingBraceKind=*/tok::greater); + parseBracedList(/*ContinueOnSemicolons=*/false, + /*ClosingBraceKind=*/tok::greater); break; case tok::l_square: parseSquare(); From c18c00d5695bfdf63e28b05af2e26cd324891ef5 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 27 Jun 2017 14:07:45 +0000 Subject: [PATCH 090/214] [clang-format] Fix a clang-tidy warning, NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306409 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/NamespaceEndCommentsFixer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Format/NamespaceEndCommentsFixer.cpp b/lib/Format/NamespaceEndCommentsFixer.cpp index 1bbb41f757ae..85b70b8c0a76 100644 --- a/lib/Format/NamespaceEndCommentsFixer.cpp +++ b/lib/Format/NamespaceEndCommentsFixer.cpp @@ -174,7 +174,7 @@ tooling::Replacements NamespaceEndCommentsFixer::analyze( AllNamespaceNames = "::" + NamespaceName + AllNamespaceNames; continue; } - NamespaceName += std::move(AllNamespaceNames); + NamespaceName += AllNamespaceNames; CompactedNamespacesCount = 0; AllNamespaceNames = std::string(); } From 5a17e5c7708b05af7c45fe8dd1c5dca14f00b608 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 27 Jun 2017 15:46:42 +0000 Subject: [PATCH 091/214] [OPENMP] Use MapVector instead of DenseMap for stable codegen, NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306419 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/OpenMPClause.h | 3 ++- lib/CodeGen/CGOpenMPRuntime.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index f977e63e04f6..14e73819f53d 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -20,6 +20,7 @@ #include "clang/AST/Stmt.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/MapVector.h" namespace clang { @@ -3001,7 +3002,7 @@ class OMPMappableExprListClause : public OMPVarListClause, // Organize the components by declaration and retrieve the original // expression. Original expressions are always the first component of the // mappable component list. - llvm::DenseMap> + llvm::MapVector> ComponentListMap; { auto CI = ComponentLists.begin(); diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 8d83255ac139..0a8fd17c3324 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -5603,7 +5603,7 @@ class MappableExprsHandler { // We have to process the component lists that relate with the same // declaration in a single chunk so that we can generate the map flags // correctly. Therefore, we organize all lists in a map. - llvm::DenseMap> Info; + llvm::MapVector> Info; // Helper function to fill the information map for the different supported // clauses. From 086ae87da44ebbbad6203a615f3ce797118bfae6 Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Tue, 27 Jun 2017 17:23:42 +0000 Subject: [PATCH 092/214] Update test for enabling ICP for AutoFDO. Summary: This is the test update patch for https://reviews.llvm.org/D34662 Reviewers: davidxl Reviewed By: davidxl Subscribers: cfe-commits, sanjoy, mehdi_amini, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D34663 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306430 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/pgo-sample-thinlto-summary.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CodeGen/pgo-sample-thinlto-summary.c b/test/CodeGen/pgo-sample-thinlto-summary.c index 7782aeb76616..65d2f0dd987c 100644 --- a/test/CodeGen/pgo-sample-thinlto-summary.c +++ b/test/CodeGen/pgo-sample-thinlto-summary.c @@ -32,10 +32,10 @@ void unroll() { baz(i); } -// Check that icp is not invoked (both -O2 and ThinLTO). +// Check that icp is not invoked for ThinLTO, but invoked for -O2. // O2-LABEL: define void @icp // THINLTO-LABEL: define void @icp -// O2-NOT: if.true.direct_targ +// O2: if.true.direct_targ // ThinLTO-NOT: if.true.direct_targ void icp(void (*p)()) { p(); From 4b751f5fa60399dadac627a9943e7b24aa42561f Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 27 Jun 2017 17:39:46 +0000 Subject: [PATCH 093/214] [x86] weaken test checks that shouldn't be here in the first place This test would fail after the proposed change in: https://reviews.llvm.org/D34242 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306433 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/avx512f-builtins.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/CodeGen/avx512f-builtins.c b/test/CodeGen/avx512f-builtins.c index c66d83611ed1..c3356461a348 100644 --- a/test/CodeGen/avx512f-builtins.c +++ b/test/CodeGen/avx512f-builtins.c @@ -1,4 +1,7 @@ // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s + +// FIXME: It's wrong to check LLVM IR transformations from clang. This run should be removed and tests added to the appropriate LLVM pass. + // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -O2 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=O2 #include @@ -8240,10 +8243,10 @@ __m128 test_mm_mask_move_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B) { // O2-LABEL: @test_mm_mask_move_ss // O2: %[[M:.*]] = and i8 %__U, 1 - // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0 - // O2: %[[ELM1:.*]] = extractelement <4 x float> %__B, i32 0 - // O2: %[[ELM2:.*]] = extractelement <4 x float> %__W, i32 0 - // O2: %[[SEL:.*]] = select i1 %[[M2]], float %[[ELM1]], float %[[ELM2]] + // O2: %[[M2:.*]] = icmp + // O2: %[[ELM1:.*]] = extractelement <4 x float> + // O2: %[[ELM2:.*]] = extractelement <4 x float> + // O2: %[[SEL:.*]] = select i1 %[[M2]] // O2: %[[RES:.*]] = insertelement <4 x float> %__A, float %[[SEL]], i32 0 // O2: ret <4 x float> %[[RES]] return _mm_mask_move_ss ( __W, __U, __A, __B); @@ -8253,9 +8256,9 @@ __m128 test_mm_maskz_move_ss (__mmask8 __U, __m128 __A, __m128 __B) { // O2-LABEL: @test_mm_maskz_move_ss // O2: %[[M:.*]] = and i8 %__U, 1 - // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0 + // O2: %[[M2:.*]] = icmp // O2: %[[ELM1:.*]] = extractelement <4 x float> %__B, i32 0 - // O2: %[[SEL:.*]] = select i1 %[[M2]], float %[[ELM1]], float 0.0 + // O2: %[[SEL:.*]] = select i1 %[[M2]] // O2: %[[RES:.*]] = insertelement <4 x float> %__A, float %[[SEL]], i32 0 // O2: ret <4 x float> %[[RES]] return _mm_maskz_move_ss (__U, __A, __B); @@ -8265,10 +8268,10 @@ __m128d test_mm_mask_move_sd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __ { // O2-LABEL: @test_mm_mask_move_sd // O2: %[[M:.*]] = and i8 %__U, 1 - // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0 - // O2: %[[ELM1:.*]] = extractelement <2 x double> %__B, i32 0 - // O2: %[[ELM2:.*]] = extractelement <2 x double> %__W, i32 0 - // O2: %[[SEL:.*]] = select i1 %[[M2]], double %[[ELM1]], double %[[ELM2]] + // O2: %[[M2:.*]] = icmp + // O2: %[[ELM1:.*]] = extractelement <2 x double> + // O2: %[[ELM2:.*]] = extractelement <2 x double> + // O2: %[[SEL:.*]] = select i1 %[[M2]] // O2: %[[RES:.*]] = insertelement <2 x double> %__A, double %[[SEL]], i32 0 // O2: ret <2 x double> %[[RES]] return _mm_mask_move_sd ( __W, __U, __A, __B); @@ -8278,9 +8281,9 @@ __m128d test_mm_maskz_move_sd (__mmask8 __U, __m128d __A, __m128d __B) { // O2-LABEL: @test_mm_maskz_move_sd // O2: %[[M:.*]] = and i8 %__U, 1 - // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0 + // O2: %[[M2:.*]] = icmp // O2: %[[ELM1:.*]] = extractelement <2 x double> %__B, i32 0 - // O2: %[[SEL:.*]] = select i1 %[[M2]], double %[[ELM1]], double 0.0 + // O2: %[[SEL:.*]] = select i1 %[[M2]] // O2: %[[RES:.*]] = insertelement <2 x double> %__A, double %[[SEL]], i32 0 // O2: ret <2 x double> %[[RES]] return _mm_maskz_move_sd (__U, __A, __B); From dcdc5a7d3cbec7c4e0aaccf9e2adfa9c4ae66b4a Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Tue, 27 Jun 2017 17:45:40 +0000 Subject: [PATCH 094/214] Update the test comment to clarify the intention of the test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306434 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/pgo-sample-thinlto-summary.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/CodeGen/pgo-sample-thinlto-summary.c b/test/CodeGen/pgo-sample-thinlto-summary.c index 65d2f0dd987c..d64de536e184 100644 --- a/test/CodeGen/pgo-sample-thinlto-summary.c +++ b/test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=O2 +// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. @@ -11,9 +11,9 @@ void foo(int n) { g += baz(i); } -// O2-LABEL: define void @bar +// SAMPLEPGO-LABEL: define void @bar // THINLTO-LABEL: define void @bar -// O2-NOT: call{{.*}}foo +// SAMPLEPGO-NOT: call{{.*}}foo // THINLTO: call{{.*}}foo void bar(int n) { for (int i = 0; i < n; i++) @@ -21,10 +21,10 @@ void bar(int n) { } // Checks if loop unroll is invoked by normal compile, but not thinlto compile. -// O2-LABEL: define void @unroll +// SAMPLEPGO-LABEL: define void @unroll // THINLTO-LABEL: define void @unroll -// O2: call{{.*}}baz -// O2: call{{.*}}baz +// SAMPLEPGO: call{{.*}}baz +// SAMPLEPGO: call{{.*}}baz // THINLTO: call{{.*}}baz // THINLTO-NOT: call{{.*}}baz void unroll() { @@ -32,10 +32,10 @@ void unroll() { baz(i); } -// Check that icp is not invoked for ThinLTO, but invoked for -O2. -// O2-LABEL: define void @icp +// Checks that icp is not invoked for ThinLTO, but invoked for normal samplepgo. +// SAMPLEPGO-LABEL: define void @icp // THINLTO-LABEL: define void @icp -// O2: if.true.direct_targ +// SAMPLEPGO: if.true.direct_targ // ThinLTO-NOT: if.true.direct_targ void icp(void (*p)()) { p(); From 004e95174d0161ba92ca7e0f055462a2aeef05fa Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 27 Jun 2017 18:37:51 +0000 Subject: [PATCH 095/214] CodeGen: load indirect ObjC ARC arguments in prologue When generating a prologue, add loads for ARC arguments passed indirectly. Patch by Dave Lee! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306444 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDecl.cpp | 4 ++++ test/CodeGenObjCXX/arc-indirect.mm | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/CodeGenObjCXX/arc-indirect.mm diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index ccd3b8d513b1..4b656ea4a879 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -1860,6 +1860,10 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg, lt = Qualifiers::OCL_ExplicitNone; } + // Load objects passed indirectly. + if (Arg.isIndirect() && !ArgVal) + ArgVal = Builder.CreateLoad(DeclPtr); + if (lt == Qualifiers::OCL_Strong) { if (!isConsumed) { if (CGM.getCodeGenOpts().OptimizationLevel == 0) { diff --git a/test/CodeGenObjCXX/arc-indirect.mm b/test/CodeGenObjCXX/arc-indirect.mm new file mode 100644 index 000000000000..2684e82e2e37 --- /dev/null +++ b/test/CodeGenObjCXX/arc-indirect.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=gnustep -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-GNUSTEP %s +// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=macosx -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-DARWIN %s +// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=ios -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-DARWIN %s + +// non trivially copyable, forces inalloca +struct S { + S(const S &s) {} +}; + +@interface C +@end +@implementation C +- (void)object:(id)obj struct:(S)s { +} +@end + +// CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca) +// CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca) +// CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2 +// CHECK: %1 = load i8*, i8** %obj, align 4 +// CHECK: call void @objc_storeStrong(i8** %obj, i8* %1) From f255da2ab7a0fd98b7d34b160e640c96cce25560 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 27 Jun 2017 18:57:50 +0000 Subject: [PATCH 096/214] test: fix test for release builds Use a regex capture to avoid hardcoding the name. This should repair the failing buildbot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306447 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGenObjCXX/arc-indirect.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/CodeGenObjCXX/arc-indirect.mm b/test/CodeGenObjCXX/arc-indirect.mm index 2684e82e2e37..6982bac04118 100644 --- a/test/CodeGenObjCXX/arc-indirect.mm +++ b/test/CodeGenObjCXX/arc-indirect.mm @@ -9,6 +9,7 @@ @interface C @end + @implementation C - (void)object:(id)obj struct:(S)s { } @@ -17,5 +18,5 @@ - (void)object:(id)obj struct:(S)s { // CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca) // CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca) // CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2 -// CHECK: %1 = load i8*, i8** %obj, align 4 -// CHECK: call void @objc_storeStrong(i8** %obj, i8* %1) +// CHECK: %[[INSTANCE:[0-9]+]] = load i8*, i8** %obj, align 4 +// CHECK: call void @objc_storeStrong(i8** %obj, i8* %[[INSTANCE]]) From 563c0ec65e052e93085d4e3b7fede21da5ea768f Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 27 Jun 2017 21:31:31 +0000 Subject: [PATCH 097/214] [Sema] Allow unmarked overloadable functions. This patch extends the `overloadable` attribute to allow for one function with a given name to not be marked with the `overloadable` attribute. The overload without the `overloadable` attribute will not have its name mangled. So, the following code is now legal: void foo(void) __attribute__((overloadable)); void foo(int); void foo(float) __attribute__((overloadable)); In addition, this patch fixes a bug where we'd accept code with `__attribute__((overloadable))` inconsistently applied. In other words, we used to accept: void foo(void); void foo(void) __attribute__((overloadable)); But we will do this no longer, since it defeats the original purpose of requiring `__attribute__((overloadable))` on all redeclarations of a function. This breakage seems to not be an issue in practice, since the only code I could find that had this pattern often looked like: void foo(void); void foo(void) __attribute__((overloadable)) __asm__("foo"); void foo(int) __attribute__((overloadable)); ...Which can now be simplified by simply removing the asm label and overloadable attribute from the redeclaration of `void foo(void);` Differential Revision: https://reviews.llvm.org/D32332 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306467 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/AttrDocs.td | 40 +++++++-- include/clang/Basic/DiagnosticSemaKinds.td | 10 ++- lib/Lex/PPMacroExpansion.cpp | 2 + lib/Sema/SemaDecl.cpp | 93 ++++++++++++++----- test/CodeGen/mangle-ms.c | 9 ++ test/CodeGen/mangle.c | 4 + test/CodeGenCXX/mangle-ms.cpp | 7 ++ test/PCH/attrs.c | 3 +- test/Sema/overloadable.c | 100 +++++++++++++++++++-- 9 files changed, 224 insertions(+), 44 deletions(-) diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td index 65dd7445ba26..2987f07d8bb4 100644 --- a/include/clang/Basic/AttrDocs.td +++ b/include/clang/Basic/AttrDocs.td @@ -605,20 +605,27 @@ semantics: for ``T`` and ``U`` to be incompatible. The declaration of ``overloadable`` functions is restricted to function -declarations and definitions. Most importantly, if any function with a given -name is given the ``overloadable`` attribute, then all function declarations -and definitions with that name (and in that scope) must have the -``overloadable`` attribute. This rule even applies to redeclarations of -functions whose original declaration had the ``overloadable`` attribute, e.g., +declarations and definitions. If a function is marked with the ``overloadable`` +attribute, then all declarations and definitions of functions with that name, +except for at most one (see the note below about unmarked overloads), must have +the ``overloadable`` attribute. In addition, redeclarations of a function with +the ``overloadable`` attribute must have the ``overloadable`` attribute, and +redeclarations of a function without the ``overloadable`` attribute must *not* +have the ``overloadable`` attribute. e.g., .. code-block:: c int f(int) __attribute__((overloadable)); float f(float); // error: declaration of "f" must have the "overloadable" attribute + int f(int); // error: redeclaration of "f" must have the "overloadable" attribute int g(int) __attribute__((overloadable)); int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute + int h(int); + int h(int) __attribute__((overloadable)); // error: declaration of "h" must not + // have the "overloadable" attribute + Functions marked ``overloadable`` must have prototypes. Therefore, the following code is ill-formed: @@ -651,7 +658,28 @@ caveats to this use of name mangling: linkage specification, it's name *will* be mangled in the same way as it would in C. -Query for this feature with ``__has_extension(attribute_overloadable)``. +For the purpose of backwards compatibility, at most one function with the same +name as other ``overloadable`` functions may omit the ``overloadable`` +attribute. In this case, the function without the ``overloadable`` attribute +will not have its name mangled. + +For example: + +.. code-block:: c + + // Notes with mangled names assume Itanium mangling. + int f(int); + int f(double) __attribute__((overloadable)); + void foo() { + f(5); // Emits a call to f (not _Z1fi, as it would with an overload that + // was marked with overloadable). + f(1.0); // Emits a call to _Z1fd. + } + +Support for unmarked overloads is not present in some versions of clang. You may +query for it using ``__has_extension(overloadable_unmarked)``. + +Query for this attribute with ``__has_attribute(overloadable)``. }]; } diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index cba9b251215a..6224f13ce762 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3294,13 +3294,15 @@ def warn_iboutletcollection_property_assign : Warning< "IBOutletCollection properties should be copy/strong and not assign">, InGroup; -def err_attribute_overloadable_missing : Error< - "%select{overloaded function|redeclaration of}0 %1 must have the " - "'overloadable' attribute">; +def err_attribute_overloadable_mismatch : Error< + "redeclaration of %0 must %select{not |}1have the 'overloadable' attribute">; def note_attribute_overloadable_prev_overload : Note< - "previous overload of function is here">; + "previous %select{unmarked |}0overload of function is here">; def err_attribute_overloadable_no_prototype : Error< "'overloadable' function %0 must have a prototype">; +def err_attribute_overloadable_multiple_unmarked_overloads : Error< + "at most one overload for a given name may lack the 'overloadable' " + "attribute">; def warn_ns_attribute_wrong_return_type : Warning< "%0 attribute only applies to %select{functions|methods|properties}1 that " "return %select{an Objective-C object|a pointer|a non-retainable pointer}2">, diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index a6bfc32e2213..8af9a50cc204 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -1315,6 +1315,8 @@ static bool HasExtension(const Preprocessor &PP, StringRef Extension) { .Case("cxx_binary_literals", true) .Case("cxx_init_captures", LangOpts.CPlusPlus11) .Case("cxx_variable_templates", LangOpts.CPlusPlus) + // Miscellaneous language extensions + .Case("overloadable_unmarked", true) .Default(false); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 71f4d069b804..fd172def2dfe 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1327,15 +1327,17 @@ void Sema::ActOnExitFunctionContext() { /// overloaded function declaration or has the "overloadable" /// attribute. static bool AllowOverloadingOfFunction(LookupResult &Previous, - ASTContext &Context) { + ASTContext &Context, + const FunctionDecl *New) { if (Context.getLangOpts().CPlusPlus) return true; if (Previous.getResultKind() == LookupResult::FoundOverloaded) return true; - return (Previous.getResultKind() == LookupResult::Found - && Previous.getFoundDecl()->hasAttr()); + return Previous.getResultKind() == LookupResult::Found && + (Previous.getFoundDecl()->hasAttr() || + New->hasAttr()); } /// Add this decl to the scope shadowed decl chains. @@ -2933,6 +2935,41 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, New->dropAttr(); } + if (!getLangOpts().CPlusPlus) { + bool OldOvl = Old->hasAttr(); + if (OldOvl != New->hasAttr() && !Old->isImplicit()) { + Diag(New->getLocation(), diag::err_attribute_overloadable_mismatch) + << New << OldOvl; + + // Try our best to find a decl that actually has the overloadable + // attribute for the note. In most cases (e.g. programs with only one + // broken declaration/definition), this won't matter. + // + // FIXME: We could do this if we juggled some extra state in + // OverloadableAttr, rather than just removing it. + const Decl *DiagOld = Old; + if (OldOvl) { + auto OldIter = llvm::find_if(Old->redecls(), [](const Decl *D) { + const auto *A = D->getAttr(); + return A && !A->isImplicit(); + }); + // If we've implicitly added *all* of the overloadable attrs to this + // chain, emitting a "previous redecl" note is pointless. + DiagOld = OldIter == Old->redecls_end() ? nullptr : *OldIter; + } + + if (DiagOld) + Diag(DiagOld->getLocation(), + diag::note_attribute_overloadable_prev_overload) + << OldOvl; + + if (OldOvl) + New->addAttr(OverloadableAttr::CreateImplicit(Context)); + else + New->dropAttr(); + } + } + // If a function is first declared with a calling convention, but is later // declared or defined without one, all following decls assume the calling // convention of the first. @@ -9179,6 +9216,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool Redeclaration = false; NamedDecl *OldDecl = nullptr; + bool MayNeedOverloadableChecks = false; // Merge or overload the declaration with an existing declaration of // the same name, if appropriate. @@ -9187,13 +9225,14 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, // a declaration that requires merging. If it's an overload, // there's no more work to do here; we'll just add the new // function to the scope. - if (!AllowOverloadingOfFunction(Previous, Context)) { + if (!AllowOverloadingOfFunction(Previous, Context, NewFD)) { NamedDecl *Candidate = Previous.getRepresentativeDecl(); if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) { Redeclaration = true; OldDecl = Candidate; } } else { + MayNeedOverloadableChecks = true; switch (CheckOverload(S, NewFD, Previous, OldDecl, /*NewIsUsingDecl*/ false)) { case Ovl_Match: @@ -9208,18 +9247,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, Redeclaration = false; break; } - - if (!getLangOpts().CPlusPlus && !NewFD->hasAttr()) { - // If a function name is overloadable in C, then every function - // with that name must be marked "overloadable". - Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) - << Redeclaration << NewFD; - NamedDecl *OverloadedDecl = - Redeclaration ? OldDecl : Previous.getRepresentativeDecl(); - Diag(OverloadedDecl->getLocation(), - diag::note_attribute_overloadable_prev_overload); - NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); - } } } @@ -9234,15 +9261,10 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, MergeTypeWithPrevious = false; // ... except in the presence of __attribute__((overloadable)). - if (OldDecl->hasAttr()) { - if (!getLangOpts().CPlusPlus && !NewFD->hasAttr()) { - Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing) - << Redeclaration << NewFD; - Diag(Previous.getFoundDecl()->getLocation(), - diag::note_attribute_overloadable_prev_overload); - NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); - } + if (OldDecl->hasAttr() || + NewFD->hasAttr()) { if (IsOverload(NewFD, cast(OldDecl), false)) { + MayNeedOverloadableChecks = true; Redeclaration = false; OldDecl = nullptr; } @@ -9337,6 +9359,29 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, NewFD->setAccess(OldDecl->getAccess()); } } + } else if (!getLangOpts().CPlusPlus && MayNeedOverloadableChecks && + !NewFD->getAttr()) { + assert((Previous.empty() || + llvm::any_of(Previous, + [](const NamedDecl *ND) { + return ND->hasAttr(); + })) && + "Non-redecls shouldn't happen without overloadable present"); + + auto OtherUnmarkedIter = llvm::find_if(Previous, [](const NamedDecl *ND) { + const auto *FD = dyn_cast(ND); + return FD && !FD->hasAttr(); + }); + + if (OtherUnmarkedIter != Previous.end()) { + Diag(NewFD->getLocation(), + diag::err_attribute_overloadable_multiple_unmarked_overloads); + Diag((*OtherUnmarkedIter)->getLocation(), + diag::note_attribute_overloadable_prev_overload) + << false; + + NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); + } } // Semantic checking for this function declaration (in isolation). diff --git a/test/CodeGen/mangle-ms.c b/test/CodeGen/mangle-ms.c index 0ad43d5e06c2..042c72e6d794 100644 --- a/test/CodeGen/mangle-ms.c +++ b/test/CodeGen/mangle-ms.c @@ -2,3 +2,12 @@ // CHECK: define void @"\01?f@@$$J0YAXP6AX@Z@Z" __attribute__((overloadable)) void f(void (*x)()) {} + +// CHECK: define void @f +void f(void (*x)(int)) {} + +// CHECK: define void @g +void g(void (*x)(int)) {} + +// CHECK: define void @"\01?g@@$$J0YAXP6AX@Z@Z" +__attribute__((overloadable)) void g(void (*x)()) {} diff --git a/test/CodeGen/mangle.c b/test/CodeGen/mangle.c index 46ef512f6950..f94139bc5e3c 100644 --- a/test/CodeGen/mangle.c +++ b/test/CodeGen/mangle.c @@ -9,6 +9,10 @@ void __attribute__((__overloadable__)) f0(int a) {} // CHECK: @_Z2f0l void __attribute__((__overloadable__)) f0(long b) {} +// Unless it's unmarked. +// CHECK: @f0 +void f0(float b) {} + // CHECK: @bar // These should get merged. diff --git a/test/CodeGenCXX/mangle-ms.cpp b/test/CodeGenCXX/mangle-ms.cpp index ee0f50e5e2d3..7e2f17f27a96 100644 --- a/test/CodeGenCXX/mangle-ms.cpp +++ b/test/CodeGenCXX/mangle-ms.cpp @@ -399,6 +399,13 @@ template void fn_tmpl(); extern "C" void __attribute__((overloadable)) overloaded_fn() {} // CHECK-DAG: @"\01?overloaded_fn@@$$J0YAXXZ" +extern "C" void overloaded_fn2() {} +// CHECK-DAG: @overloaded_fn2 +// +extern "C" void __attribute__((overloadable)) overloaded_fn3(); +extern "C" void overloaded_fn3() {} +// CHECK-DAG: @overloaded_fn3 + namespace UnnamedType { struct S { typedef struct {} *T1[1]; diff --git a/test/PCH/attrs.c b/test/PCH/attrs.c index 3f34d4d00908..3bf660cf28e0 100644 --- a/test/PCH/attrs.c +++ b/test/PCH/attrs.c @@ -13,8 +13,9 @@ int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", " #else +float f(float); double f(double); // expected-error{{overloadable}} - // expected-note@11{{previous overload}} + // expected-note@-2{{previous unmarked overload}} void h() { g(0); } #endif diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index be9b862f2934..4bdec85f9ca9 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -3,12 +3,15 @@ int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}} void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}} -int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}} -float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}} +int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}} +float *f(float); int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \ // expected-note{{previous declaration is here}} double *f(double) __attribute__((overloadable)); // okay, new +// Ensure we don't complain about overloadable on implicitly declared functions. +int isdigit(int) __attribute__((overloadable)); + void test_f(int iv, float fv, double dv) { int *ip = f(iv); float *fp = f(fv); @@ -71,19 +74,19 @@ void test() { f1(); } -void before_local_1(int) __attribute__((overloadable)); // expected-note {{here}} +void before_local_1(int) __attribute__((overloadable)); void before_local_2(int); // expected-note {{here}} void before_local_3(int) __attribute__((overloadable)); void local() { - void before_local_1(char); // expected-error {{must have the 'overloadable' attribute}} - void before_local_2(char) __attribute__((overloadable)); // expected-error {{conflicting types}} + void before_local_1(char); + void before_local_2(char); // expected-error {{conflicting types}} void before_local_3(char) __attribute__((overloadable)); - void after_local_1(char); // expected-note {{here}} - void after_local_2(char) __attribute__((overloadable)); // expected-note {{here}} + void after_local_1(char); + void after_local_2(char) __attribute__((overloadable)); void after_local_3(char) __attribute__((overloadable)); } -void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}} -void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}} +void after_local_1(int) __attribute__((overloadable)); +void after_local_2(int); void after_local_3(int) __attribute__((overloadable)); // Make sure we allow C-specific conversions in C. @@ -152,6 +155,85 @@ void dropping_qualifiers_is_incompatible() { foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} } +void overloadable_with_global() { + void wg_foo(void) __attribute__((overloadable)); // expected-note{{previous}} + void wg_foo(int) __attribute__((overloadable)); +} + +int wg_foo; // expected-error{{redefinition of 'wg_foo' as different kind of symbol}} + +#if !__has_extension(overloadable_unmarked) +#error "We should have unmarked overload support" +#endif + +void to_foo0(int); +void to_foo0(double) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo0(int); +void to_foo0(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo0(int); + +void to_foo1(int) __attribute__((overloadable)); // expected-note 2{{previous overload}} +void to_foo1(double); +void to_foo1(int); // expected-error{{must have the 'overloadable' attribute}} +void to_foo1(double); +void to_foo1(int); // expected-error{{must have the 'overloadable' attribute}} + +void to_foo2(int); // expected-note{{previous unmarked overload}} +void to_foo2(double) __attribute__((overloadable)); // expected-note 2{{previous overload}} +void to_foo2(int) __attribute__((overloadable)); // expected-error {{must not have the 'overloadable' attribute}} +void to_foo2(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo2(int); +void to_foo2(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo2(int); + +void to_foo3(int); +void to_foo3(double) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo3(int); +void to_foo3(double); // expected-error{{must have the 'overloadable' attribute}} + +void to_foo4(int) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo4(int); // expected-error{{must have the 'overloadable' attribute}} +void to_foo4(double) __attribute__((overloadable)); + +void to_foo5(int); +void to_foo5(int); // expected-note 3{{previous unmarked overload}} +void to_foo5(float) __attribute__((overloadable)); +void to_foo5(double); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(float) __attribute__((overloadable)); +void to_foo5(short); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(long); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(double) __attribute__((overloadable)); + +void to_foo6(int) __attribute__((enable_if(1, ""), overloadable)); // expected-note{{previous overload}} +void to_foo6(int) __attribute__((enable_if(1, ""))); // expected-error{{must have the 'overloadable' attribute}} +void to_foo6(int) __attribute__((enable_if(1, ""), overloadable)); + +void to_foo7(int) __attribute__((enable_if(1, ""))); // expected-note{{previous unmarked overload}} +void to_foo7(int) __attribute__((enable_if(1, ""), overloadable)); // expected-error{{must not have the 'overloadable' attribute}} +void to_foo7(int) __attribute__((enable_if(1, ""))); + +void to_foo8(char *__attribute__((pass_object_size(0)))) + __attribute__((enable_if(1, ""))); +void to_foo8(char *__attribute__((pass_object_size(0)))) + __attribute__((overloadable)); + +void to_foo9(int); // expected-note{{previous unmarked overload}} +// FIXME: It would be nice if we did better with the "previous unmarked +// overload" diag. +void to_foo9(int) __attribute__((overloadable)); // expected-error{{must not have the 'overloadable' attribute}} expected-note{{previous declaration}} expected-note{{previous unmarked overload}} +void to_foo9(float); // expected-error{{conflicting types for 'to_foo9'}} +void to_foo9(float) __attribute__((overloadable)); +void to_foo9(double); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo9(double) __attribute__((overloadable)); + +void to_foo10(int) __attribute__((overloadable)); +void to_foo10(double); // expected-note{{previous unmarked overload}} +// no "note: previous redecl" if no previous decl has `overloadable` +// spelled out +void to_foo10(float); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo10(float); // expected-error{{must have the 'overloadable' attribute}} +void to_foo10(float); // expected-error{{must have the 'overloadable' attribute}} + // Bug: we used to treat `__typeof__(foo)` as though it was `__typeof__(&foo)` // if `foo` was overloaded with only one function that could have its address // taken. From 34efc84dff3e2cb91e6afdf460a7893a4a886029 Mon Sep 17 00:00:00 2001 From: Jonathan Coe Date: Tue, 27 Jun 2017 22:54:56 +0000 Subject: [PATCH 098/214] [libclang] Support for querying the exception specification type through libclang Summary: This patch exposes the exception specification type (noexcept, etc.) of a C++ function through libclang and Python clang.cindex. Reviewers: rsmith, aaron.ballman Reviewed By: aaron.ballman Subscribers: jbcoe, cfe-commits Differential Revision: https://reviews.llvm.org/D34091 Patch by Andrew Bennieston git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306483 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/clang/cindex.py | 44 ++++++++++++ .../test_exception_specification_kind.py | 27 ++++++++ include/clang-c/Index.h | 69 ++++++++++++++++++- test/Index/get-cursor.cpp | 17 ++++- tools/c-index-test/c-index-test.c | 31 +++++++++ tools/libclang/CXType.cpp | 18 +++++ tools/libclang/libclang.exports | 2 + 7 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 bindings/python/tests/test_exception_specification_kind.py diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 8440b0aabe08..5e70bde770f8 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -1367,6 +1367,30 @@ class TemplateArgumentKind(BaseEnumeration): TemplateArgumentKind.NULLPTR = TemplateArgumentKind(3) TemplateArgumentKind.INTEGRAL = TemplateArgumentKind(4) +### Exception Specification Kinds ### +class ExceptionSpecificationKind(BaseEnumeration): + """ + An ExceptionSpecificationKind describes the kind of exception specification + that a function has. + """ + + # The required BaseEnumeration declarations. + _kinds = [] + _name_map = None + + def __repr__(self): + return 'ExceptionSpecificationKind.{}'.format(self.name) + +ExceptionSpecificationKind.NONE = ExceptionSpecificationKind(0) +ExceptionSpecificationKind.DYNAMIC_NONE = ExceptionSpecificationKind(1) +ExceptionSpecificationKind.DYNAMIC = ExceptionSpecificationKind(2) +ExceptionSpecificationKind.MS_ANY = ExceptionSpecificationKind(3) +ExceptionSpecificationKind.BASIC_NOEXCEPT = ExceptionSpecificationKind(4) +ExceptionSpecificationKind.COMPUTED_NOEXCEPT = ExceptionSpecificationKind(5) +ExceptionSpecificationKind.UNEVALUATED = ExceptionSpecificationKind(6) +ExceptionSpecificationKind.UNINSTANTIATED = ExceptionSpecificationKind(7) +ExceptionSpecificationKind.UNPARSED = ExceptionSpecificationKind(8) + ### Cursors ### class Cursor(Structure): @@ -1586,6 +1610,18 @@ def result_type(self): return self._result_type + @property + def exception_specification_kind(self): + ''' + Retrieve the exception specification kind, which is one of the values + from the ExceptionSpecificationKind enumeration. + ''' + if not hasattr(self, '_exception_specification_kind'): + exc_kind = conf.lib.clang_getCursorExceptionSpecificationType(self) + self._exception_specification_kind = ExceptionSpecificationKind.from_id(exc_kind) + + return self._exception_specification_kind + @property def underlying_typedef_type(self): """Return the underlying type of a typedef declaration. @@ -2254,6 +2290,14 @@ def visitor(field, children): callbacks['fields_visit'](visitor), fields) return iter(fields) + def get_exception_specification_kind(self): + """ + Return the kind of the exception specification; a value from + the ExceptionSpecificationKind enumeration. + """ + return ExceptionSpecificationKind.from_id( + conf.lib.clang.getExceptionSpecificationType(self)) + @property def spelling(self): """Retrieve the spelling of this Type.""" diff --git a/bindings/python/tests/test_exception_specification_kind.py b/bindings/python/tests/test_exception_specification_kind.py new file mode 100644 index 000000000000..543d47f7db97 --- /dev/null +++ b/bindings/python/tests/test_exception_specification_kind.py @@ -0,0 +1,27 @@ +import clang.cindex +from clang.cindex import ExceptionSpecificationKind +from .util import get_tu + + +def find_function_declarations(node, declarations=[]): + if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: + declarations.append((node.spelling, node.exception_specification_kind)) + for child in node.get_children(): + declarations = find_function_declarations(child, declarations) + return declarations + + +def test_exception_specification_kind(): + source = """int square1(int x); + int square2(int x) noexcept; + int square3(int x) noexcept(noexcept(x * x));""" + + tu = get_tu(source, lang='cpp', flags=['-std=c++14']) + + declarations = find_function_declarations(tu.cursor) + expected = [ + ('square1', ExceptionSpecificationKind.NONE), + ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT), + ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT) + ] + assert declarations == expected diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 4241e43a9697..f404e6d72ec9 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -171,7 +171,60 @@ typedef struct CXVersion { */ int Subminor; } CXVersion; - + +/** + * \brief Describes the exception specification of a cursor. + * + * A negative value indicates that the cursor is not a function declaration. + */ +enum CXCursor_ExceptionSpecificationKind { + + /** + * \brief The cursor has no exception specification. + */ + CXCursor_ExceptionSpecificationKind_None, + + /** + * \brief The cursor has exception specification throw() + */ + CXCursor_ExceptionSpecificationKind_DynamicNone, + + /** + * \brief The cursor has exception specification throw(T1, T2) + */ + CXCursor_ExceptionSpecificationKind_Dynamic, + + /** + * \brief The cursor has exception specification throw(...). + */ + CXCursor_ExceptionSpecificationKind_MSAny, + + /** + * \brief The cursor has exception specification basic noexcept. + */ + CXCursor_ExceptionSpecificationKind_BasicNoexcept, + + /** + * \brief The cursor has exception specification computed noexcept. + */ + CXCursor_ExceptionSpecificationKind_ComputedNoexcept, + + /** + * \brief The exception specification has not yet been evaluated. + */ + CXCursor_ExceptionSpecificationKind_Unevaluated, + + /** + * \brief The exception specification has not yet been instantiated. + */ + CXCursor_ExceptionSpecificationKind_Uninstantiated, + + /** + * \brief The exception specification has not been parsed yet. + */ + CXCursor_ExceptionSpecificationKind_Unparsed +}; + /** * \brief Provides a shared context for creating translation units. * @@ -3470,6 +3523,13 @@ CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T); */ CINDEX_LINKAGE CXType clang_getResultType(CXType T); +/** + * \brief Retrieve the exception specification type associated with a function type. + * + * If a non-function type is passed in, an error code of -1 is returned. + */ +CINDEX_LINKAGE int clang_getExceptionSpecificationType(CXType T); + /** * \brief Retrieve the number of non-variadic parameters associated with a * function type. @@ -3498,6 +3558,13 @@ CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T); */ CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); +/** + * \brief Retrieve the exception specification type associated with a given cursor. + * + * This only returns a valid result if the cursor refers to a function or method. + */ +CINDEX_LINKAGE int clang_getCursorExceptionSpecificationType(CXCursor C); + /** * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 * otherwise. diff --git a/test/Index/get-cursor.cpp b/test/Index/get-cursor.cpp index 27f75938fedd..8aa12d5bc310 100644 --- a/test/Index/get-cursor.cpp +++ b/test/Index/get-cursor.cpp @@ -145,6 +145,13 @@ void test(TestColl coll) { const int operator""_toint(unsigned long long val) { return int(val); } +// noexcept specifications +void f_noexcept() noexcept; +template void f_computed_noexcept(T t) noexcept(noexcept(t+t)); +void f_dynamic_noexcept_none() throw(); +void f_dynamic_noexcept() throw(int); +void f_dynamic_noexcept_any() throw(...); + // RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s // CHECK-COMPLETION-1: CXXConstructor=X:6:3 // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )} @@ -209,11 +216,11 @@ const int operator""_toint(unsigned long long val) { return int(val); } // RUN: c-index-test -cursor-at=%s:66:23 %s | FileCheck -check-prefix=CHECK-TEMPLSPEC %s // CHECK-TEMPLSPEC: 66:23 ClassDecl=TC:66:23 (Definition) [Specialization of TC:59:7] Extent=[66:1 - 66:31] Spelling=TC ([66:23 - 66:25]) -// RUN: c-index-test -cursor-at=%s:69:3 -cursor-at=%s:70:11 -cursor-at=%s:73:6 -cursor-at=%s:74:6 -cursor-at=%s:77:8 -cursor-at=%s:78:8 -cursor-at=%s:79:8 -cursor-at=%s:80:8 -cursor-at=%s:81:8 -cursor-at=%s:82:8 -cursor-at=%s:85:6 -cursor-at=%s:86:6 -cursor-at=%s:87:6 -cursor-at=%s:88:6 -cursor-at=%s:91:5 -cursor-at=%s:92:5 -cursor-at=%s:93:5 -cursor-at=%s:94:5 -cursor-at=%s:95:5 -cursor-at=%s:96:5 -cursor-at=%s:97:5 -cursor-at=%s:98:5 -cursor-at=%s:100:5 -cursor-at=%s:101:5 -cursor-at=%s:104:6 -cursor-at=%s:105:6 -cursor-at=%s:106:6 -cursor-at=%s:107:6 -cursor-at=%s:108:6 -cursor-at=%s:109:6 -cursor-at=%s:110:6 -cursor-at=%s:111:6 -cursor-at=%s:113:6 -cursor-at=%s:114:6 -cursor-at=%s:117:8 -cursor-at=%s:118:8 -cursor-at=%s:120:8 -cursor-at=%s:121:8 -cursor-at=%s:122:8 -cursor-at=%s:123:8 -cursor-at=%s:124:8 -cursor-at=%s:125:8 -cursor-at=%s:128:6 -cursor-at=%s:129:6 -cursor-at=%s:130:6 -cursor-at=%s:132:3 -cursor-at=%s:146:15 -std=c++11 %s | FileCheck -check-prefix=CHECK-SPELLING %s +// RUN: c-index-test -cursor-at=%s:69:3 -cursor-at=%s:70:11 -cursor-at=%s:73:6 -cursor-at=%s:74:6 -cursor-at=%s:77:8 -cursor-at=%s:78:8 -cursor-at=%s:79:8 -cursor-at=%s:80:8 -cursor-at=%s:81:8 -cursor-at=%s:82:8 -cursor-at=%s:85:6 -cursor-at=%s:86:6 -cursor-at=%s:87:6 -cursor-at=%s:88:6 -cursor-at=%s:91:5 -cursor-at=%s:92:5 -cursor-at=%s:93:5 -cursor-at=%s:94:5 -cursor-at=%s:95:5 -cursor-at=%s:96:5 -cursor-at=%s:97:5 -cursor-at=%s:98:5 -cursor-at=%s:100:5 -cursor-at=%s:101:5 -cursor-at=%s:104:6 -cursor-at=%s:105:6 -cursor-at=%s:106:6 -cursor-at=%s:107:6 -cursor-at=%s:108:6 -cursor-at=%s:109:6 -cursor-at=%s:110:6 -cursor-at=%s:111:6 -cursor-at=%s:113:6 -cursor-at=%s:114:6 -cursor-at=%s:117:8 -cursor-at=%s:118:8 -cursor-at=%s:120:8 -cursor-at=%s:121:8 -cursor-at=%s:122:8 -cursor-at=%s:123:8 -cursor-at=%s:124:8 -cursor-at=%s:125:8 -cursor-at=%s:128:6 -cursor-at=%s:129:6 -cursor-at=%s:130:6 -cursor-at=%s:132:3 -cursor-at=%s:146:15 -cursor-at=%s:149:6 -cursor-at=%s:150:25 -cursor-at=%s:151:6 -cursor-at=%s:152:6 -cursor-at=%s:153:6 -std=c++11 %s | FileCheck -check-prefix=CHECK-SPELLING %s // CHECK-SPELLING: 69:3 CXXConstructor=A:69:3 (default constructor) Extent=[69:3 - 69:6] Spelling=A ([69:3 - 69:4]) // CHECK-SPELLING: 70:11 CXXDestructor=~A:70:11 (virtual) Extent=[70:3 - 70:15] Spelling=~A ([70:11 - 70:13]) // CHECK-SPELLING: 73:6 CXXMethod=operator=:73:6 Extent=[73:3 - 73:25] Spelling=operator= ([73:6 - 73:15]) -// CHECK-SPELLING: 74:6 CXXMethod=operator=:74:6 Extent=[74:3 - 74:29] Spelling=operator= ([74:6 - 74:15]) +// CHECK-SPELLING: 74:6 CXXMethod=operator=:74:6 (noexcept) Extent=[74:3 - 74:29] Spelling=operator= ([74:6 - 74:15]) // CHECK-SPELLING: 77:8 CXXMethod=operator+:77:8 (const) Extent=[77:3 - 77:25] Spelling=operator+ ([77:8 - 77:17]) // CHECK-SPELLING: 78:8 CXXMethod=operator-:78:8 (const) Extent=[78:3 - 78:25] Spelling=operator- ([78:8 - 78:17]) // CHECK-SPELLING: 79:8 CXXMethod=operator~:79:8 (const) Extent=[79:3 - 79:25] Spelling=operator~ ([79:8 - 79:17]) @@ -257,8 +264,14 @@ const int operator""_toint(unsigned long long val) { return int(val); } // CHECK-SPELLING: 130:6 CXXMethod=operator():130:6 (const) Extent=[130:3 - 130:37] Spelling=operator() ([130:6 - 130:16]) // CHECK-SPELLING: 132:12 CXXConversion=operator bool:132:12 (const) Extent=[132:3 - 132:33] Spelling=operator bool ([132:12 - 132:25]) // CHECK-SPELLING: 146:11 FunctionDecl=operator""_toint:146:11 (Definition) Extent=[146:1 - 146:72] Spelling=operator""_toint ([146:11 - 146:27]) +// CHECK-SPELLING: 149:6 FunctionDecl=f_noexcept:149:6 (noexcept) Extent=[149:1 - 149:27] Spelling=f_noexcept ([149:6 - 149:16]) +// CHECK-SPELLING: 150:25 FunctionTemplate=f_computed_noexcept:150:25 (computed-noexcept) Extent=[150:1 - 150:73] Spelling=f_computed_noexcept ([150:25 - 150:44]) +// CHECK-SPELLING: 151:6 FunctionDecl=f_dynamic_noexcept_none:151:6 (noexcept dynamic none) Extent=[151:1 - 151:39] Spelling=f_dynamic_noexcept_none ([151:6 - 151:29]) +// CHECK-SPELLING: 152:6 FunctionDecl=f_dynamic_noexcept:152:6 (noexcept dynamic) Extent=[152:1 - 152:37] Spelling=f_dynamic_noexcept ([152:6 - 152:24]) +// CHECK-SPELLING: 153:6 FunctionDecl=f_dynamic_noexcept_any:153:6 (noexcept dynamic any) Extent=[153:1 - 153:41] Spelling=f_dynamic_noexcept_any ([153:6 - 153:28]) // RUN: c-index-test -cursor-at=%s:141:13 -cursor-at=%s:141:18 -cursor-at=%s:142:11 -std=c++11 %s | FileCheck -check-prefix=CHECK-FORRANGE %s // CHECK-FORRANGE: 141:13 VarDecl=lv:141:13 (Definition) Extent=[141:8 - 141:17] Spelling=lv ([141:13 - 141:15]) // CHECK-FORRANGE: 141:18 DeclRefExpr=coll:140:20 Extent=[141:18 - 141:22] Spelling=coll ([141:18 - 141:22]) // CHECK-FORRANGE: 142:11 DeclRefExpr=lv:141:13 Extent=[142:11 - 142:13] Spelling=lv ([142:11 - 142:13]) + diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index d25ae117a68a..1e925569dd95 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -809,6 +809,37 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { if (clang_Cursor_isObjCOptional(Cursor)) printf(" (@optional)"); + switch (clang_getCursorExceptionSpecificationType(Cursor)) + { + case CXCursor_ExceptionSpecificationKind_None: + break; + + case CXCursor_ExceptionSpecificationKind_DynamicNone: + printf(" (noexcept dynamic none)"); + break; + + case CXCursor_ExceptionSpecificationKind_Dynamic: + printf(" (noexcept dynamic)"); + break; + + case CXCursor_ExceptionSpecificationKind_MSAny: + printf(" (noexcept dynamic any)"); + break; + + case CXCursor_ExceptionSpecificationKind_BasicNoexcept: + printf(" (noexcept)"); + break; + + case CXCursor_ExceptionSpecificationKind_ComputedNoexcept: + printf(" (computed-noexcept)"); + break; + + case CXCursor_ExceptionSpecificationKind_Unevaluated: + case CXCursor_ExceptionSpecificationKind_Uninstantiated: + case CXCursor_ExceptionSpecificationKind_Unparsed: + break; + } + { CXString language; CXString definedIn; diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index df9aa656b5d9..5875459734a2 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -684,6 +684,24 @@ CXType clang_getCursorResultType(CXCursor C) { return MakeCXType(QualType(), cxcursor::getCursorTU(C)); } +int clang_getExceptionSpecificationType(CXType X) { + QualType T = GetQualType(X); + if (T.isNull()) + return -1; + + if (const auto *FD = T->getAs()) + return static_cast(FD->getExceptionSpecType()); + + return -1; +} + +int clang_getCursorExceptionSpecificationType(CXCursor C) { + if (clang_isDeclaration(C.kind)) + return clang_getExceptionSpecificationType(clang_getCursorType(C)); + + return -1; +} + unsigned clang_isPODType(CXType X) { QualType T = GetQualType(X); if (T.isNull()) diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 187d4749ebc1..e78899e4c759 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -175,6 +175,7 @@ clang_getCursorCompletionString clang_getCursorDefinition clang_getCursorDisplayName clang_getCursorExtent +clang_getCursorExceptionSpecificationType clang_getCursorKind clang_getCursorKindSpelling clang_getCursorLanguage @@ -210,6 +211,7 @@ clang_getElementType clang_getEnumConstantDeclUnsignedValue clang_getEnumConstantDeclValue clang_getEnumDeclIntegerType +clang_getExceptionSpecificationType clang_getFieldDeclBitWidth clang_getExpansionLocation clang_getFile From 5b7d7d2b2d0bd7054f51b9d108cdd5299a0ec33e Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Tue, 27 Jun 2017 23:56:34 +0000 Subject: [PATCH 099/214] [COFF, ARM64] Add support for Windows ARM64 COFF format Summary: This is the clang part of the initial implementation to support Windows ARM64 COFF format. Reviewers: ruiu, t.p.northover, rnk, compnerd Reviewed By: ruiu, compnerd Subscribers: aemerson, kristof.beyls, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D34706 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306489 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 39 +++++++++++++++++++++++++++ test/Preprocessor/predefined-macros.c | 6 +++++ 2 files changed, 45 insertions(+) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index b9d8dc04b326..02ded70b2011 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -6550,6 +6550,43 @@ class AArch64leTargetInfo : public AArch64TargetInfo { } }; +class MicrosoftARM64TargetInfo + : public WindowsTargetInfo { + const llvm::Triple Triple; + +public: + MicrosoftARM64TargetInfo(const llvm::Triple &Triple, + const TargetOptions &Opts) + : WindowsTargetInfo(Triple, Opts), Triple(Triple) { + WCharType = UnsignedShort; + SizeType = UnsignedLongLong; + TheCXXABI.set(TargetCXXABI::Microsoft); + } + + void setDataLayout() override { + resetDataLayout("e-m:w-i64:64-i128:128-n32:64-S128"); + } + + void getVisualStudioDefines(const LangOptions &Opts, + MacroBuilder &Builder) const { + WindowsTargetInfo::getVisualStudioDefines(Opts, + Builder); + Builder.defineMacro("_WIN32", "1"); + Builder.defineMacro("_WIN64", "1"); + Builder.defineMacro("_M_ARM64", "1"); + } + + void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const override { + WindowsTargetInfo::getTargetDefines(Opts, Builder); + getVisualStudioDefines(Opts, Builder); + } + + BuiltinVaListKind getBuiltinVaListKind() const override { + return TargetInfo::CharPtrBuiltinVaList; + } +}; + class AArch64beTargetInfo : public AArch64TargetInfo { void setDataLayout() override { assert(!getTriple().isOSBinFormatMachO()); @@ -9406,6 +9443,8 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple, return new NetBSDTargetInfo(Triple, Opts); case llvm::Triple::OpenBSD: return new OpenBSDTargetInfo(Triple, Opts); + case llvm::Triple::Win32: + return new MicrosoftARM64TargetInfo(Triple, Opts); default: return new AArch64leTargetInfo(Triple, Opts); } diff --git a/test/Preprocessor/predefined-macros.c b/test/Preprocessor/predefined-macros.c index 7385cd2c93ef..662a712d6477 100644 --- a/test/Preprocessor/predefined-macros.c +++ b/test/Preprocessor/predefined-macros.c @@ -185,3 +185,9 @@ // CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 +// RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN + +// CHECK-ARM64-WIN: #define _M_ARM64 1 +// CHECK-ARM64-WIN: #define _WIN32 1 +// CHECK-ARM64-WIN: #define _WIN64 1 From afd3b93fc835d07303f8880c091dbd5306f5fb9c Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 28 Jun 2017 00:42:48 +0000 Subject: [PATCH 100/214] [CodeGen] Fix assertion failure in EmitCallArg. The assertion was failing when a method of a parameterized class was called and the types of the argument and parameter didn't match. To fix the failure, move the assertion in EmitCallArg to its only caller EmitCallArgs and require the argument and parameter types match only when the method is not parameterized. rdar://problem/32874473 Differential Revision: https://reviews.llvm.org/D34665 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306494 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 9 +++++++- test/CodeGenObjC/parameterized_classes.m | 28 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 38d520a2beb0..8795e4a89989 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -3389,6 +3389,14 @@ void CodeGenFunction::EmitCallArgs( unsigned Idx = LeftToRight ? I : E - I - 1; CallExpr::const_arg_iterator Arg = ArgRange.begin() + Idx; unsigned InitialArgSize = Args.size(); + // If *Arg is an ObjCIndirectCopyRestoreExpr, check that either the types of + // the argument and parameter match or the objc method is parameterized. + assert((!isa(*Arg) || + getContext().hasSameUnqualifiedType((*Arg)->getType(), + ArgTypes[Idx]) || + (isa(AC.getDecl()) && + isObjCMethodWithTypeParams(cast(AC.getDecl())))) && + "Argument and parameter types don't match"); EmitCallArg(Args, *Arg, ArgTypes[Idx]); // In particular, we depend on it being the last arg in Args, and the // objectsize bits depend on there only being one arg if !LeftToRight. @@ -3449,7 +3457,6 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, if (const ObjCIndirectCopyRestoreExpr *CRE = dyn_cast(E)) { assert(getLangOpts().ObjCAutoRefCount); - assert(getContext().hasSameUnqualifiedType(E->getType(), type)); return emitWritebackArg(*this, args, CRE); } diff --git a/test/CodeGenObjC/parameterized_classes.m b/test/CodeGenObjC/parameterized_classes.m index 8fe5c52b8d39..34aca35af313 100644 --- a/test/CodeGenObjC/parameterized_classes.m +++ b/test/CodeGenObjC/parameterized_classes.m @@ -96,3 +96,31 @@ - (void)setDest:(NSObject *)a { _destination = a; } @end + +// CHECK-LABEL: define internal void @"\01-[C0 foo1]"( +// CHECK: {{.*}} = alloca +// CHECK: {{.*}} = alloca +// CHECK: %[[D:.*]] = alloca %[[TY:.*]]* +// CHECK: %[[TEMP:.*]] = alloca %[[TY]]* +// CHECK: %[[V4:.*]] = load %[[TY]]*, %[[TY]]** %[[D]] +// CHECK: store %[[TY]]* %[[V4]], %[[TY]]** %[[TEMP]] +// CHECK: %[[V7:.*]] = bitcast %[[TY]]** %[[TEMP]] to i8** +// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8**)*)(i8* %{{.*}}, i8* %{{.*}}, i8** %[[V7]]) + +@interface P0 : NSObject +- (void)m0:(ObjectType *)first; +@end + +@interface C0 : NSObject +-(void)foo1; +@end + +@implementation C0 { + P0 *x; +} + +-(void)foo1 { + NSString *d; + [x m0:&d]; +} +@end From 9b79aecc27490fd2c84b2ff10e8f15d2c139fbb5 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 28 Jun 2017 01:56:07 +0000 Subject: [PATCH 101/214] Remove a redundant call to ArgList::hasFlag. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306497 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Clang.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 292cf72b56ca..072d62346cdc 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -781,15 +781,14 @@ static void addPGOAndCoverageFlags(Compilation &C, const Driver &D, CmdArgs.push_back("-femit-coverage-data"); if (Args.hasFlag(options::OPT_fcoverage_mapping, - options::OPT_fno_coverage_mapping, false) && - !ProfileGenerateArg) - D.Diag(clang::diag::err_drv_argument_only_allowed_with) - << "-fcoverage-mapping" - << "-fprofile-instr-generate"; + options::OPT_fno_coverage_mapping, false)) { + if (!ProfileGenerateArg) + D.Diag(clang::diag::err_drv_argument_only_allowed_with) + << "-fcoverage-mapping" + << "-fprofile-instr-generate"; - if (Args.hasFlag(options::OPT_fcoverage_mapping, - options::OPT_fno_coverage_mapping, false)) CmdArgs.push_back("-fcoverage-mapping"); + } if (C.getArgs().hasArg(options::OPT_c) || C.getArgs().hasArg(options::OPT_S)) { From f1a55e9516177a93b38481af6eb749e004fc5615 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Wed, 28 Jun 2017 06:46:23 +0000 Subject: [PATCH 102/214] DiagnosticRenderer.h: Prune \param SM, corresponding to rL306384. [-Wdocumentation] git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306511 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/DiagnosticRenderer.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/clang/Frontend/DiagnosticRenderer.h b/include/clang/Frontend/DiagnosticRenderer.h index 54a3d692b3cc..e453d7db624c 100644 --- a/include/clang/Frontend/DiagnosticRenderer.h +++ b/include/clang/Frontend/DiagnosticRenderer.h @@ -128,8 +128,6 @@ class DiagnosticRenderer { /// \param Message The diagnostic message to emit. /// \param Ranges The underlined ranges for this code snippet. /// \param FixItHints The FixIt hints active for this diagnostic. - /// \param SM The SourceManager; will be null if the diagnostic came from the - /// frontend, thus \p Loc will be invalid. void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef Ranges, ArrayRef FixItHints, From 48a9f92925dcc419806e2652675bece0f0db62c9 Mon Sep 17 00:00:00 2001 From: Karthik Bhat Date: Wed, 28 Jun 2017 08:52:08 +0000 Subject: [PATCH 103/214] Fix crash in clang while handling __has_trivial_destructor. Fix crash in clang when an array of unknown bounds of an incomplete type is passed to __has_trivial_destructor. Patch by Puneetha https://reviews.llvm.org/D34198 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306519 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 20 +++++++++++--------- test/SemaCXX/type-traits.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 710ead30790f..71c4c8070e77 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4093,15 +4093,9 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT, case UTT_IsStandardLayout: case UTT_IsPOD: case UTT_IsLiteral: - ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0); - LLVM_FALLTHROUGH; - - // C++1z [meta.unary.prop]: - // T shall be a complete type, cv void, or an array of unknown bound. - case UTT_IsDestructible: - case UTT_IsNothrowDestructible: - case UTT_IsTriviallyDestructible: - // Per the GCC type traits documentation, the same constraints apply to these. + // Per the GCC type traits documentation, T shall be a complete type, cv void, + // or an array of unknown bound. But GCC actually imposes the same constraints + // as above. case UTT_HasNothrowAssign: case UTT_HasNothrowMoveAssign: case UTT_HasNothrowConstructor: @@ -4113,6 +4107,14 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT, case UTT_HasTrivialCopy: case UTT_HasTrivialDestructor: case UTT_HasVirtualDestructor: + ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0); + LLVM_FALLTHROUGH; + + // C++1z [meta.unary.prop]: + // T shall be a complete type, cv void, or an array of unknown bound. + case UTT_IsDestructible: + case UTT_IsNothrowDestructible: + case UTT_IsTriviallyDestructible: if (ArgTy->isIncompleteArrayType() || ArgTy->isVoidType()) return true; diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index 8a994f01ba1a..5879a77dd5a8 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -1447,7 +1447,9 @@ void has_trivial_default_constructor() { { int arr[T(__has_trivial_constructor(const Int))]; } { int arr[T(__has_trivial_constructor(AllDefaulted))]; } { int arr[T(__has_trivial_constructor(AllDeleted))]; } + { int arr[T(__has_trivial_constructor(ACompleteType[]))]; } + { int arr[F(__has_trivial_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_constructor(HasCons))]; } { int arr[F(__has_trivial_constructor(HasRef))]; } { int arr[F(__has_trivial_constructor(HasCopy))]; } @@ -1478,7 +1480,9 @@ void has_trivial_move_constructor() { { int arr[T(__has_trivial_move_constructor(HasCons))]; } { int arr[T(__has_trivial_move_constructor(HasStaticMemberMoveCtor))]; } { int arr[T(__has_trivial_move_constructor(AllDeleted))]; } - + { int arr[T(__has_trivial_move_constructor(ACompleteType[]))]; } + + { int arr[F(__has_trivial_move_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_move_constructor(HasVirt))]; } { int arr[F(__has_trivial_move_constructor(DerivesVirt))]; } { int arr[F(__has_trivial_move_constructor(HasMoveCtor))]; } @@ -1508,7 +1512,9 @@ void has_trivial_copy_constructor() { { int arr[T(__has_trivial_copy(AllDeleted))]; } { int arr[T(__has_trivial_copy(DerivesAr))]; } { int arr[T(__has_trivial_copy(DerivesHasRef))]; } + { int arr[T(__has_trivial_copy(ACompleteType[]))]; } + { int arr[F(__has_trivial_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_copy(HasCopy))]; } { int arr[F(__has_trivial_copy(HasTemplateCons))]; } { int arr[F(__has_trivial_copy(VirtAr))]; } @@ -1536,7 +1542,9 @@ void has_trivial_copy_assignment() { { int arr[T(__has_trivial_assign(AllDeleted))]; } { int arr[T(__has_trivial_assign(DerivesAr))]; } { int arr[T(__has_trivial_assign(DerivesHasRef))]; } + { int arr[T(__has_trivial_assign(ACompleteType[]))]; } + { int arr[F(__has_trivial_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_assign(IntRef))]; } { int arr[F(__has_trivial_assign(HasCopyAssign))]; } { int arr[F(__has_trivial_assign(const Int))]; } @@ -1572,8 +1580,10 @@ void has_trivial_destructor() { { int arr[T(__has_trivial_destructor(AllDefaulted))]; } { int arr[T(__has_trivial_destructor(AllDeleted))]; } { int arr[T(__has_trivial_destructor(DerivesHasRef))]; } + { int arr[T(__has_trivial_destructor(ACompleteType[]))]; } { int arr[F(__has_trivial_destructor(HasDest))]; } + { int arr[F(__has_trivial_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_destructor(void))]; } { int arr[F(__has_trivial_destructor(cvoid))]; } { int arr[F(__has_trivial_destructor(AllPrivate))]; } @@ -1625,7 +1635,9 @@ void has_nothrow_assign() { { int arr[T(__has_nothrow_assign(AllPrivate))]; } { int arr[T(__has_nothrow_assign(UsingAssign))]; } { int arr[T(__has_nothrow_assign(DerivesAr))]; } + { int arr[T(__has_nothrow_assign(ACompleteType[]))]; } + { int arr[F(__has_nothrow_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_assign(IntRef))]; } { int arr[F(__has_nothrow_assign(HasCopyAssign))]; } { int arr[F(__has_nothrow_assign(HasMultipleCopyAssign))]; } @@ -1650,8 +1662,9 @@ void has_nothrow_move_assign() { { int arr[T(__has_nothrow_move_assign(HasMemberNoThrowMoveAssign))]; } { int arr[T(__has_nothrow_move_assign(HasMemberNoExceptNoThrowMoveAssign))]; } { int arr[T(__has_nothrow_move_assign(AllDeleted))]; } + { int arr[T(__has_nothrow_move_assign(ACompleteType[]))]; } - + { int arr[F(__has_nothrow_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_move_assign(HasThrowMoveAssign))]; } { int arr[F(__has_nothrow_move_assign(HasNoExceptFalseMoveAssign))]; } { int arr[F(__has_nothrow_move_assign(HasMemberThrowMoveAssign))]; } @@ -1683,7 +1696,9 @@ void has_trivial_move_assign() { { int arr[T(__has_trivial_move_assign(Int))]; } { int arr[T(__has_trivial_move_assign(HasStaticMemberMoveAssign))]; } { int arr[T(__has_trivial_move_assign(AllDeleted))]; } + { int arr[T(__has_trivial_move_assign(ACompleteType[]))]; } + { int arr[F(__has_trivial_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_move_assign(HasVirt))]; } { int arr[F(__has_trivial_move_assign(DerivesVirt))]; } { int arr[F(__has_trivial_move_assign(HasMoveAssign))]; } @@ -1717,7 +1732,9 @@ void has_nothrow_copy() { { int arr[T(__has_nothrow_copy(HasTemplateCons))]; } { int arr[T(__has_nothrow_copy(AllPrivate))]; } { int arr[T(__has_nothrow_copy(DerivesAr))]; } + { int arr[T(__has_nothrow_copy(ACompleteType[]))]; } + { int arr[F(__has_nothrow_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_copy(HasCopy))]; } { int arr[F(__has_nothrow_copy(HasMultipleCopy))]; } { int arr[F(__has_nothrow_copy(VirtAr))]; } @@ -1743,7 +1760,9 @@ void has_nothrow_constructor() { { int arr[T(__has_nothrow_constructor(HasVirtDest))]; } // { int arr[T(__has_nothrow_constructor(VirtAr))]; } // not implemented { int arr[T(__has_nothrow_constructor(AllPrivate))]; } + { int arr[T(__has_nothrow_constructor(ACompleteType[]))]; } + { int arr[F(__has_nothrow_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_constructor(HasCons))]; } { int arr[F(__has_nothrow_constructor(HasRef))]; } { int arr[F(__has_nothrow_constructor(HasCopy))]; } @@ -1779,7 +1798,9 @@ void has_virtual_destructor() { { int arr[F(__has_virtual_destructor(HasMoveAssign))]; } { int arr[F(__has_virtual_destructor(IntRef))]; } { int arr[F(__has_virtual_destructor(VirtAr))]; } + { int arr[F(__has_virtual_destructor(ACompleteType[]))]; } + { int arr[F(__has_virtual_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[T(__has_virtual_destructor(HasVirtDest))]; } { int arr[T(__has_virtual_destructor(DerivedVirtDest))]; } { int arr[F(__has_virtual_destructor(VirtDestAr))]; } From 351c5b32bd8b35886cc5ad8d48bac63488bd43a1 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Wed, 28 Jun 2017 15:06:34 +0000 Subject: [PATCH 104/214] Use vfs::FileSystem in ASTUnit when creating CompilerInvocation. Summary: It used to always call into the RealFileSystem before. Reviewers: bkramer, krasimir, klimek, bruno Reviewed By: klimek Subscribers: bruno, cfe-commits Differential Revision: https://reviews.llvm.org/D34469 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306549 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/Utils.h | 9 +++++---- lib/Frontend/ASTUnit.cpp | 2 +- lib/Frontend/CreateInvocationFromCommandLine.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 0ee46846c804..8ccc31982dab 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -184,10 +184,11 @@ createChainedIncludesSource(CompilerInstance &CI, /// /// \return A CompilerInvocation, or 0 if none was built for the given /// argument vector. -std::unique_ptr -createInvocationFromCommandLine(ArrayRef Args, - IntrusiveRefCntPtr Diags = - IntrusiveRefCntPtr()); +std::unique_ptr createInvocationFromCommandLine( + ArrayRef Args, + IntrusiveRefCntPtr Diags = + IntrusiveRefCntPtr(), + IntrusiveRefCntPtr VFS = nullptr); /// Return the value of the last argument as an integer, or a default. If Diags /// is non-null, emits an error if the argument is given, but non-integral. diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 1f34f10f55af..c5a911fdae08 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1638,7 +1638,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( &StoredDiagnostics, nullptr); CI = clang::createInvocationFromCommandLine( - llvm::makeArrayRef(ArgBegin, ArgEnd), Diags); + llvm::makeArrayRef(ArgBegin, ArgEnd), Diags, VFS); if (!CI) return nullptr; } diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp index 49d459e78c45..c3ce7ce2b742 100644 --- a/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -31,8 +31,8 @@ using namespace llvm::opt; /// \return A CompilerInvocation, or 0 if none was built for the given /// argument vector. std::unique_ptr clang::createInvocationFromCommandLine( - ArrayRef ArgList, - IntrusiveRefCntPtr Diags) { + ArrayRef ArgList, IntrusiveRefCntPtr Diags, + IntrusiveRefCntPtr VFS) { if (!Diags.get()) { // No diagnostics engine was provided, so create our own diagnostics object // with the default options. @@ -46,7 +46,7 @@ std::unique_ptr clang::createInvocationFromCommandLine( // FIXME: We shouldn't have to pass in the path info. driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), - *Diags); + *Diags, VFS); // Don't check that inputs exist, they may have been remapped. TheDriver.setCheckInputsExist(false); From ddb61cae6a5e7f3f0bc5da4290334368d03da2a0 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Wed, 28 Jun 2017 15:59:55 +0000 Subject: [PATCH 105/214] [Bash-autocompletion] Check clang version in Bash Summary: Add check if user's clang version supports --autocomplete or not. If not, we just autocomplete files. Reviewers: ruiu, v.g.vassilev, teemperor Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34607 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306555 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/bash-autocomplete.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index ba908bcc0bc3..46e29b87bb54 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -1,7 +1,7 @@ # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this. _clang() { - local cur prev words cword arg + local cur prev words cword arg flags _init_completion -n : || return # bash always separates '=' as a token even if there's no space before/after '='. @@ -24,7 +24,14 @@ _clang() arg="$w2=,$cur" fi - local flags=$( clang --autocomplete="$arg" ) + flags=$( clang --autocomplete="$arg" 2>/dev/null ) + # If clang is old that it does not support --autocomplete, + # fall back to the filename completion. + if [[ "$?" != 0 ]]; then + _filedir + return + fi + if [[ "$cur" == '=' ]]; then COMPREPLY=( $( compgen -W "$flags" -- "") ) elif [[ "$flags" == "" || "$arg" == "" ]]; then From af42c8bd388d0e6369a9e5c1041b2e9126cb6f50 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Wed, 28 Jun 2017 16:29:26 +0000 Subject: [PATCH 106/214] [Bash-autocompletion] Invoke clang where user called Summary: When user build clang and used completion Eg. `build/bin/clang -fno[tab]`, we want to invoke `build/bin/clang --autocomplete=-fno`, rather than `clang --autocomplete=-fno`. Differential Revision: https://reviews.llvm.org/D34761 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306559 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/bash-autocomplete.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index 46e29b87bb54..775b1f45351a 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -24,7 +24,7 @@ _clang() arg="$w2=,$cur" fi - flags=$( clang --autocomplete="$arg" 2>/dev/null ) + flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null ) # If clang is old that it does not support --autocomplete, # fall back to the filename completion. if [[ "$?" != 0 ]]; then From 145692ef46de14b98bb54ed3ed098b2b69dd2b9a Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 28 Jun 2017 18:36:27 +0000 Subject: [PATCH 107/214] [ASTReader] Treat multiple defns of ObjC protocols the same as interfaces. Summary: In change 2ba19793512, the ASTReader logic for ObjC interfaces was modified to preserve the first definition-data read, "merging" later definitions into it rather than overwriting it (though this "merging" is, in practice, a no-op that discards the later definition-data). Unfortunately this change was only made to ObjC interfaces, not protocols; this means that when (for example) loading a protocol that references an interface, if both the protocol and interface are multiply defined (as can easily happen if the same header is read from multiple contexts), an _inconsistent_ pair of definitions is loaded: first-read for the interface and last-read for the protocol. This in turn causes very subtle downstream bugs in the Swift ClangImporter, which filters the results of name lookups based on the owning module of a definition; inconsistency between a pair of related definitions causes name lookup failures at various stages of compilation. To fix these downstream issues, this change replicates the logic applied to interfaces in change 2ba19793512, but for ObjC protocols. rdar://30851899 Reviewers: doug.gregor, rsmith Reviewed By: doug.gregor Subscribers: jordan_rose, cfe-commits Differential Revision: https://reviews.llvm.org/D34741 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306583 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Redeclarable.h | 54 +++++++++++++++++++++++++++++ lib/Serialization/ASTReaderDecl.cpp | 49 ++++++++++++++++++-------- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h index cd5f186a2086..89a9d3c4cc21 100644 --- a/include/clang/AST/Redeclarable.h +++ b/include/clang/AST/Redeclarable.h @@ -21,6 +21,60 @@ namespace clang { class ASTContext; +// Some notes on redeclarables: +// +// - Every redeclarable is on a circular linked list. +// +// - Every decl has a pointer to the first element of the chain _and_ a +// DeclLink that may point to one of 3 possible states: +// - the "previous" (temporal) element in the chain +// - the "latest" (temporal) element in the chain +// - the an "uninitialized-latest" value (when newly-constructed) +// +// - The first element is also often called the canonical element. Every +// element has a pointer to it so that "getCanonical" can be fast. +// +// - Most links in the chain point to previous, except the link out of +// the first; it points to latest. +// +// - Elements are called "first", "previous", "latest" or +// "most-recent" when referring to temporal order: order of addition +// to the chain. +// +// - To make matters confusing, the DeclLink type uses the term "next" +// for its pointer-storage internally (thus functions like +// NextIsPrevious). It's easiest to just ignore the implementation of +// DeclLink when making sense of the redeclaration chain. +// +// - There's also a "definition" link for several types of +// redeclarable, where only one definition should exist at any given +// time (and the defn pointer is stored in the decl's "data" which +// is copied to every element on the chain when it's changed). +// +// Here is some ASCII art: +// +// "first" "latest" +// "canonical" "most recent" +// +------------+ first +--------------+ +// | | <--------------------------- | | +// | | | | +// | | | | +// | | +--------------+ | | +// | | first | | | | +// | | <---- | | | | +// | | | | | | +// | @class A | link | @interface A | link | @class A | +// | seen first | <---- | seen second | <---- | seen third | +// | | | | | | +// +------------+ +--------------+ +--------------+ +// | data | defn | data | defn | data | +// | | ----> | | <---- | | +// +------------+ +--------------+ +--------------+ +// | | ^ ^ +// | |defn | | +// | link +-----+ | +// +-->-------------------------------------------+ + /// \brief Provides common interface for the Decls that can be redeclared. template class Redeclarable { diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 07ab421cfc51..e1b1abba46fb 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -126,6 +126,9 @@ namespace clang { void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); void MergeDefinitionData(ObjCInterfaceDecl *D, struct ObjCInterfaceDecl::DefinitionData &&NewDD); + void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); + void MergeDefinitionData(ObjCProtocolDecl *D, + struct ObjCProtocolDecl::DefinitionData &&NewDD); static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, @@ -1045,18 +1048,8 @@ void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { IVD->setSynthesize(synth); } -void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { - RedeclarableResult Redecl = VisitRedeclarable(PD); - VisitObjCContainerDecl(PD); - mergeRedeclarable(PD, Redecl); - - if (Record.readInt()) { - // Read the definition. - PD->allocateDefinitionData(); - - // Set the definition data of the canonical declaration, so other - // redeclarations will see it. - PD->getCanonicalDecl()->Data = PD->Data; +void ASTDeclReader::ReadObjCDefinitionData( + struct ObjCProtocolDecl::DefinitionData &Data) { unsigned NumProtoRefs = Record.readInt(); SmallVector ProtoRefs; @@ -1067,9 +1060,37 @@ void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { ProtoLocs.reserve(NumProtoRefs); for (unsigned I = 0; I != NumProtoRefs; ++I) ProtoLocs.push_back(ReadSourceLocation()); - PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), - Reader.getContext()); + Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, + ProtoLocs.data(), Reader.getContext()); +} + +void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, + struct ObjCProtocolDecl::DefinitionData &&NewDD) { + // FIXME: odr checking? +} +void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { + RedeclarableResult Redecl = VisitRedeclarable(PD); + VisitObjCContainerDecl(PD); + mergeRedeclarable(PD, Redecl); + + if (Record.readInt()) { + // Read the definition. + PD->allocateDefinitionData(); + + ReadObjCDefinitionData(PD->data()); + + ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); + if (Canon->Data.getPointer()) { + // If we already have a definition, keep the definition invariant and + // merge the data. + MergeDefinitionData(Canon, std::move(PD->data())); + PD->Data = Canon->Data; + } else { + // Set the definition data of the canonical declaration, so other + // redeclarations will see it. + PD->getCanonicalDecl()->Data = PD->Data; + } // Note that we have deserialized a definition. Reader.PendingDefinitions.insert(PD); } else { From 64b75be74b549be56038f8795788ebb73714709e Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 29 Jun 2017 00:54:44 +0000 Subject: [PATCH 108/214] CodeGen: handle missed case of COMDAT handling When Protocol references are constructed, we need to add the reference symbol to a COMDAT group on non-MachO object file formats (MachO handles this by having a coalesced attribute). This adds the missing case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306622 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 11 +++++------ test/CodeGenObjC/protocol-comdat.m | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 7976c53d9e98..224d2d6606a2 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -6381,16 +6381,15 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF, llvm::GlobalVariable *PTGV = CGM.getModule().getGlobalVariable(ProtocolName); if (PTGV) return CGF.Builder.CreateAlignedLoad(PTGV, Align); - PTGV = new llvm::GlobalVariable( - CGM.getModule(), - Init->getType(), false, - llvm::GlobalValue::WeakAnyLinkage, - Init, - ProtocolName); + PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, + llvm::GlobalValue::WeakAnyLinkage, Init, + ProtocolName); PTGV->setSection(GetSectionName("__objc_protorefs", "coalesced,no_dead_strip")); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); PTGV->setAlignment(Align.getQuantity()); + if (!CGM.getTriple().isOSBinFormatMachO()) + PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName)); CGM.addCompilerUsedGlobal(PTGV); return CGF.Builder.CreateAlignedLoad(PTGV, Align); } diff --git a/test/CodeGenObjC/protocol-comdat.m b/test/CodeGenObjC/protocol-comdat.m index 65e1b9fa2c82..a19ba8cf35dc 100644 --- a/test/CodeGenObjC/protocol-comdat.m +++ b/test/CodeGenObjC/protocol-comdat.m @@ -4,6 +4,9 @@ @protocol P - (void) method; @end +@protocol Q; +@protocol R; + @interface I

@end @@ -11,9 +14,14 @@ @implementation I - (void) method { } @end +_Bool f(void) { + return @protocol(Q) == @protocol(R); +} // CHECK: $"\01l_OBJC_PROTOCOL_$_P" = comdat any // CHECK: $"\01l_OBJC_LABEL_PROTOCOL_$_P" = comdat any +// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_Q" = comdat any +// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_R" = comdat any // CHECK: @"\01l_OBJC_PROTOCOL_$_P" = {{.*}}, comdat // CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, comdat From 2d7d5c241bce687a4c7018a023efb7b22769ca9d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Jun 2017 02:19:42 +0000 Subject: [PATCH 109/214] Track the set of module maps read while building a .pcm file and reload those when preprocessing from that .pcm file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306628 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 50 ++++++++++++------- include/clang/Lex/HeaderSearch.h | 2 +- include/clang/Serialization/ASTReader.h | 7 +++ lib/Frontend/CompilerInstance.cpp | 7 ++- lib/Frontend/DependencyFile.cpp | 6 +-- lib/Frontend/FrontendAction.cpp | 42 +++++++++------- lib/Lex/ModuleMap.cpp | 3 +- lib/Serialization/ASTReader.cpp | 23 +++++++-- lib/Serialization/ASTWriter.cpp | 18 ++++--- test/Modules/Inputs/preprocess-decluse/a.h | 1 + .../Inputs/preprocess-decluse/a.modulemap | 1 + test/Modules/Inputs/preprocess-decluse/b.h | 1 + .../Inputs/preprocess-decluse/b.modulemap | 1 + .../Inputs/preprocess-decluse/main.modulemap | 1 + test/Modules/preprocess-decluse.cpp | 18 +++++++ 15 files changed, 127 insertions(+), 54 deletions(-) create mode 100644 test/Modules/Inputs/preprocess-decluse/a.h create mode 100644 test/Modules/Inputs/preprocess-decluse/a.modulemap create mode 100644 test/Modules/Inputs/preprocess-decluse/b.h create mode 100644 test/Modules/Inputs/preprocess-decluse/b.modulemap create mode 100644 test/Modules/Inputs/preprocess-decluse/main.modulemap create mode 100644 test/Modules/preprocess-decluse.cpp diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 5e01f6416748..e658af742e5c 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -80,9 +80,19 @@ namespace SrcMgr { /// system_header is seen or in various other cases. /// enum CharacteristicKind { - C_User, C_System, C_ExternCSystem + C_User, C_System, C_ExternCSystem, C_User_ModuleMap, C_System_ModuleMap }; + /// Determine whether a file / directory characteristic is for system code. + inline bool isSystem(CharacteristicKind CK) { + return CK != C_User && CK != C_User_ModuleMap; + } + + /// Determine whether a file characteristic is for a module map. + inline bool isModuleMap(CharacteristicKind CK) { + return CK == C_User_ModuleMap || CK == C_System_ModuleMap; + } + /// \brief One instance of this struct is kept for every file loaded or used. /// /// This object owns the MemoryBuffer object. @@ -251,12 +261,14 @@ namespace SrcMgr { /// preprocessing of this \#include, including this SLocEntry. /// /// Zero means the preprocessor didn't provide such info for this SLocEntry. - unsigned NumCreatedFIDs; + unsigned NumCreatedFIDs : 31; + + /// \brief Whether this FileInfo has any \#line directives. + unsigned HasLineDirectives : 1; - /// \brief Contains the ContentCache* and the bits indicating the - /// characteristic of the file and whether it has \#line info, all - /// bitmangled together. - uintptr_t Data; + /// \brief The content cache and the characteristic of the file. + llvm::PointerIntPair + ContentAndKind; friend class clang::SourceManager; friend class clang::ASTWriter; @@ -269,10 +281,9 @@ namespace SrcMgr { FileInfo X; X.IncludeLoc = IL.getRawEncoding(); X.NumCreatedFIDs = 0; - X.Data = (uintptr_t)Con; - assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned"); - assert((unsigned)FileCharacter < 4 && "invalid file character"); - X.Data |= (unsigned)FileCharacter; + X.HasLineDirectives = false; + X.ContentAndKind.setPointer(Con); + X.ContentAndKind.setInt(FileCharacter); return X; } @@ -280,22 +291,22 @@ namespace SrcMgr { return SourceLocation::getFromRawEncoding(IncludeLoc); } - const ContentCache* getContentCache() const { - return reinterpret_cast(Data & ~uintptr_t(7)); + const ContentCache *getContentCache() const { + return ContentAndKind.getPointer(); } /// \brief Return whether this is a system header or not. CharacteristicKind getFileCharacteristic() const { - return (CharacteristicKind)(Data & 3); + return ContentAndKind.getInt(); } /// \brief Return true if this FileID has \#line directives in it. - bool hasLineDirectives() const { return (Data & 4) != 0; } + bool hasLineDirectives() const { return HasLineDirectives; } /// \brief Set the flag that indicates that this FileID has /// line table entries associated with it. void setHasLineDirectives() { - Data |= 4; + HasLineDirectives = true; } }; @@ -407,6 +418,8 @@ namespace SrcMgr { }; public: + SLocEntry() : Offset(), IsExpansion(), File() {} + unsigned getOffset() const { return Offset; } bool isExpansion() const { return IsExpansion; } @@ -789,9 +802,8 @@ class SourceManager : public RefCountedBase { FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID = 0, unsigned LoadedOffset = 0) { - const SrcMgr::ContentCache * - IR = getOrCreateContentCache(SourceFile, - /*isSystemFile=*/FileCharacter != SrcMgr::C_User); + const SrcMgr::ContentCache *IR = + getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); assert(IR && "getOrCreateContentCache() cannot return NULL"); return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset); } @@ -1360,7 +1372,7 @@ class SourceManager : public RefCountedBase { /// \brief Returns if a SourceLocation is in a system header. bool isInSystemHeader(SourceLocation Loc) const { - return getFileCharacteristic(Loc) != SrcMgr::C_User; + return isSystem(getFileCharacteristic(Loc)); } /// \brief Returns if a SourceLocation is in an "extern C" system header. diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index ee17dcbb8b5a..1b7f80c87ff1 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -47,7 +47,7 @@ struct HeaderFileInfo { /// whether it is C++ clean or not. This can be set by the include paths or /// by \#pragma gcc system_header. This is an instance of /// SrcMgr::CharacteristicKind. - unsigned DirInfo : 2; + unsigned DirInfo : 3; /// \brief Whether this header file info was supplied by an external source, /// and has not changed since. diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 737f6fb3d413..9b94aadd767f 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -1146,6 +1146,7 @@ class ASTReader time_t StoredTime; bool Overridden; bool Transient; + bool TopLevelModuleMap; }; /// \brief Reads the stored information about an input file. @@ -2249,6 +2250,12 @@ class ASTReader llvm::function_ref Visitor); + /// Visit all the top-level module maps loaded when building the given module + /// file. + void visitTopLevelModuleMaps(serialization::ModuleFile &MF, + llvm::function_ref< + void(const FileEntry *)> Visitor); + bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index e5da2ae4f22e..3b5335478dbf 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -825,8 +825,11 @@ bool CompilerInstance::InitializeSourceManager( const FrontendInputFile &Input, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr, HeaderSearch *HS, DependencyOutputOptions &DepOpts, const FrontendOptions &Opts) { - SrcMgr::CharacteristicKind - Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User; + SrcMgr::CharacteristicKind Kind = + Input.getKind().getFormat() == InputKind::ModuleMap + ? Input.isSystem() ? SrcMgr::C_System_ModuleMap + : SrcMgr::C_User_ModuleMap + : Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User; if (Input.isBuffer()) { SourceMgr.setMainFileID(SourceMgr.createFileID( diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index bd14c53e4d15..561eb9c4a316 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -55,8 +55,8 @@ struct DepCollectorPPCallbacks : public PPCallbacks { llvm::sys::path::remove_leading_dotslash(FE->getName()); DepCollector.maybeAddDependency(Filename, /*FromModule*/false, - FileType != SrcMgr::C_User, - /*IsModuleFile*/false, /*IsMissing*/false); + isSystem(FileType), + /*IsModuleFile*/false, /*IsMissing*/false); } void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, @@ -265,7 +265,7 @@ bool DFGImpl::FileMatchesDepCriteria(const char *Filename, if (IncludeSystemHeaders) return true; - return FileType == SrcMgr::C_User; + return !isSystem(FileType); } void DFGImpl::FileChanged(SourceLocation Loc, diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index f81a06b31869..eed8631bdb8c 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -200,12 +200,12 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, /// /// \param CI The compiler instance. /// \param InputFile Populated with the filename from the line marker. -/// \param AddLineNote If \c true, add a line note corresponding to this line -/// directive. Only use this if the directive will not actually be -/// visited by the preprocessor. +/// \param IsModuleMap If \c true, add a line note corresponding to this line +/// directive. (We need to do this because the directive will not be +/// visited by the preprocessor.) static SourceLocation ReadOriginalFileName(CompilerInstance &CI, std::string &InputFile, - bool AddLineNote = false) { + bool IsModuleMap = false) { auto &SourceMgr = CI.getSourceManager(); auto MainFileID = SourceMgr.getMainFileID(); @@ -231,7 +231,7 @@ static SourceLocation ReadOriginalFileName(CompilerInstance &CI, unsigned LineNo; SourceLocation LineNoLoc = T.getLocation(); - if (AddLineNote) { + if (IsModuleMap) { llvm::SmallString<16> Buffer; if (Lexer::getSpelling(LineNoLoc, Buffer, SourceMgr, CI.getLangOpts()) .getAsInteger(10, LineNo)) @@ -250,10 +250,10 @@ static SourceLocation ReadOriginalFileName(CompilerInstance &CI, return SourceLocation(); InputFile = Literal.GetString().str(); - if (AddLineNote) + if (IsModuleMap) CI.getSourceManager().AddLineNote( LineNoLoc, LineNo, SourceMgr.getLineTableFilenameID(InputFile), false, - false, SrcMgr::C_User); + false, SrcMgr::C_User_ModuleMap); return T.getLocation(); } @@ -403,7 +403,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, Offset = 0; if (IsPreprocessed) { SourceLocation EndOfLineMarker = - ReadOriginalFileName(CI, PresumedModuleMapFile, /*AddLineNote*/true); + ReadOriginalFileName(CI, PresumedModuleMapFile, /*IsModuleMap*/ true); if (EndOfLineMarker.isValid()) Offset = CI.getSourceManager().getDecomposedLoc(EndOfLineMarker).second; } @@ -547,21 +547,29 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, CI.getPreprocessorOpts() = AST->getPreprocessorOpts(); CI.getLangOpts() = AST->getLangOpts(); - // Preload all the module files loaded transitively by the AST unit. - if (auto ASTReader = AST->getASTReader()) { - auto &MM = ASTReader->getModuleManager(); - for (ModuleFile &MF : MM) - if (&MF != &MM.getPrimaryModule()) - CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName); - } - // FIXME: Preload module maps loaded by the AST unit. - // Set the shared objects, these are reset when we finish processing the // file, otherwise the CompilerInstance will happily destroy them. CI.setFileManager(&AST->getFileManager()); CI.createSourceManager(CI.getFileManager()); CI.getSourceManager().initializeForReplay(AST->getSourceManager()); + // Preload all the module files loaded transitively by the AST unit. Also + // load all module map files that were parsed as part of building the AST + // unit. + if (auto ASTReader = AST->getASTReader()) { + auto &MM = ASTReader->getModuleManager(); + auto &PrimaryModule = MM.getPrimaryModule(); + + for (ModuleFile &MF : MM) + if (&MF != &PrimaryModule) + CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName); + + ASTReader->visitTopLevelModuleMaps(PrimaryModule, + [&](const FileEntry *FE) { + CI.getFrontendOpts().ModuleMapFiles.push_back(FE->getName()); + }); + } + // Set up the input file for replay purposes. auto Kind = AST->getInputKind(); if (Kind.getFormat() == InputKind::ModuleMap) { diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 018d59e5e871..40f78ce25ceb 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -2710,7 +2710,8 @@ bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem, // If the module map file wasn't already entered, do so now. if (ID.isInvalid()) { - auto FileCharacter = IsSystem ? SrcMgr::C_System : SrcMgr::C_User; + auto FileCharacter = + IsSystem ? SrcMgr::C_System_ModuleMap : SrcMgr::C_User_ModuleMap; ID = SourceMgr.createFileID(File, ExternModuleLoc, FileCharacter); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 7c9ff0912578..fab7539aaa68 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1398,8 +1398,7 @@ bool ASTReader::ReadSLocEntry(int ID) { } const SrcMgr::ContentCache *ContentCache - = SourceMgr.getOrCreateContentCache(File, - /*isSystemFile=*/FileCharacter != SrcMgr::C_User); + = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); if (OverriddenBuffer && !ContentCache->BufferOverridden && ContentCache->ContentsEntry == ContentCache->OrigEntry && !ContentCache->getRawBuffer()) { @@ -1697,9 +1696,9 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, HeaderFileInfo HFI; unsigned Flags = *d++; // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. - HFI.isImport |= (Flags >> 4) & 0x01; - HFI.isPragmaOnce |= (Flags >> 3) & 0x01; - HFI.DirInfo = (Flags >> 1) & 0x03; + HFI.isImport |= (Flags >> 5) & 0x01; + HFI.isPragmaOnce |= (Flags >> 4) & 0x01; + HFI.DirInfo = (Flags >> 1) & 0x07; HFI.IndexHeaderMapHeader = Flags & 0x01; // FIXME: Find a better way to handle this. Maybe just store a // "has been included" flag? @@ -2029,6 +2028,7 @@ ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { R.StoredTime = static_cast(Record[2]); R.Overridden = static_cast(Record[3]); R.Transient = static_cast(Record[4]); + R.TopLevelModuleMap = static_cast(Record[5]); R.Filename = Blob; ResolveImportedPath(F, R.Filename); return R; @@ -8909,6 +8909,19 @@ void ASTReader::visitInputFiles(serialization::ModuleFile &MF, } } +void ASTReader::visitTopLevelModuleMaps( + serialization::ModuleFile &MF, + llvm::function_ref Visitor) { + unsigned NumInputs = MF.InputFilesLoaded.size(); + for (unsigned I = 0; I < NumInputs; ++I) { + InputFileInfo IFI = readInputFileInfo(MF, I + 1); + if (IFI.TopLevelModuleMap) + // FIXME: This unnecessarily re-reads the InputFileInfo. + if (auto *FE = getInputFile(MF, I + 1).getFile()) + Visitor(FE); + } +} + std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { // If we know the owning module, use it. if (Module *M = D->getImportedOwningModule()) diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 1c0db14ced14..c6129d326cb6 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1692,6 +1692,7 @@ namespace { bool IsSystemFile; bool IsTransient; bool BufferOverridden; + bool IsTopLevelModuleMap; }; } // end anonymous namespace @@ -1710,6 +1711,7 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient + IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); @@ -1724,7 +1726,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, // We only care about file entries that were not overridden. if (!SLoc->isFile()) continue; - const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); + const SrcMgr::FileInfo &File = SLoc->getFile(); + const SrcMgr::ContentCache *Cache = File.getContentCache(); if (!Cache->OrigEntry) continue; @@ -1733,6 +1736,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, Entry.IsSystemFile = Cache->IsSystemFile; Entry.IsTransient = Cache->IsTransient; Entry.BufferOverridden = Cache->BufferOverridden; + Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) && + File.getIncludeLoc().isInvalid(); if (Cache->IsSystemFile) SortedFiles.push_back(Entry); else @@ -1763,7 +1768,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, (uint64_t)Entry.File->getSize(), (uint64_t)getTimestampForOutput(Entry.File), Entry.BufferOverridden, - Entry.IsTransient}; + Entry.IsTransient, + Entry.IsTopLevelModuleMap}; EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); } @@ -1798,7 +1804,7 @@ static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives // FileEntry fields. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID @@ -1817,7 +1823,7 @@ static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob return Stream.EmitAbbrev(std::move(Abbrev)); @@ -1925,8 +1931,8 @@ namespace { endian::Writer LE(Out); uint64_t Start = Out.tell(); (void)Start; - unsigned char Flags = (Data.HFI.isImport << 4) - | (Data.HFI.isPragmaOnce << 3) + unsigned char Flags = (Data.HFI.isImport << 5) + | (Data.HFI.isPragmaOnce << 4) | (Data.HFI.DirInfo << 1) | Data.HFI.IndexHeaderMapHeader; LE.write(Flags); diff --git a/test/Modules/Inputs/preprocess-decluse/a.h b/test/Modules/Inputs/preprocess-decluse/a.h new file mode 100644 index 000000000000..17ab46c84892 --- /dev/null +++ b/test/Modules/Inputs/preprocess-decluse/a.h @@ -0,0 +1 @@ +// a.h diff --git a/test/Modules/Inputs/preprocess-decluse/a.modulemap b/test/Modules/Inputs/preprocess-decluse/a.modulemap new file mode 100644 index 000000000000..47105fe36399 --- /dev/null +++ b/test/Modules/Inputs/preprocess-decluse/a.modulemap @@ -0,0 +1 @@ +module A { textual header "a.h" } diff --git a/test/Modules/Inputs/preprocess-decluse/b.h b/test/Modules/Inputs/preprocess-decluse/b.h new file mode 100644 index 000000000000..2243de1baf9a --- /dev/null +++ b/test/Modules/Inputs/preprocess-decluse/b.h @@ -0,0 +1 @@ +#include "a.h" diff --git a/test/Modules/Inputs/preprocess-decluse/b.modulemap b/test/Modules/Inputs/preprocess-decluse/b.modulemap new file mode 100644 index 000000000000..bd0bdf0e2e94 --- /dev/null +++ b/test/Modules/Inputs/preprocess-decluse/b.modulemap @@ -0,0 +1 @@ +module B { header "b.h" use A } diff --git a/test/Modules/Inputs/preprocess-decluse/main.modulemap b/test/Modules/Inputs/preprocess-decluse/main.modulemap new file mode 100644 index 000000000000..0392c846ce99 --- /dev/null +++ b/test/Modules/Inputs/preprocess-decluse/main.modulemap @@ -0,0 +1 @@ +module Main { use B } diff --git a/test/Modules/preprocess-decluse.cpp b/test/Modules/preprocess-decluse.cpp new file mode 100644 index 000000000000..5c87e0dddac2 --- /dev/null +++ b/test/Modules/preprocess-decluse.cpp @@ -0,0 +1,18 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fmodules-strict-decluse -I%S/Inputs/preprocess-decluse \ +// RUN: -fmodule-name=B -emit-module -o %t/b.pcm \ +// RUN: -fmodule-map-file=%S/Inputs/preprocess-decluse/a.modulemap \ +// RUN: -x c++-module-map %S/Inputs/preprocess-decluse/b.modulemap +// RUN: %clang_cc1 -fmodules -fmodules-strict-decluse -I%S/Inputs/preprocess-decluse \ +// RUN: -fmodule-map-file=%S/Inputs/preprocess-decluse/main.modulemap \ +// RUN: -fmodule-file=%t/b.pcm -fmodule-name=Main %s -verify +// RUN: %clang_cc1 -fmodules -fmodules-strict-decluse -I%S/Inputs/preprocess-decluse \ +// RUN: -fmodule-map-file=%S/Inputs/preprocess-decluse/main.modulemap \ +// RUN: -fmodule-file=%t/b.pcm -fmodule-name=Main %s \ +// RUN: -E -frewrite-imports -o %t/rewrite.ii +// RUN: %clang_cc1 -fmodules -fmodules-strict-decluse -I%S/Inputs/preprocess-decluse \ +// RUN: -fmodule-map-file=%S/Inputs/preprocess-decluse/main.modulemap \ +// RUN: -fmodule-name=Main %t/rewrite.ii -verify + +// expected-no-diagnostics +#include "b.h" From 7416a3a78f99e02775d0e75dbe37f2fc103d7bae Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Thu, 29 Jun 2017 06:53:13 +0000 Subject: [PATCH 110/214] Factor out a functionality from isBeforeInTranslationUnit The first user of this API will be the cross translation unit functionality of the Static Analyzer which will be committed in a follow-up patch. Differential Revision: https://reviews.llvm.org/D34506 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306648 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 11 ++++ lib/Basic/SourceManager.cpp | 85 ++++++++++++++++------------- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index e658af742e5c..ed3f8dfa86e7 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -1489,6 +1489,17 @@ class SourceManager : public RefCountedBase { /// \returns true if LHS source location comes before RHS, false otherwise. bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const; + /// \brief Determines whether the two decomposed source location is in the + /// same translation unit. As a byproduct, it also calculates the order + /// of the source locations in case they are in the same TU. + /// + /// \returns Pair of bools the first component is true if the two locations + /// are in the same TU. The second bool is true if the first is true + /// and \p LOffs is before \p ROffs. + std::pair + isInTheSameTranslationUnit(std::pair &LOffs, + std::pair &ROffs) const; + /// \brief Determines the order of 2 source locations in the "source location /// address space". bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const { diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 3936afab21a4..f0b53b4e48a5 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -2018,9 +2018,51 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, if (LOffs.first.isInvalid() || ROffs.first.isInvalid()) return LOffs.first.isInvalid() && !ROffs.first.isInvalid(); + std::pair InSameTU = isInTheSameTranslationUnit(LOffs, ROffs); + if (InSameTU.first) + return InSameTU.second; + + // If we arrived here, the location is either in a built-ins buffer or + // associated with global inline asm. PR5662 and PR22576 are examples. + + StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); + StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); + bool LIsBuiltins = LB == ""; + bool RIsBuiltins = RB == ""; + // Sort built-in before non-built-in. + if (LIsBuiltins || RIsBuiltins) { + if (LIsBuiltins != RIsBuiltins) + return LIsBuiltins; + // Both are in built-in buffers, but from different files. We just claim that + // lower IDs come first. + return LOffs.first < ROffs.first; + } + bool LIsAsm = LB == ""; + bool RIsAsm = RB == ""; + // Sort assembler after built-ins, but before the rest. + if (LIsAsm || RIsAsm) { + if (LIsAsm != RIsAsm) + return RIsAsm; + assert(LOffs.first == ROffs.first); + return false; + } + bool LIsScratch = LB == ""; + bool RIsScratch = RB == ""; + // Sort scratch after inline asm, but before the rest. + if (LIsScratch || RIsScratch) { + if (LIsScratch != RIsScratch) + return LIsScratch; + return LOffs.second < ROffs.second; + } + llvm_unreachable("Unsortable locations found"); +} + +std::pair SourceManager::isInTheSameTranslationUnit( + std::pair &LOffs, + std::pair &ROffs) const { // If the source locations are in the same file, just compare offsets. if (LOffs.first == ROffs.first) - return LOffs.second < ROffs.second; + return std::make_pair(true, LOffs.second < ROffs.second); // If we are comparing a source location with multiple locations in the same // file, we get a big win by caching the result. @@ -2030,7 +2072,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // If we are comparing a source location with multiple locations in the same // file, we get a big win by caching the result. if (IsBeforeInTUCache.isCacheValid(LOffs.first, ROffs.first)) - return IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second); + return std::make_pair( + true, IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second)); // Okay, we missed in the cache, start updating the cache for this query. IsBeforeInTUCache.setQueryFIDs(LOffs.first, ROffs.first, @@ -2060,44 +2103,12 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // locations within the common file and cache them. if (LOffs.first == ROffs.first) { IsBeforeInTUCache.setCommonLoc(LOffs.first, LOffs.second, ROffs.second); - return IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second); + return std::make_pair( + true, IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second)); } - - // If we arrived here, the location is either in a built-ins buffer or - // associated with global inline asm. PR5662 and PR22576 are examples. - // Clear the lookup cache, it depends on a common location. IsBeforeInTUCache.clear(); - StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); - StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); - bool LIsBuiltins = LB == ""; - bool RIsBuiltins = RB == ""; - // Sort built-in before non-built-in. - if (LIsBuiltins || RIsBuiltins) { - if (LIsBuiltins != RIsBuiltins) - return LIsBuiltins; - // Both are in built-in buffers, but from different files. We just claim that - // lower IDs come first. - return LOffs.first < ROffs.first; - } - bool LIsAsm = LB == ""; - bool RIsAsm = RB == ""; - // Sort assembler after built-ins, but before the rest. - if (LIsAsm || RIsAsm) { - if (LIsAsm != RIsAsm) - return RIsAsm; - assert(LOffs.first == ROffs.first); - return false; - } - bool LIsScratch = LB == ""; - bool RIsScratch = RB == ""; - // Sort scratch after inline asm, but before the rest. - if (LIsScratch || RIsScratch) { - if (LIsScratch != RIsScratch) - return LIsScratch; - return LOffs.second < ROffs.second; - } - llvm_unreachable("Unsortable locations found"); + return std::make_pair(false, false); } void SourceManager::PrintStats() const { From 322c1b35469ef0209f1348e90805e613c29bef5c Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Thu, 29 Jun 2017 08:44:10 +0000 Subject: [PATCH 111/214] [OpenCL] Allow function declaration with empty argument list. Summary: does it make sense to enable K&R function declaration style for OpenCL? clang throws following error message for the declaration w/o arguments: ``` int my_func(); error: function with no prototype cannot use the spir_function calling convention ``` Current way to fix this issue is to specify that parameter list is empty by using 'void': ``` int my_func(void); ``` Let me know what do you think about this patch. Reviewers: Anastasia, yaxunl Reviewed By: Anastasia Subscribers: cfe-commits, echuraev Differential Revision: https://reviews.llvm.org/D33681 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306653 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaType.cpp | 2 +- test/SemaOpenCL/function-no-args.cl | 9 +++++++++ test/SemaOpenCL/invalid-pipes-cl2.0.cl | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/SemaOpenCL/function-no-args.cl diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 8c8402e75e37..465e8d146dd2 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4355,7 +4355,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex)); - if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) { + if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus && !LangOpts.OpenCL) { // Simple void foo(), where the incoming T is the result type. T = Context.getFunctionNoProtoType(T, EI); } else { diff --git a/test/SemaOpenCL/function-no-args.cl b/test/SemaOpenCL/function-no-args.cl new file mode 100644 index 000000000000..12070a58580a --- /dev/null +++ b/test/SemaOpenCL/function-no-args.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s +// expected-no-diagnostics + +global int gi; +int my_func(); +int my_func() { + gi = 2; + return gi; +} diff --git a/test/SemaOpenCL/invalid-pipes-cl2.0.cl b/test/SemaOpenCL/invalid-pipes-cl2.0.cl index a50811650d2c..463fd3d0dabc 100644 --- a/test/SemaOpenCL/invalid-pipes-cl2.0.cl +++ b/test/SemaOpenCL/invalid-pipes-cl2.0.cl @@ -3,7 +3,7 @@ global pipe int gp; // expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}} global reserve_id_t rid; // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}} -extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int ()' can only be used as a function parameter in OpenCL}} +extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}} kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}} } From 3f3ec7612cf8bfa97841100cbf8a70b92d5c3c40 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 29 Jun 2017 10:43:44 +0000 Subject: [PATCH 112/214] [Tooling] FixedCompilationDatabase should be able to strip positional arguments when `-fsyntax-only` is used Previously, Clang failed to create a fixed compilation database when the compilation arguments use -fsyntax-only instead of -c. This commit fixes the issue by forcing Clang to look at the compilation job when stripping the positional arguments. Differential Revision: https://reviews.llvm.org/D34687 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306659 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/CompilationDatabase.cpp | 8 ++++--- unittests/Tooling/CompilationDatabaseTest.cpp | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 77c5b547ca09..0e835579e04e 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -255,10 +255,12 @@ static bool stripPositionalArgs(std::vector Args, CompileJobAnalyzer CompileAnalyzer; for (const auto &Cmd : Jobs) { - // Collect only for Assemble jobs. If we do all jobs we get duplicates - // since Link jobs point to Assemble jobs as inputs. - if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass) + // Collect only for Assemble and Compile jobs. If we do all jobs we get + // duplicates since Link jobs point to Assemble jobs as inputs. + if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass || + Cmd.getSource().getKind() == driver::Action::CompileJobClass) { CompileAnalyzer.run(&Cmd.getSource()); + } } if (CompileAnalyzer.Inputs.empty()) { diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp index 5a6693eb4dbb..fd8afe6b7976 100644 --- a/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/unittests/Tooling/CompilationDatabaseTest.cpp @@ -586,6 +586,27 @@ TEST(ParseFixedCompilationDatabase, HandlesPositionalArgs) { EXPECT_EQ(2, Argc); } +TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) { + // Adjust the given command line arguments to ensure that any positional + // arguments in them are stripped. + const char *Argv[] = {"--", "somefile.cpp", "-fsyntax-only", "-DDEF3"}; + int Argc = llvm::array_lengthof(Argv); + std::string ErrorMessage; + std::unique_ptr Database = + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMessage); + ASSERT_TRUE((bool)Database); + ASSERT_TRUE(ErrorMessage.empty()); + std::vector Result = Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + std::vector Expected; + Expected.push_back("clang-tool"); + Expected.push_back("-fsyntax-only"); + Expected.push_back("-DDEF3"); + Expected.push_back("source"); + ASSERT_EQ(Expected, Result[0].CommandLine); +} + TEST(ParseFixedCompilationDatabase, HandlesArgv0) { const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"}; int Argc = sizeof(Argv) / sizeof(char*); From ba2af70d9cfaddc5b8c2fa6e2a55387025b8f3ee Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 29 Jun 2017 10:47:23 +0000 Subject: [PATCH 113/214] Revert r306653, "[OpenCL] Allow function declaration with empty argument list." It broke bots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306660 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaType.cpp | 2 +- test/SemaOpenCL/function-no-args.cl | 9 --------- test/SemaOpenCL/invalid-pipes-cl2.0.cl | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 test/SemaOpenCL/function-no-args.cl diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 465e8d146dd2..8c8402e75e37 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4355,7 +4355,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex)); - if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus && !LangOpts.OpenCL) { + if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) { // Simple void foo(), where the incoming T is the result type. T = Context.getFunctionNoProtoType(T, EI); } else { diff --git a/test/SemaOpenCL/function-no-args.cl b/test/SemaOpenCL/function-no-args.cl deleted file mode 100644 index 12070a58580a..000000000000 --- a/test/SemaOpenCL/function-no-args.cl +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s -// expected-no-diagnostics - -global int gi; -int my_func(); -int my_func() { - gi = 2; - return gi; -} diff --git a/test/SemaOpenCL/invalid-pipes-cl2.0.cl b/test/SemaOpenCL/invalid-pipes-cl2.0.cl index 463fd3d0dabc..a50811650d2c 100644 --- a/test/SemaOpenCL/invalid-pipes-cl2.0.cl +++ b/test/SemaOpenCL/invalid-pipes-cl2.0.cl @@ -3,7 +3,7 @@ global pipe int gp; // expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}} global reserve_id_t rid; // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}} -extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}} +extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int ()' can only be used as a function parameter in OpenCL}} kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}} } From 1747f04c528f04f9daa2d77885cc3c27d2553674 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Thu, 29 Jun 2017 13:30:41 +0000 Subject: [PATCH 114/214] [clang-format] Fix parsing of msg{field}-style proto options Summary: This patch makes the `{` in `msg_field{field: OK}` in a proto option scope be treated as an assignment operator. Previosly the added test case was formatted as: ``` option (MyProto.options) = { field_a: OK field_b{field_c: OK} field_d: OKOKOK field_e: OK } ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34749 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306672 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 6 ++++-- unittests/Format/FormatTestProto.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 767096b60ef2..d78a37532fe8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1570,8 +1570,10 @@ class ExpressionParser { const FormatToken *NextNonComment = Current->getNextNonComment(); if (Current->is(TT_ConditionalExpr)) return prec::Conditional; - if (NextNonComment && NextNonComment->is(tok::colon) && - NextNonComment->is(TT_DictLiteral)) + if (NextNonComment && Current->is(TT_SelectorName) && + (NextNonComment->is(TT_DictLiteral) || + (Style.Language == FormatStyle::LK_Proto && + NextNonComment->is(tok::less)))) return prec::Assignment; if (Current->is(TT_JsComputedPropertyName)) return prec::Assignment; diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 0b052bd4c649..2e3b9311d12c 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -201,6 +201,12 @@ TEST_F(FormatTestProto, FormatsOptions) { " field_c: \"OK\"\n" " msg_field{field_d: 123}\n" "};"); + verifyFormat("option (MyProto.options) = {\n" + " field_a: OK\n" + " field_b{field_c: OK}\n" + " field_d: OKOKOK\n" + " field_e: OK\n" + "}"); // Support syntax with <> instead of {}. verifyFormat("option (MyProto.options) = {\n" @@ -208,6 +214,13 @@ TEST_F(FormatTestProto, FormatsOptions) { " msg_field: \n" "};"); + verifyFormat("option (MyProto.options) = {\n" + " field_a: OK\n" + " field_b\n" + " field_d: OKOKOK\n" + " field_e: OK\n" + "}"); + verifyFormat("option (MyProto.options) = {\n" " msg_field: <>\n" " field_c: \"OK\",\n" From e3c11765ca248ea8e62227e52e53aa1ec8983a52 Mon Sep 17 00:00:00 2001 From: Michael Zuckerman Date: Thu, 29 Jun 2017 13:41:04 +0000 Subject: [PATCH 115/214] [Clang][X86][Goldmont]Adding new target-cpu: Goldmont [Clang-side] Connecting the GoldMont processor to his feature. Reviewers: 1. igorb 2. delena 3. zvi Differential Revision: https://reviews.llvm.org/D34807 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306673 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 21 +++++++ test/Preprocessor/predefined-arch-macros.c | 73 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 02ded70b2011..840cb1228b65 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -2737,6 +2737,7 @@ class X86TargetInfo : public TargetInfo { //@{ CK_Bonnell, CK_Silvermont, + CK_Goldmont, //@} /// \name Nehalem @@ -2878,6 +2879,7 @@ class X86TargetInfo : public TargetInfo { .Case("atom", CK_Bonnell) // Legacy name. .Case("silvermont", CK_Silvermont) .Case("slm", CK_Silvermont) // Legacy name. + .Case("goldmont", CK_Goldmont) .Case("nehalem", CK_Nehalem) .Case("corei7", CK_Nehalem) // Legacy name. .Case("westmere", CK_Westmere) @@ -3093,6 +3095,7 @@ class X86TargetInfo : public TargetInfo { case CK_Penryn: case CK_Bonnell: case CK_Silvermont: + case CK_Goldmont: case CK_Nehalem: case CK_Westmere: case CK_SandyBridge: @@ -3285,6 +3288,21 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "fxsr", true); setFeatureEnabledImpl(Features, "cx16", true); break; + case CK_Goldmont: + setFeatureEnabledImpl(Features, "sha", true); + setFeatureEnabledImpl(Features, "rdseed", true); + setFeatureEnabledImpl(Features, "xsave", true); + setFeatureEnabledImpl(Features, "xsaveopt", true); + setFeatureEnabledImpl(Features, "xsavec", true); + setFeatureEnabledImpl(Features, "xsaves", true); + setFeatureEnabledImpl(Features, "clflushopt", true); + setFeatureEnabledImpl(Features, "mpx", true); + setFeatureEnabledImpl(Features, "aes", true); + setFeatureEnabledImpl(Features, "pclmul", true); + setFeatureEnabledImpl(Features, "sse4.2", true); + setFeatureEnabledImpl(Features, "fxsr", true); + setFeatureEnabledImpl(Features, "cx16", true); + break; case CK_KNL: setFeatureEnabledImpl(Features, "avx512f", true); setFeatureEnabledImpl(Features, "avx512cd", true); @@ -3893,6 +3911,9 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, case CK_Silvermont: defineCPUMacros(Builder, "slm"); break; + case CK_Goldmont: + defineCPUMacros(Builder, "goldmont"); + break; case CK_Nehalem: case CK_Westmere: case CK_SandyBridge: diff --git a/test/Preprocessor/predefined-arch-macros.c b/test/Preprocessor/predefined-arch-macros.c index 08f4d2573f40..146d005f3f96 100644 --- a/test/Preprocessor/predefined-arch-macros.c +++ b/test/Preprocessor/predefined-arch-macros.c @@ -986,6 +986,79 @@ // CHECK_ATOM_M64: #define __x86_64 1 // CHECK_ATOM_M64: #define __x86_64__ 1 // +// RUN: %clang -march=goldmont -m32 -E -dM %s -o - 2>&1 \ +// RUN: -target i386-unknown-linux \ +// RUN: | FileCheck %s -check-prefix=CHECK_GLM_M32 +// CHECK_GLM_M32: #define __AES__ 1 +// CHECK_GLM_M32: #define __CLFLUSHOPT__ 1 +// CHECK_GLM_M32: #define __FXSR__ 1 +// CHECK_GLM_M32: #define __MMX__ 1 +// CHECK_GLM_M32: #define __MPX__ 1 +// CHECK_GLM_M32: #define __PCLMUL__ 1 +// CHECK_GLM_M32: #define __POPCNT__ 1 +// CHECK_GLM_M32: #define __RDSEED__ 1 +// CHECK_GLM_M32: #define __SHA__ 1 +// CHECK_GLM_M32: #define __SSE2__ 1 +// CHECK_GLM_M32: #define __SSE3__ 1 +// CHECK_GLM_M32: #define __SSE4_1__ 1 +// CHECK_GLM_M32: #define __SSE4_2__ 1 +// CHECK_GLM_M32: #define __SSE_MATH__ 1 +// CHECK_GLM_M32: #define __SSE__ 1 +// CHECK_GLM_M32: #define __SSSE3__ 1 +// CHECK_GLM_M32: #define __XSAVEC__ 1 +// CHECK_GLM_M32: #define __XSAVEOPT__ 1 +// CHECK_GLM_M32: #define __XSAVES__ 1 +// CHECK_GLM_M32: #define __XSAVE__ 1 +// CHECK_GLM_M32: #define __clang__ 1 +// CHECK_GLM_M32: #define __goldmont 1 +// CHECK_GLM_M32: #define __goldmont__ 1 +// CHECK_GLM_M32: #define __i386 1 +// CHECK_GLM_M32: #define __i386__ 1 +// CHECK_GLM_M32: #define __linux 1 +// CHECK_GLM_M32: #define __linux__ 1 +// CHECK_GLM_M32: #define __llvm__ 1 +// CHECK_GLM_M32: #define __tune_goldmont__ 1 +// CHECK_GLM_M32: #define __unix 1 +// CHECK_GLM_M32: #define __unix__ 1 +// CHECK_GLM_M32: #define i386 1 +// CHECK_GLM_M32: #define linux 1 +// CHECK_GLM_M32: #define unix 1 +// +// RUN: %clang -march=goldmont -m64 -E -dM %s -o - 2>&1 \ +// RUN: -target i386-unknown-linux \ +// RUN: | FileCheck %s -check-prefix=CHECK_GLM_M64 +// CHECK_GLM_M64: #define __AES__ 1 +// CHECK_GLM_M64: #define __CLFLUSHOPT__ 1 +// CHECK_GLM_M64: #define __FXSR__ 1 +// CHECK_GLM_M64: #define __MMX__ 1 +// CHECK_GLM_M64: #define __MPX__ 1 +// CHECK_GLM_M64: #define __PCLMUL__ 1 +// CHECK_GLM_M64: #define __POPCNT__ 1 +// CHECK_GLM_M64: #define __RDSEED__ 1 +// CHECK_GLM_M64: #define __SSE2__ 1 +// CHECK_GLM_M64: #define __SSE3__ 1 +// CHECK_GLM_M64: #define __SSE4_1__ 1 +// CHECK_GLM_M64: #define __SSE4_2__ 1 +// CHECK_GLM_M64: #define __SSE__ 1 +// CHECK_GLM_M64: #define __SSSE3__ 1 +// CHECK_GLM_M64: #define __XSAVEC__ 1 +// CHECK_GLM_M64: #define __XSAVEOPT__ 1 +// CHECK_GLM_M64: #define __XSAVES__ 1 +// CHECK_GLM_M64: #define __XSAVE__ 1 +// CHECK_GLM_M64: #define __gnu_linux__ 1 +// CHECK_GLM_M64: #define __goldmont 1 +// CHECK_GLM_M64: #define __goldmont__ 1 +// CHECK_GLM_M64: #define __linux 1 +// CHECK_GLM_M64: #define __linux__ 1 +// CHECK_GLM_M64: #define __llvm__ 1 +// CHECK_GLM_M64: #define __tune_goldmont__ 1 +// CHECK_GLM_M64: #define __unix 1 +// CHECK_GLM_M64: #define __unix__ 1 +// CHECK_GLM_M64: #define __x86_64 1 +// CHECK_GLM_M64: #define __x86_64__ 1 +// CHECK_GLM_M64: #define linux 1 +// CHECK_GLM_M64: #define unix 1 +// // RUN: %clang -march=slm -m32 -E -dM %s -o - 2>&1 \ // RUN: -target i386-unknown-linux \ // RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SLM_M32 From c416cf246dff9ab857956c210eefd5690054f818 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 29 Jun 2017 14:18:26 +0000 Subject: [PATCH 116/214] Fix NSAPI constants to reflect the current state of NSStringMethodKind/NSDictionaryMethodKind enums Patch by Vladimir Voskresensky! Differential Revision: https://reviews.llvm.org/D34766 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306680 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/NSAPI.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/NSAPI.h b/include/clang/AST/NSAPI.h index 583f9d9f1deb..3757116e7c70 100644 --- a/include/clang/AST/NSAPI.h +++ b/include/clang/AST/NSAPI.h @@ -49,7 +49,7 @@ class NSAPI { NSStr_initWithString, NSStr_initWithUTF8String }; - static const unsigned NumNSStringMethods = 5; + static const unsigned NumNSStringMethods = 6; IdentifierInfo *getNSClassId(NSClassIdKindKind K) const; @@ -112,7 +112,7 @@ class NSAPI { NSMutableDict_setObjectForKeyedSubscript, NSMutableDict_setValueForKey }; - static const unsigned NumNSDictionaryMethods = 14; + static const unsigned NumNSDictionaryMethods = 13; /// \brief The Objective-C NSDictionary selectors. Selector getNSDictionarySelector(NSDictionaryMethodKind MK) const; From 71607099bc1e9bc3e004f173540e47cba906e1b8 Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Thu, 29 Jun 2017 15:49:03 +0000 Subject: [PATCH 117/214] [OpenMP] Add support for auxiliary triple specification Summary: Device offloading requires the specification of an additional flag containing the triple of the //other// architecture the code is being compiled on if such an architecture exists. If compiling for the host, the auxiliary triple flag will contain the triple describing the device and vice versa. Reviewers: arpith-jacob, sfantao, caomhin, carlo.bertolli, ABataev, Hahnfeld, jlebar, hfinkel, tstellar Reviewed By: Hahnfeld Subscribers: rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D29339 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306689 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Clang.cpp | 17 +++++++++ lib/Frontend/CompilerInstance.cpp | 5 +-- lib/Frontend/CompilerInvocation.cpp | 4 +++ lib/Frontend/InitPreprocessor.cpp | 2 +- test/Driver/openmp-offload.c | 56 ++++++++++++++--------------- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 072d62346cdc..3b9805b5a925 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -129,6 +129,13 @@ forAllAssociatedToolChains(Compilation &C, const JobAction &JA, else if (JA.isDeviceOffloading(Action::OFK_Cuda)) Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_OpenMP)) { + auto TCs = C.getOffloadToolChains(); + for (auto II = TCs.first, IE = TCs.second; II != IE; ++II) + Work(*II->second); + } else if (JA.isDeviceOffloading(Action::OFK_OpenMP)) + Work(*C.getSingleOffloadToolChain()); + // // TODO: Add support for other offloading programming models here. // @@ -1992,6 +1999,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(NormalizedTriple)); } + if (IsOpenMPDevice) { + // We have to pass the triple of the host if compiling for an OpenMP device. + std::string NormalizedTriple = + C.getSingleOffloadToolChain() + ->getTriple() + .normalize(); + CmdArgs.push_back("-aux-triple"); + CmdArgs.push_back(Args.MakeArgString(NormalizedTriple)); + } + if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm || Triple.getArch() == llvm::Triple::thumb)) { unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 3b5335478dbf..9be5f9cd1bd9 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -936,8 +936,9 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { if (!hasTarget()) return false; - // Create TargetInfo for the other side of CUDA compilation. - if (getLangOpts().CUDA && !getFrontendOpts().AuxTriple.empty()) { + // Create TargetInfo for the other side of CUDA and OpenMP compilation. + if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) && + !getFrontendOpts().AuxTriple.empty()) { auto TO = std::make_shared(); TO->Triple = getFrontendOpts().AuxTriple; TO->HostTriple = getTarget().getTriple().str(); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 6254b0013bab..c49fda975241 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2644,6 +2644,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple; } + // Set the triple of the host for OpenMP device compile. + if (LangOpts.OpenMPIsDevice) + Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple; + // FIXME: Override value name discarding when asan or msan is used because the // backend passes depend on the name of the alloca in order to print out // names. diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 08befb33c962..71420df00025 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -1043,7 +1043,7 @@ void clang::InitializePreprocessor( if (InitOpts.UsePredefines) { // FIXME: This will create multiple definitions for most of the predefined // macros. This is not the right way to handle this. - if (LangOpts.CUDA && PP.getAuxTargetInfo()) + if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo()) InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, Builder); diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index 39eb41e6ac08..23851738d86f 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -250,15 +250,15 @@ // // Compile for the powerpc device. // -// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-SAME: [[T1OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" // CHK-COMMANDS: ld{{(\.exe)?}}" {{.*}}"-o" " // CHK-COMMANDS-SAME: [[T1BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T1OBJ]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T1PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T1BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T1ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T1BC]]" // CHK-COMMANDS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le-ibm-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T1OBJ:[^\\/]+\.o]]" "{{.*}}[[T1ASM]]" @@ -267,15 +267,15 @@ // // Compile for the x86 device. // -// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-SAME: [[T2OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" // CHK-COMMANDS: ld{{(\.exe)?}}" {{.*}}"-o" " // CHK-COMMANDS-SAME: [[T2BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T2OBJ]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T2PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T2BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T2ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T2BC]]" // CHK-COMMANDS-ST: clang{{.*}}" "-cc1as" "-triple" "x86_64-pc-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[T2OBJ:[^\\/]+\.o]]" "{{.*}}[[T2ASM]]" @@ -398,25 +398,25 @@ // CHK-BUJOBS-ST-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[HOSTPP]]" "-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" // Create target 1 object. -// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-SAME: [[T1OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T1PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T1BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T1ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T1BC]]" // CHK-BUJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le-ibm-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T1OBJ:[^\\/]+\.o]]" "{{.*}}[[T1ASM]]" // Create target 2 object. -// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-SAME: [[T2OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T2PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T2BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T2ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T2BC]]" // CHK-BUJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "x86_64-pc-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[T2OBJ:[^\\/]+\.o]]" "{{.*}}[[T2ASM]]" @@ -464,13 +464,13 @@ // CHK-UBJOBS-ST-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[HOSTPP]]" "-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" // Create target 1 object. -// CHK-UBJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-SAME: [[T1OBJ:[^\\/]+\.o]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" // CHK-UBJOBS: ld{{(\.exe)?}}" {{.*}}"-o" " // CHK-UBJOBS-SAME: [[T1BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T1OBJ]]" -// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T1BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T1ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T1BC]]" // CHK-UBJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le-ibm-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T1OBJ:[^\\/]+\.o]]" "{{.*}}[[T1ASM]]" @@ -478,13 +478,13 @@ // CHK-UBJOBS-ST-SAME: [[T1BIN:[^\\/]+\.out-openmp-powerpc64le-ibm-linux-gnu]]" {{.*}}"{{.*}}[[T1OBJ]]" // Create target 2 object. -// CHK-UBJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-SAME: [[T2OBJ:[^\\/]+\.o]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" // CHK-UBJOBS: ld{{(\.exe)?}}" {{.*}}"-o" " // CHK-UBJOBS-SAME: [[T2BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T2OBJ]]" -// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T2BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T2ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T2BC]]" // CHK-UBJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "x86_64-pc-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-UBJOBS-ST-SAME: [[T2OBJ:[^\\/]+\.o]]" "{{.*}}[[T2ASM]]" @@ -559,21 +559,21 @@ // CHK-UBUJOBS-ST-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[HOSTPP]]" "-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" // Create target 1 object. -// CHK-UBUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-SAME: [[T1OBJ:[^\\/]+\.o]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T1BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T1ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T1BC]]" // CHK-UBUJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le-ibm-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T1OBJ:[^\\/]+\.o]]" "{{.*}}[[T1ASM]]" // Create target 2 object. -// CHK-UBUJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-SAME: [[T2OBJ:[^\\/]+\.o]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T2BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]" -// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " +// CHK-UBUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T2ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T2BC]]" // CHK-UBUJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "x86_64-pc-linux-gnu" "-filetype" "obj" {{.*}}"-o" " // CHK-UBUJOBS-ST-SAME: [[T2OBJ:[^\\/]+\.o]]" "{{.*}}[[T2ASM]]" From 9959fc27fd0f4e66fcf1e67cb1a13e6f51df1ea2 Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Thu, 29 Jun 2017 15:59:19 +0000 Subject: [PATCH 118/214] [OpenMP] Pass -fopenmp-is-device to preprocessing and machine specific code generation stages Summary: The preprocessing and code generation and optimization stages of the compiler are also passed the "-fopenmp-is-device" flag. This is used to trigger machine specific preprocessing and code generation when performing device offloading to an NVIDIA GPU via OpenMP directives. Reviewers: arpith-jacob, caomhin, carlo.bertolli, Hahnfeld, hfinkel, tstellar Reviewed By: Hahnfeld Subscribers: Hahnfeld, rengolin Differential Revision: https://reviews.llvm.org/D29645 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306691 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Clang.cpp | 8 +++++--- test/Driver/openmp-offload.c | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 3b9805b5a925..9d222a21357a 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4429,10 +4429,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // device declarations can be identified. Also, -fopenmp-is-device is passed // along to tell the frontend that it is generating code for a device, so that // only the relevant declarations are emitted. - if (IsOpenMPDevice && Inputs.size() == 2) { + if (IsOpenMPDevice) { CmdArgs.push_back("-fopenmp-is-device"); - CmdArgs.push_back("-fopenmp-host-ir-file-path"); - CmdArgs.push_back(Args.MakeArgString(Inputs.back().getFilename())); + if (Inputs.size() == 2) { + CmdArgs.push_back("-fopenmp-host-ir-file-path"); + CmdArgs.push_back(Args.MakeArgString(Inputs.back().getFilename())); + } } // For all the host OpenMP offloading compile jobs we need to pass the targets diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index 23851738d86f..567f3fdf2239 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -589,3 +589,13 @@ // CHK-UBUJOBS-ST-SAME: [[HOSTOBJ:[^\\/]+\.o]]" "{{.*}}[[HOSTASM]]" // CHK-UBUJOBS-ST: clang-offload-bundler{{.*}}" "-type=o" "-targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu,host-powerpc64le--linux" "-outputs= // CHK-UBUJOBS-ST-SAME: [[RES:[^\\/]+\.o]]" "-inputs={{.*}}[[T1OBJ]],{{.*}}[[T2OBJ]],{{.*}}[[HOSTOBJ]]" + +/// ########################################################################### + +/// Check -fopenmp-is-device is also passed when generating the *.i and *.s intermediate files. +// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -save-temps -no-canonical-prefixes %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s + +// CHK-FOPENMP-IS-DEVICE: clang{{.*}}.i" {{.*}}" "-fopenmp-is-device" +// CHK-FOPENMP-IS-DEVICE-NEXT: clang{{.*}}.bc" {{.*}}.i" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" +// CHK-FOPENMP-IS-DEVICE-NEXT: clang{{.*}}.s" {{.*}}.bc" "-fopenmp-is-device" From e157d3d2a7e0fe44d93a769df905bccdfe293901 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 29 Jun 2017 16:08:10 +0000 Subject: [PATCH 119/214] Initialize variable and silence potentially uninitialized warning. Patch by Liza Sakellari! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306692 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Lookup.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index 9134ddf9198c..145355c5ec3d 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -465,10 +465,9 @@ class LookupResult { Paths = nullptr; } } else { - AmbiguityKind SavedAK; + AmbiguityKind SavedAK = Ambiguity; bool WasAmbiguous = false; if (ResultKind == Ambiguous) { - SavedAK = Ambiguity; WasAmbiguous = true; } ResultKind = Found; From afca04ace56897134f5e8e809c7e5dd2d5c7daa4 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 29 Jun 2017 16:43:05 +0000 Subject: [PATCH 120/214] [OPENMP][DEBUG] Generate second function with correct arg types. Currently, if the some of the parameters are captured by value, this argument is converted to uintptr_t type and thus we loosing the debug info about real type of the argument (captured variable): ``` void @.outlined_function.(uintptr %par); ... %a = alloca i32 %a.casted = alloca uintptr %cast = bitcast uintptr* %a.casted to i32* %a.val = load i32, i32 *%a store i32 %a.val, i32 *%cast %a.casted.val = load uintptr, uintptr* %a.casted call void @.outlined_function.(uintptr %a.casted.val) ... ``` To resolve this problem, in debug mode a speciall external wrapper function is generated, that calls the outlined function with the correct parameters types: ``` void @.wrapper.(uintptr %par) { %a = alloca i32 %cast = bitcast i32* %a to uintptr* store uintptr %par, uintptr *%cast %a.val = load i32, i32* %a call void @.outlined_function.(i32 %a) ret void } void @.outlined_function.(i32 %par); ... %a = alloca i32 %a.casted = alloca uintptr %cast = bitcast uintptr* %a.casted to i32* %a.val = load i32, i32 *%a store i32 %a.val, i32 *%cast %a.casted.val = load uintptr, uintptr* %a.casted call void @.wrapper.(uintptr %a.casted.val) ... ``` git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306697 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGOpenMPRuntime.cpp | 18 +- lib/CodeGen/CGStmtOpenMP.cpp | 203 ++- test/OpenMP/parallel_codegen.cpp | 4 +- test/OpenMP/target_codegen.cpp | 283 +-- test/OpenMP/target_codegen_global_capture.cpp | 143 +- test/OpenMP/target_data_codegen.cpp | 51 +- .../target_data_use_device_ptr_codegen.cpp | 113 +- test/OpenMP/target_enter_data_codegen.cpp | 51 +- test/OpenMP/target_exit_data_codegen.cpp | 51 +- test/OpenMP/target_firstprivate_codegen.cpp | 160 +- test/OpenMP/target_is_device_ptr_codegen.cpp | 112 +- test/OpenMP/target_map_codegen.cpp | 1600 +++++++++-------- test/OpenMP/target_parallel_codegen.cpp | 186 +- test/OpenMP/target_teams_codegen.cpp | 186 +- test/OpenMP/target_update_codegen.cpp | 53 +- 15 files changed, 1698 insertions(+), 1516 deletions(-) diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 0a8fd17c3324..3df95a4e9b2a 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -5927,16 +5927,11 @@ emitOffloadingArrays(CodeGenFunction &CGF, for (unsigned i = 0; i < Info.NumberOfPtrs; ++i) { llvm::Value *BPVal = *BasePointers[i]; - if (BPVal->getType()->isPointerTy()) - BPVal = CGF.Builder.CreateBitCast(BPVal, CGM.VoidPtrTy); - else { - assert(BPVal->getType()->isIntegerTy() && - "If not a pointer, the value type must be an integer."); - BPVal = CGF.Builder.CreateIntToPtr(BPVal, CGM.VoidPtrTy); - } llvm::Value *BP = CGF.Builder.CreateConstInBoundsGEP2_32( llvm::ArrayType::get(CGM.VoidPtrTy, Info.NumberOfPtrs), Info.BasePointersArray, 0, i); + BP = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( + BP, BPVal->getType()->getPointerTo(/*AddrSpace=*/0)); Address BPAddr(BP, Ctx.getTypeAlignInChars(Ctx.VoidPtrTy)); CGF.Builder.CreateStore(BPVal, BPAddr); @@ -5945,16 +5940,11 @@ emitOffloadingArrays(CodeGenFunction &CGF, Info.CaptureDeviceAddrMap.insert(std::make_pair(DevVD, BPAddr)); llvm::Value *PVal = Pointers[i]; - if (PVal->getType()->isPointerTy()) - PVal = CGF.Builder.CreateBitCast(PVal, CGM.VoidPtrTy); - else { - assert(PVal->getType()->isIntegerTy() && - "If not a pointer, the value type must be an integer."); - PVal = CGF.Builder.CreateIntToPtr(PVal, CGM.VoidPtrTy); - } llvm::Value *P = CGF.Builder.CreateConstInBoundsGEP2_32( llvm::ArrayType::get(CGM.VoidPtrTy, Info.NumberOfPtrs), Info.PointersArray, 0, i); + P = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( + P, PVal->getType()->getPointerTo(/*AddrSpace=*/0)); Address PAddr(P, Ctx.getTypeAlignInChars(Ctx.VoidPtrTy)); CGF.Builder.CreateStore(PVal, PAddr); diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index 77f3c332a12f..493cd627e418 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -239,21 +239,47 @@ static QualType getCanonicalParamType(ASTContext &C, QualType T) { return C.getCanonicalParamType(T); } -llvm::Function * -CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { - assert( - CapturedStmtInfo && - "CapturedStmtInfo should be set when generating the captured function"); - const CapturedDecl *CD = S.getCapturedDecl(); - const RecordDecl *RD = S.getCapturedRecordDecl(); +namespace { + /// Contains required data for proper outlined function codegen. + struct FunctionOptions { + /// Captured statement for which the function is generated. + const CapturedStmt *S = nullptr; + /// true if cast to/from UIntPtr is required for variables captured by + /// value. + bool UIntPtrCastRequired = true; + /// true if only casted argumefnts must be registered as local args or VLA + /// sizes. + bool RegisterCastedArgsOnly = false; + /// Name of the generated function. + StringRef FunctionName; + explicit FunctionOptions(const CapturedStmt *S, bool UIntPtrCastRequired, + bool RegisterCastedArgsOnly, + StringRef FunctionName) + : S(S), UIntPtrCastRequired(UIntPtrCastRequired), + RegisterCastedArgsOnly(UIntPtrCastRequired && RegisterCastedArgsOnly), + FunctionName(FunctionName) {} + }; +} + +static std::pair emitOutlinedFunctionPrologue( + CodeGenFunction &CGF, FunctionArgList &Args, + llvm::DenseMap> + &LocalAddrs, + llvm::DenseMap> + &VLASizes, + llvm::Value *&CXXThisValue, const FunctionOptions &FO) { + const CapturedDecl *CD = FO.S->getCapturedDecl(); + const RecordDecl *RD = FO.S->getCapturedRecordDecl(); assert(CD->hasBody() && "missing CapturedDecl body"); + CXXThisValue = nullptr; // Build the argument list. + CodeGenModule &CGM = CGF.CGM; ASTContext &Ctx = CGM.getContext(); - FunctionArgList Args; + bool HasUIntPtrArgs = false; Args.append(CD->param_begin(), std::next(CD->param_begin(), CD->getContextParamPosition())); - auto I = S.captures().begin(); + auto I = FO.S->captures().begin(); for (auto *FD : RD->fields()) { QualType ArgType = FD->getType(); IdentifierInfo *II = nullptr; @@ -265,23 +291,24 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { // deal with pointers. We can pass in the same way the VLA type sizes to the // outlined function. if ((I->capturesVariableByCopy() && !ArgType->isAnyPointerType()) || - I->capturesVariableArrayType()) - ArgType = Ctx.getUIntPtrType(); + I->capturesVariableArrayType()) { + HasUIntPtrArgs = true; + if (FO.UIntPtrCastRequired) + ArgType = Ctx.getUIntPtrType(); + } if (I->capturesVariable() || I->capturesVariableByCopy()) { CapVar = I->getCapturedVar(); II = CapVar->getIdentifier(); } else if (I->capturesThis()) - II = &getContext().Idents.get("this"); + II = &Ctx.Idents.get("this"); else { assert(I->capturesVariableArrayType()); - II = &getContext().Idents.get("vla"); + II = &Ctx.Idents.get("vla"); } - if (ArgType->isVariablyModifiedType()) { - ArgType = - getCanonicalParamType(getContext(), ArgType.getNonReferenceType()); - } - Args.push_back(ImplicitParamDecl::Create(getContext(), /*DC=*/nullptr, + if (ArgType->isVariablyModifiedType()) + ArgType = getCanonicalParamType(Ctx, ArgType.getNonReferenceType()); + Args.push_back(ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(), II, ArgType, ImplicitParamDecl::Other)); ++I; @@ -296,90 +323,166 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args); llvm::FunctionType *FuncLLVMTy = CGM.getTypes().GetFunctionType(FuncInfo); - llvm::Function *F = llvm::Function::Create( - FuncLLVMTy, llvm::GlobalValue::InternalLinkage, - CapturedStmtInfo->getHelperName(), &CGM.getModule()); + llvm::Function *F = + llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage, + FO.FunctionName, &CGM.getModule()); CGM.SetInternalFunctionAttributes(CD, F, FuncInfo); if (CD->isNothrow()) F->addFnAttr(llvm::Attribute::NoUnwind); // Generate the function. - StartFunction(CD, Ctx.VoidTy, F, FuncInfo, Args, CD->getLocation(), - CD->getBody()->getLocStart()); + CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, Args, CD->getLocation(), + CD->getBody()->getLocStart()); unsigned Cnt = CD->getContextParamPosition(); - I = S.captures().begin(); + I = FO.S->captures().begin(); for (auto *FD : RD->fields()) { // If we are capturing a pointer by copy we don't need to do anything, just // use the value that we get from the arguments. if (I->capturesVariableByCopy() && FD->getType()->isAnyPointerType()) { const VarDecl *CurVD = I->getCapturedVar(); - Address LocalAddr = GetAddrOfLocalVar(Args[Cnt]); + Address LocalAddr = CGF.GetAddrOfLocalVar(Args[Cnt]); // If the variable is a reference we need to materialize it here. if (CurVD->getType()->isReferenceType()) { - Address RefAddr = CreateMemTemp(CurVD->getType(), getPointerAlign(), - ".materialized_ref"); - EmitStoreOfScalar(LocalAddr.getPointer(), RefAddr, /*Volatile=*/false, - CurVD->getType()); + Address RefAddr = CGF.CreateMemTemp( + CurVD->getType(), CGM.getPointerAlign(), ".materialized_ref"); + CGF.EmitStoreOfScalar(LocalAddr.getPointer(), RefAddr, + /*Volatile=*/false, CurVD->getType()); LocalAddr = RefAddr; } - setAddrOfLocalVar(CurVD, LocalAddr); + if (!FO.RegisterCastedArgsOnly) + LocalAddrs.insert({Args[Cnt], {CurVD, LocalAddr}}); ++Cnt; ++I; continue; } LValueBaseInfo BaseInfo(AlignmentSource::Decl, false); - LValue ArgLVal = - MakeAddrLValue(GetAddrOfLocalVar(Args[Cnt]), Args[Cnt]->getType(), - BaseInfo); + LValue ArgLVal = CGF.MakeAddrLValue(CGF.GetAddrOfLocalVar(Args[Cnt]), + Args[Cnt]->getType(), BaseInfo); if (FD->hasCapturedVLAType()) { - LValue CastedArgLVal = - MakeAddrLValue(castValueFromUintptr(*this, FD->getType(), - Args[Cnt]->getName(), ArgLVal), - FD->getType(), BaseInfo); + if (FO.UIntPtrCastRequired) { + ArgLVal = CGF.MakeAddrLValue(castValueFromUintptr(CGF, FD->getType(), + Args[Cnt]->getName(), + ArgLVal), + FD->getType(), BaseInfo); + } auto *ExprArg = - EmitLoadOfLValue(CastedArgLVal, SourceLocation()).getScalarVal(); + CGF.EmitLoadOfLValue(ArgLVal, SourceLocation()).getScalarVal(); auto VAT = FD->getCapturedVLAType(); - VLASizeMap[VAT->getSizeExpr()] = ExprArg; + VLASizes.insert({Args[Cnt], {VAT->getSizeExpr(), ExprArg}}); } else if (I->capturesVariable()) { auto *Var = I->getCapturedVar(); QualType VarTy = Var->getType(); Address ArgAddr = ArgLVal.getAddress(); if (!VarTy->isReferenceType()) { if (ArgLVal.getType()->isLValueReferenceType()) { - ArgAddr = EmitLoadOfReference( + ArgAddr = CGF.EmitLoadOfReference( ArgAddr, ArgLVal.getType()->castAs()); } else if (!VarTy->isVariablyModifiedType() || !VarTy->isPointerType()) { assert(ArgLVal.getType()->isPointerType()); - ArgAddr = EmitLoadOfPointer( + ArgAddr = CGF.EmitLoadOfPointer( ArgAddr, ArgLVal.getType()->castAs()); } } - setAddrOfLocalVar( - Var, Address(ArgAddr.getPointer(), getContext().getDeclAlign(Var))); + if (!FO.RegisterCastedArgsOnly) { + LocalAddrs.insert( + {Args[Cnt], + {Var, Address(ArgAddr.getPointer(), Ctx.getDeclAlign(Var))}}); + } } else if (I->capturesVariableByCopy()) { assert(!FD->getType()->isAnyPointerType() && "Not expecting a captured pointer."); auto *Var = I->getCapturedVar(); QualType VarTy = Var->getType(); - setAddrOfLocalVar(Var, castValueFromUintptr(*this, FD->getType(), - Args[Cnt]->getName(), ArgLVal, - VarTy->isReferenceType())); + LocalAddrs.insert( + {Args[Cnt], + {Var, + FO.UIntPtrCastRequired + ? castValueFromUintptr(CGF, FD->getType(), Args[Cnt]->getName(), + ArgLVal, VarTy->isReferenceType()) + : ArgLVal.getAddress()}}); } else { // If 'this' is captured, load it into CXXThisValue. assert(I->capturesThis()); - CXXThisValue = - EmitLoadOfLValue(ArgLVal, Args[Cnt]->getLocation()).getScalarVal(); + CXXThisValue = CGF.EmitLoadOfLValue(ArgLVal, Args[Cnt]->getLocation()) + .getScalarVal(); + LocalAddrs.insert({Args[Cnt], {nullptr, ArgLVal.getAddress()}}); } ++Cnt; ++I; } + return {F, HasUIntPtrArgs}; +} + +llvm::Function * +CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) { + assert( + CapturedStmtInfo && + "CapturedStmtInfo should be set when generating the captured function"); + const CapturedDecl *CD = S.getCapturedDecl(); + // Build the argument list. + bool NeedWrapperFunction = + getDebugInfo() && + CGM.getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo; + FunctionArgList Args; + llvm::DenseMap> LocalAddrs; + llvm::DenseMap> VLASizes; + FunctionOptions FO(&S, !NeedWrapperFunction, /*RegisterCastedArgsOnly=*/false, + CapturedStmtInfo->getHelperName()); + llvm::Function *F; + bool HasUIntPtrArgs; + std::tie(F, HasUIntPtrArgs) = emitOutlinedFunctionPrologue( + *this, Args, LocalAddrs, VLASizes, CXXThisValue, FO); + for (const auto &LocalAddrPair : LocalAddrs) { + if (LocalAddrPair.second.first) { + setAddrOfLocalVar(LocalAddrPair.second.first, + LocalAddrPair.second.second); + } + } + for (const auto &VLASizePair : VLASizes) + VLASizeMap[VLASizePair.second.first] = VLASizePair.second.second; PGO.assignRegionCounters(GlobalDecl(CD), F); CapturedStmtInfo->EmitBody(*this, CD->getBody()); FinishFunction(CD->getBodyRBrace()); - - return F; + if (!NeedWrapperFunction || !HasUIntPtrArgs) + return F; + + FunctionOptions WrapperFO(&S, /*UIntPtrCastRequired=*/true, + /*RegisterCastedArgsOnly=*/true, + ".nondebug_wrapper."); + CodeGenFunction WrapperCGF(CGM, /*suppressNewContext=*/true); + WrapperCGF.disableDebugInfo(); + Args.clear(); + LocalAddrs.clear(); + VLASizes.clear(); + llvm::Function *WrapperF = + emitOutlinedFunctionPrologue(WrapperCGF, Args, LocalAddrs, VLASizes, + WrapperCGF.CXXThisValue, WrapperFO).first; + LValueBaseInfo BaseInfo(AlignmentSource::Decl, false); + llvm::SmallVector CallArgs; + for (const auto *Arg : Args) { + llvm::Value *CallArg; + auto I = LocalAddrs.find(Arg); + if (I != LocalAddrs.end()) { + LValue LV = + WrapperCGF.MakeAddrLValue(I->second.second, Arg->getType(), BaseInfo); + CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation()); + } else { + auto EI = VLASizes.find(Arg); + if (EI != VLASizes.end()) + CallArg = EI->second.second; + else { + LValue LV = WrapperCGF.MakeAddrLValue(WrapperCGF.GetAddrOfLocalVar(Arg), + Arg->getType(), BaseInfo); + CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation()); + } + } + CallArgs.emplace_back(CallArg); + } + WrapperCGF.Builder.CreateCall(F, CallArgs); + WrapperCGF.FinishFunction(); + return WrapperF; } //===----------------------------------------------------------------------===// diff --git a/test/OpenMP/parallel_codegen.cpp b/test/OpenMP/parallel_codegen.cpp index c43533c6c194..23b323778b47 100644 --- a/test/OpenMP/parallel_codegen.cpp +++ b/test/OpenMP/parallel_codegen.cpp @@ -64,7 +64,7 @@ int main (int argc, char **argv) { // CHECK: call {{.*}}void @{{.+terminate.*|abort}}( // CHECK-NEXT: unreachable // CHECK-NEXT: } -// CHECK-DEBUG: define internal void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid., i64 [[VLA_SIZE:%.+]], i32* [[VLA_ADDR:%[^)]+]]) +// CHECK-DEBUG: define internal void [[OMP_OUTLINED_DEBUG:@.+]](i32* noalias %.global_tid., i32* noalias %.bound_tid., i64 [[VLA_SIZE:%.+]], i32* [[VLA_ADDR:%[^)]+]]) // CHECK-DEBUG-SAME: #[[FN_ATTRS:[0-9]+]] // CHECK-DEBUG: store i32* [[VLA_ADDR]], i32** [[VLA_PTR_ADDR:%.+]], // CHECK-DEBUG: [[VLA_REF:%.+]] = load i32*, i32** [[VLA_PTR_ADDR]] @@ -80,6 +80,8 @@ int main (int argc, char **argv) { // CHECK-DAG: declare {{.*}}void @__kmpc_fork_call(%ident_t*, i32, void (i32*, i32*, ...)*, ...) // CHECK-DEBUG-DAG: define linkonce_odr void [[FOO]](i32 %argc) // CHECK-DEBUG-DAG: declare void @__kmpc_fork_call(%ident_t*, i32, void (i32*, i32*, ...)*, ...) +// CHECK-DEBUG-DAG: define internal void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid., i64 [[VLA_SIZE:%.+]], i32* [[VLA_ADDR:%[^)]+]]) +// CHECK-DEBUG-DAG: call void [[OMP_OUTLINED_DEBUG]] // CHECK: define linkonce_odr {{[a-z\_\b]*[ ]?i32}} [[TMAIN]](i8** %argc) // CHECK: store i8** %argc, i8*** [[ARGC_ADDR:%.+]], diff --git a/test/OpenMP/target_codegen.cpp b/test/OpenMP/target_codegen.cpp index aaaf5fae5729..c457045c17c7 100644 --- a/test/OpenMP/target_codegen.cpp +++ b/test/OpenMP/target_codegen.cpp @@ -117,10 +117,10 @@ int foo(int n) { // CHECK-DAG: [[P]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR:%[^,]+]], i32 0, i32 0 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]] // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR]], i32 0, i32 [[IDX0]] - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[BP0:%[^,]+]], i[[SZ]]* [[CBPADDR0]] + // CHECK-DAG: store i[[SZ]] [[P0:%[^,]+]], i[[SZ]]* [[CPADDR0]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK: [[RET2:%.+]] = load i32, i32* [[RHV]], align 4 @@ -144,17 +144,17 @@ int foo(int n) { // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0 - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[BP0:%[^,]+]], i[[SZ]]* [[CBPADDR0]] + // CHECK-DAG: store i[[SZ]] [[P0:%[^,]+]], i[[SZ]]* [[CPADDR0]] // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1 - // CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] - // CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] - // CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P1]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[BP1:%[^,]+]], i[[SZ]]* [[CBPADDR1]] + // CHECK-DAG: store i[[SZ]] [[P1:%[^,]+]], i[[SZ]]* [[CPADDR1]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -198,87 +198,89 @@ int foo(int n) { // CHECK-DAG: [[PR]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P:%[^,]+]], i32 0, i32 0 // CHECK-DAG: [[SR]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S:%[^,]+]], i32 0, i32 0 - // CHECK-DAG: [[SADDR0:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX0:[0-9]+]] + // CHECK-DAG: [[SADDR0:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX0:0]] // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX0]] // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX0]] - // CHECK-DAG: [[SADDR1:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX1:[0-9]+]] + // CHECK-DAG: [[SADDR1:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX1:1]] // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX1]] // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX1]] - // CHECK-DAG: [[SADDR2:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX2:[0-9]+]] + // CHECK-DAG: [[SADDR2:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX2:2]] // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX2]] // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX2]] - // CHECK-DAG: [[SADDR3:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX3:[0-9]+]] + // CHECK-DAG: [[SADDR3:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX3:3]] // CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX3]] // CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX3]] - // CHECK-DAG: [[SADDR4:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX4:[0-9]+]] + // CHECK-DAG: [[SADDR4:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX4:4]] // CHECK-DAG: [[BPADDR4:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX4]] // CHECK-DAG: [[PADDR4:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX4]] - // CHECK-DAG: [[SADDR5:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX5:[0-9]+]] + // CHECK-DAG: [[SADDR5:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX5:5]] // CHECK-DAG: [[BPADDR5:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX5]] // CHECK-DAG: [[PADDR5:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX5]] - // CHECK-DAG: [[SADDR6:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX6:[0-9]+]] + // CHECK-DAG: [[SADDR6:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX6:6]] // CHECK-DAG: [[BPADDR6:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX6]] // CHECK-DAG: [[PADDR6:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX6]] - // CHECK-DAG: [[SADDR7:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX7:[0-9]+]] + // CHECK-DAG: [[SADDR7:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX7:7]] // CHECK-DAG: [[BPADDR7:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX7]] // CHECK-DAG: [[PADDR7:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX7]] - // CHECK-DAG: [[SADDR8:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX8:[0-9]+]] + // CHECK-DAG: [[SADDR8:%.+]] = getelementptr inbounds [9 x i[[SZ]]], [9 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX8:8]] // CHECK-DAG: [[BPADDR8:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BP]], i32 0, i32 [[IDX8]] // CHECK-DAG: [[PADDR8:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[P]], i32 0, i32 [[IDX8]] // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. - // CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: [[P1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: store i8* [[BP1]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P1]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: [[P3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: [[P4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] 40, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: [[P5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP5]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P5]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] [[BNSIZE]], i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: [[P6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP6]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P6]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] 400, i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: [[P7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP7]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P7]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] [[CNSIZE]], i[[SZ]]* {{%[^,]+}} - - // CHECK-DAG: [[BP8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: [[P8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP8]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P8]], i8** {{%[^,]+}} - // CHECK-DAG: store i[[SZ]] {{12|16}}, i[[SZ]]* {{%[^,]+}} + // CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR2]] + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR2]] + // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* [[SADDR2]] + + // CHECK-DAG: [[CBPADDR6:%.+]] = bitcast i8** [[BPADDR6]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR6:%.+]] = bitcast i8** [[PADDR6]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CBPADDR6]] + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CPADDR6]] + // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* [[SADDR6]] + + // CHECK-DAG: [[CBPADDR5:%.+]] = bitcast i8** [[BPADDR5]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR5:%.+]] = bitcast i8** [[PADDR5]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CBPADDR5]] + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CPADDR5]] + // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* [[SADDR5]] + + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CBPADDR0]] + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CPADDR0]] + // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* [[SADDR0]] + + // CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to [10 x float]** + // CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to [10 x float]** + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CBPADDR1]] + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CPADDR1]] + // CHECK-DAG: store i[[SZ]] 40, i[[SZ]]* [[SADDR1]] + + // CHECK-DAG: [[CBPADDR3:%.+]] = bitcast i8** [[BPADDR3]] to float** + // CHECK-DAG: [[CPADDR3:%.+]] = bitcast i8** [[PADDR3]] to float** + // CHECK-DAG: store float* %{{.+}}, float** [[CBPADDR3]] + // CHECK-DAG: store float* %{{.+}}, float** [[CPADDR3]] + // CHECK-DAG: store i[[SZ]] [[BNSIZE]], i[[SZ]]* [[SADDR3]] + + // CHECK-DAG: [[CBPADDR4:%.+]] = bitcast i8** [[BPADDR4]] to [5 x [10 x double]]** + // CHECK-DAG: [[CPADDR4:%.+]] = bitcast i8** [[PADDR4]] to [5 x [10 x double]]** + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CBPADDR4]] + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CPADDR4]] + // CHECK-DAG: store i[[SZ]] 400, i[[SZ]]* [[SADDR4]] + + // CHECK-DAG: [[CBPADDR7:%.+]] = bitcast i8** [[BPADDR7]] to double** + // CHECK-DAG: [[CPADDR7:%.+]] = bitcast i8** [[PADDR7]] to double** + // CHECK-DAG: store double* %{{.+}}, double** [[CBPADDR7]] + // CHECK-DAG: store double* %{{.+}}, double** [[CPADDR7]] + // CHECK-DAG: store i[[SZ]] [[CNSIZE]], i[[SZ]]* [[SADDR7]] + + // CHECK-DAG: [[CBPADDR8:%.+]] = bitcast i8** [[BPADDR8]] to [[TT]]** + // CHECK-DAG: [[CPADDR8:%.+]] = bitcast i8** [[PADDR8]] to [[TT]]** + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CBPADDR8]] + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CPADDR8]] + // CHECK-DAG: store i[[SZ]] {{12|16}}, i[[SZ]]* [[SADDR8]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK: [[RET2:%.+]] = load i32, i32* [[RHV]], align 4 @@ -468,48 +470,53 @@ int bar(int n){ // CHECK-DAG: [[BPR]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP:%.+]], i32 0, i32 0 // CHECK-DAG: [[PR]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P:%.+]], i32 0, i32 0 // CHECK-DAG: [[SR]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S:%.+]], i32 0, i32 0 -// CHECK-DAG: [[SADDR0:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 [[IDX0:[0-9]+]] -// CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 [[IDX0]] -// CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 [[IDX0]] -// CHECK-DAG: [[SADDR1:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 [[IDX1:[0-9]+]] -// CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 [[IDX1]] -// CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 [[IDX1]] -// CHECK-DAG: [[SADDR2:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 [[IDX2:[0-9]+]] -// CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 [[IDX2]] -// CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 [[IDX2]] -// CHECK-DAG: [[SADDR3:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 [[IDX3:[0-9]+]] -// CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 [[IDX3]] -// CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 [[IDX3]] +// CHECK-DAG: [[SADDR0:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX0:0]] +// CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 0, i32 [[IDX0]] +// CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 0, i32 [[IDX0]] +// CHECK-DAG: [[SADDR1:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX1:1]] +// CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 0, i32 [[IDX1]] +// CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 0, i32 [[IDX1]] +// CHECK-DAG: [[SADDR2:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX2:2]] +// CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 0, i32 [[IDX2]] +// CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 0, i32 [[IDX2]] +// CHECK-DAG: [[SADDR3:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX3:3]] +// CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 0, i32 [[IDX3]] +// CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 0, i32 [[IDX3]] +// CHECK-DAG: [[SADDR4:%.+]] = getelementptr inbounds [5 x i[[SZ]]], [5 x i[[SZ]]]* [[S]], i32 0, i32 [[IDX4:4]] +// CHECK-DAG: [[BPADDR4:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BP]], i32 0, i32 [[IDX4]] +// CHECK-DAG: [[PADDR4:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[P]], i32 0, i32 [[IDX4]] // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. -// CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} -// CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} -// CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - -// CHECK-DAG: [[BP2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: [[P2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: store i8* [[BP2]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P2]], i8** {{%[^,]+}} -// CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} - -// CHECK-DAG: [[BP3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: [[P3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} -// CHECK-DAG: store i[[SZ]] 8, i[[SZ]]* {{%[^,]+}} - -// CHECK-DAG: [[BP4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: [[P4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} -// CHECK-DAG: store i[[SZ]] [[CSIZE]], i[[SZ]]* {{%[^,]+}} +// CHECK-DAG: [[CBPADDR3:%.+]] = bitcast i8** [[BPADDR3]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR3:%.+]] = bitcast i8** [[PADDR3]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR3]] +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR3]] +// CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* [[SADDR3]] + +// CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CBPADDR2]] +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CPADDR2]] +// CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* [[SADDR2]] + +// CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CBPADDR1]] +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CPADDR1]] +// CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* [[SADDR1]] + +// CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to [[S1]]** +// CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to [[S1]]** +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CBPADDR0]] +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CPADDR0]] +// CHECK-DAG: store i[[SZ]] 8, i[[SZ]]* [[SADDR0]] + +// CHECK-DAG: [[CBPADDR4:%.+]] = bitcast i8** [[BPADDR4]] to i16** +// CHECK-DAG: [[CPADDR4:%.+]] = bitcast i8** [[PADDR4]] to i16** +// CHECK-DAG: store i16* %{{.+}}, i16** [[CBPADDR4]] +// CHECK-DAG: store i16* %{{.+}}, i16** [[CPADDR4]] +// CHECK-DAG: store i[[SZ]] [[CSIZE]], i[[SZ]]* [[SADDR4]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK: [[RET2:%.+]] = load i32, i32* [[RHV]], align 4 @@ -533,29 +540,31 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL0:%[^,]+]], i[[SZ]]* [[CBPADDR0]] +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]] // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL1:%[^,]+]], i[[SZ]]* [[CBPADDR1]] +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]] // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] +// CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL2:%[^,]+]], i[[SZ]]* [[CBPADDR2]] +// CHECK-DAG: store i[[SZ]] [[VAL2]], i[[SZ]]* [[CPADDR2]] // CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 3 // CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 3 -// CHECK-DAG: store i8* [[BP3:%[^,]+]], i8** [[BPADDR3]] -// CHECK-DAG: store i8* [[P3:%[^,]+]], i8** [[PADDR3]] -// CHECK-DAG: [[BP3]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P3]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: [[CBPADDR3:%.+]] = bitcast i8** [[BPADDR3]] to [10 x i32]** +// CHECK-DAG: [[CPADDR3:%.+]] = bitcast i8** [[PADDR3]] to [10 x i32]** +// CHECK-DAG: store [10 x i32]* [[VAL3:%[^,]+]], [10 x i32]** [[CBPADDR3]] +// CHECK-DAG: store [10 x i32]* [[VAL3]], [10 x i32]** [[CPADDR3]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -585,24 +594,24 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL0:%[^,]+]], i[[SZ]]* [[CBPADDR0]] +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]] // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL1:%[^,]+]], i[[SZ]]* [[CBPADDR1]] +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]] // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] -// CHECK-DAG: [[BP2]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P2]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to [10 x i32]** +// CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to [10 x i32]** +// CHECK-DAG: store [10 x i32]* [[VAL2:%[^,]+]], [10 x i32]** [[CBPADDR2]] +// CHECK-DAG: store [10 x i32]* [[VAL2]], [10 x i32]** [[CPADDR2]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] diff --git a/test/OpenMP/target_codegen_global_capture.cpp b/test/OpenMP/target_codegen_global_capture.cpp index b08bf10f9f29..eb34082b2940 100644 --- a/test/OpenMP/target_codegen_global_capture.cpp +++ b/test/OpenMP/target_codegen_global_capture.cpp @@ -36,10 +36,10 @@ double Gd = 4.0; // CHECK-SAME: i16 {{[^,]*}}[[B:%[^,]+]], // CHECK-SAME: i16 {{[^,]*}}[[C:%[^,]+]], // CHECK-SAME: i16 {{[^,]*}}[[D:%[^,]+]]) -// CHECK: [[LA:%.+]] = alloca i16 -// CHECK: [[LB:%.+]] = alloca i16 -// CHECK: [[LC:%.+]] = alloca i16 -// CHECK: [[LD:%.+]] = alloca i16 +// CHECK: [[LA:%.+]] = alloca i16, +// CHECK: [[LB:%.+]] = alloca i16, +// CHECK: [[LC:%.+]] = alloca i16, +// CHECK: [[LD:%.+]] = alloca i16, int foo(short a, short b, short c, short d){ static float Sa = 5.0; static float Sb = 6.0; @@ -61,22 +61,22 @@ int foo(short a, short b, short c, short d){ // CHECK-DAG: store i16 [[VALLB]], i16* [[CONVLB:%.+]], // CHECK-DAG: [[CONVLB]] = bitcast i[[sz:64|32]]* [[CADDRLB:%.+]] to i16* // CHECK-DAG: [[CVALLB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLB]], - // CHECK-DAG: [[CPTRLB:%.+]] = inttoptr i[[sz]] [[CVALLB]] to i8* - // CHECK-DAG: store i8* [[CPTRLB]], i8** [[GEPLB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLC]], i16* [[CONVLC:%.+]], // CHECK-DAG: [[CONVLC]] = bitcast i[[sz]]* [[CADDRLC:%.+]] to i16* // CHECK-DAG: [[CVALLC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLC]], - // CHECK-DAG: [[CPTRLC:%.+]] = inttoptr i[[sz]] [[CVALLC]] to i8* - // CHECK-DAG: store i8* [[CPTRLC]], i8** [[GEPLC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLD]], i16* [[CONVLD:%.+]], // CHECK-DAG: [[CONVLD]] = bitcast i[[sz]]* [[CADDRLD:%.+]] to i16* // CHECK-DAG: [[CVALLD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLD]], - // CHECK-DAG: [[CPTRLD:%.+]] = inttoptr i[[sz]] [[CVALLD]] to i8* - // CHECK-DAG: store i8* [[CPTRLD]], i8** [[GEPLD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static vars being captured. @@ -84,22 +84,22 @@ int foo(short a, short b, short c, short d){ // CHECK-DAG: store float [[VALFB]], float* [[CONVFB:%.+]], // CHECK-DAG: [[CONVFB]] = bitcast i[[sz]]* [[CADDRFB:%.+]] to float* // CHECK-DAG: [[CVALFB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFB]], - // CHECK-DAG: [[CPTRFB:%.+]] = inttoptr i[[sz]] [[CVALFB]] to i8* - // CHECK-DAG: store i8* [[CPTRFB]], i8** [[GEPFB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFC]], float* [[CONVFC:%.+]], // CHECK-DAG: [[CONVFC]] = bitcast i[[sz]]* [[CADDRFC:%.+]] to float* // CHECK-DAG: [[CVALFC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFC]], - // CHECK-DAG: [[CPTRFC:%.+]] = inttoptr i[[sz]] [[CVALFC]] to i8* - // CHECK-DAG: store i8* [[CPTRFC]], i8** [[GEPFC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFD]], float* [[CONVFD:%.+]], // CHECK-DAG: [[CONVFD]] = bitcast i[[sz]]* [[CADDRFD:%.+]] to float* // CHECK-DAG: [[CVALFD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFD]], - // CHECK-DAG: [[CPTRFD:%.+]] = inttoptr i[[sz]] [[CVALFD]] to i8* - // CHECK-DAG: store i8* [[CPTRFD]], i8** [[GEPFD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static global vars being captured. @@ -107,25 +107,28 @@ int foo(short a, short b, short c, short d){ // CHECK-64-DAG: store double [[VALGB]], double* [[CONVGB:%.+]], // CHECK-64-DAG: [[CONVGB]] = bitcast i[[sz]]* [[CADDRGB:%.+]] to double* // CHECK-64-DAG: [[CVALGB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGB]], - // CHECK-64-DAG: [[CPTRGB:%.+]] = inttoptr i[[sz]] [[CVALGB]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGB]], i8** [[GEPGB:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gb to i8*), i8** [[GEPGB:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGB]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gb, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to double** // CHECK-DAG: [[GEPGB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGC]], double* [[CONVGC:%.+]], // CHECK-64-DAG: [[CONVGC]] = bitcast i[[sz]]* [[CADDRGC:%.+]] to double* // CHECK-64-DAG: [[CVALGC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGC]], - // CHECK-64-DAG: [[CPTRGC:%.+]] = inttoptr i[[sz]] [[CVALGC]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGC]], i8** [[GEPGC:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gc to i8*), i8** [[GEPGC:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGC]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gc, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to double** // CHECK-DAG: [[GEPGC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGD]], double* [[CONVGD:%.+]], // CHECK-64-DAG: [[CONVGD]] = bitcast i[[sz]]* [[CADDRGD:%.+]] to double* // CHECK-64-DAG: [[CVALGD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGD]], - // CHECK-64-DAG: [[CPTRGD:%.+]] = inttoptr i[[sz]] [[CVALGD]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGD]], i8** [[GEPGD:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gd to i8*), i8** [[GEPGD:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGD]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gd, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to double** // CHECK-DAG: [[GEPGD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK: call i32 @__tgt_target @@ -197,22 +200,22 @@ int bar(short a, short b, short c, short d){ // CHECK-DAG: store i16 [[VALLB]], i16* [[CONVLB:%.+]], // CHECK-DAG: [[CONVLB]] = bitcast i[[sz:64|32]]* [[CADDRLB:%.+]] to i16* // CHECK-DAG: [[CVALLB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLB]], - // CHECK-DAG: [[CPTRLB:%.+]] = inttoptr i[[sz]] [[CVALLB]] to i8* - // CHECK-DAG: store i8* [[CPTRLB]], i8** [[GEPLB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLC]], i16* [[CONVLC:%.+]], // CHECK-DAG: [[CONVLC]] = bitcast i[[sz]]* [[CADDRLC:%.+]] to i16* // CHECK-DAG: [[CVALLC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLC]], - // CHECK-DAG: [[CPTRLC:%.+]] = inttoptr i[[sz]] [[CVALLC]] to i8* - // CHECK-DAG: store i8* [[CPTRLC]], i8** [[GEPLC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLD]], i16* [[CONVLD:%.+]], // CHECK-DAG: [[CONVLD]] = bitcast i[[sz]]* [[CADDRLD:%.+]] to i16* // CHECK-DAG: [[CVALLD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLD]], - // CHECK-DAG: [[CPTRLD:%.+]] = inttoptr i[[sz]] [[CVALLD]] to i8* - // CHECK-DAG: store i8* [[CPTRLD]], i8** [[GEPLD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static vars being captured. @@ -220,22 +223,22 @@ int bar(short a, short b, short c, short d){ // CHECK-DAG: store float [[VALFB]], float* [[CONVFB:%.+]], // CHECK-DAG: [[CONVFB]] = bitcast i[[sz]]* [[CADDRFB:%.+]] to float* // CHECK-DAG: [[CVALFB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFB]], - // CHECK-DAG: [[CPTRFB:%.+]] = inttoptr i[[sz]] [[CVALFB]] to i8* - // CHECK-DAG: store i8* [[CPTRFB]], i8** [[GEPFB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFC]], float* [[CONVFC:%.+]], // CHECK-DAG: [[CONVFC]] = bitcast i[[sz]]* [[CADDRFC:%.+]] to float* // CHECK-DAG: [[CVALFC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFC]], - // CHECK-DAG: [[CPTRFC:%.+]] = inttoptr i[[sz]] [[CVALFC]] to i8* - // CHECK-DAG: store i8* [[CPTRFC]], i8** [[GEPFC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFD]], float* [[CONVFD:%.+]], // CHECK-DAG: [[CONVFD]] = bitcast i[[sz]]* [[CADDRFD:%.+]] to float* // CHECK-DAG: [[CVALFD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFD]], - // CHECK-DAG: [[CPTRFD:%.+]] = inttoptr i[[sz]] [[CVALFD]] to i8* - // CHECK-DAG: store i8* [[CPTRFD]], i8** [[GEPFD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static global vars being captured. @@ -243,25 +246,28 @@ int bar(short a, short b, short c, short d){ // CHECK-64-DAG: store double [[VALGB]], double* [[CONVGB:%.+]], // CHECK-64-DAG: [[CONVGB]] = bitcast i[[sz]]* [[CADDRGB:%.+]] to double* // CHECK-64-DAG: [[CVALGB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGB]], - // CHECK-64-DAG: [[CPTRGB:%.+]] = inttoptr i[[sz]] [[CVALGB]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGB]], i8** [[GEPGB:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gb to i8*), i8** [[GEPGB:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGB]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gb, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to double** // CHECK-DAG: [[GEPGB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGC]], double* [[CONVGC:%.+]], // CHECK-64-DAG: [[CONVGC]] = bitcast i[[sz]]* [[CADDRGC:%.+]] to double* // CHECK-64-DAG: [[CVALGC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGC]], - // CHECK-64-DAG: [[CPTRGC:%.+]] = inttoptr i[[sz]] [[CVALGC]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGC]], i8** [[GEPGC:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gc to i8*), i8** [[GEPGC:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGC]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gc, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to double** // CHECK-DAG: [[GEPGC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGD]], double* [[CONVGD:%.+]], // CHECK-64-DAG: [[CONVGD]] = bitcast i[[sz]]* [[CADDRGD:%.+]] to double* // CHECK-64-DAG: [[CVALGD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGD]], - // CHECK-64-DAG: [[CPTRGD:%.+]] = inttoptr i[[sz]] [[CVALGD]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGD]], i8** [[GEPGD:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gd to i8*), i8** [[GEPGD:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGD]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gd, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to double** // CHECK-DAG: [[GEPGD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK: call i32 @__tgt_target @@ -339,22 +345,22 @@ int tbar(T a, T b, T c, T d){ // CHECK-DAG: store i16 [[VALLB]], i16* [[CONVLB:%.+]], // CHECK-DAG: [[CONVLB]] = bitcast i[[sz:64|32]]* [[CADDRLB:%.+]] to i16* // CHECK-DAG: [[CVALLB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLB]], - // CHECK-DAG: [[CPTRLB:%.+]] = inttoptr i[[sz]] [[CVALLB]] to i8* - // CHECK-DAG: store i8* [[CPTRLB]], i8** [[GEPLB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLC]], i16* [[CONVLC:%.+]], // CHECK-DAG: [[CONVLC]] = bitcast i[[sz]]* [[CADDRLC:%.+]] to i16* // CHECK-DAG: [[CVALLC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLC]], - // CHECK-DAG: [[CPTRLC:%.+]] = inttoptr i[[sz]] [[CVALLC]] to i8* - // CHECK-DAG: store i8* [[CPTRLC]], i8** [[GEPLC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store i16 [[VALLD]], i16* [[CONVLD:%.+]], // CHECK-DAG: [[CONVLD]] = bitcast i[[sz]]* [[CADDRLD:%.+]] to i16* // CHECK-DAG: [[CVALLD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRLD]], - // CHECK-DAG: [[CPTRLD:%.+]] = inttoptr i[[sz]] [[CVALLD]] to i8* - // CHECK-DAG: store i8* [[CPTRLD]], i8** [[GEPLD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALLD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPLD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPLD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static vars being captured. @@ -362,22 +368,22 @@ int tbar(T a, T b, T c, T d){ // CHECK-DAG: store float [[VALFB]], float* [[CONVFB:%.+]], // CHECK-DAG: [[CONVFB]] = bitcast i[[sz]]* [[CADDRFB:%.+]] to float* // CHECK-DAG: [[CVALFB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFB]], - // CHECK-DAG: [[CPTRFB:%.+]] = inttoptr i[[sz]] [[CVALFB]] to i8* - // CHECK-DAG: store i8* [[CPTRFB]], i8** [[GEPFB:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFB]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFB:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFC]], float* [[CONVFC:%.+]], // CHECK-DAG: [[CONVFC]] = bitcast i[[sz]]* [[CADDRFC:%.+]] to float* // CHECK-DAG: [[CVALFC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFC]], - // CHECK-DAG: [[CPTRFC:%.+]] = inttoptr i[[sz]] [[CVALFC]] to i8* - // CHECK-DAG: store i8* [[CPTRFC]], i8** [[GEPFC:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFC]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFC:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-DAG: store float [[VALFD]], float* [[CONVFD:%.+]], // CHECK-DAG: [[CONVFD]] = bitcast i[[sz]]* [[CADDRFD:%.+]] to float* // CHECK-DAG: [[CVALFD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRFD]], - // CHECK-DAG: [[CPTRFD:%.+]] = inttoptr i[[sz]] [[CVALFD]] to i8* - // CHECK-DAG: store i8* [[CPTRFD]], i8** [[GEPFD:%.+]], + // CHECK-DAG: store i[[sz]] [[CVALFD]], i[[sz]]* [[CBP:%.+]], + // CHECK-DAG: [[CBP]] = bitcast i8** [[GEPFD:%.+]] to i[[sz]]* // CHECK-DAG: [[GEPFD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // 3 static global vars being captured. @@ -385,25 +391,28 @@ int tbar(T a, T b, T c, T d){ // CHECK-64-DAG: store double [[VALGB]], double* [[CONVGB:%.+]], // CHECK-64-DAG: [[CONVGB]] = bitcast i[[sz]]* [[CADDRGB:%.+]] to double* // CHECK-64-DAG: [[CVALGB:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGB]], - // CHECK-64-DAG: [[CPTRGB:%.+]] = inttoptr i[[sz]] [[CVALGB]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGB]], i8** [[GEPGB:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gb to i8*), i8** [[GEPGB:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGB]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gb, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGB:%.+]] to double** // CHECK-DAG: [[GEPGB]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGC]], double* [[CONVGC:%.+]], // CHECK-64-DAG: [[CONVGC]] = bitcast i[[sz]]* [[CADDRGC:%.+]] to double* // CHECK-64-DAG: [[CVALGC:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGC]], - // CHECK-64-DAG: [[CPTRGC:%.+]] = inttoptr i[[sz]] [[CVALGC]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGC]], i8** [[GEPGC:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gc to i8*), i8** [[GEPGC:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGC]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gc, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGC:%.+]] to double** // CHECK-DAG: [[GEPGC]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK-64-DAG: store double [[VALGD]], double* [[CONVGD:%.+]], // CHECK-64-DAG: [[CONVGD]] = bitcast i[[sz]]* [[CADDRGD:%.+]] to double* // CHECK-64-DAG: [[CVALGD:%.+]] = load i[[sz]], i[[sz]]* [[CADDRGD]], - // CHECK-64-DAG: [[CPTRGD:%.+]] = inttoptr i[[sz]] [[CVALGD]] to i8* - // CHECK-64-DAG: store i8* [[CPTRGD]], i8** [[GEPGD:%.+]], - // CHECK-32-DAG: store i8* bitcast (double* @Gd to i8*), i8** [[GEPGD:%.+]], + // CHECK-64-DAG: store i[[sz]] [[CVALGD]], i[[sz]]* [[CBP:%.+]], + // CHECK-64-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to i[[sz]]* + // CHECK-32-DAG: store double* @Gd, double** [[CBP:%.+]], + // CHECK-32-DAG: [[CBP]] = bitcast i8** [[GEPGD:%.+]] to double** // CHECK-DAG: [[GEPGD]] = getelementptr inbounds [9 x i8*], [9 x i8*]* %{{.+}}, i32 0, i32 {{[0-8]}} // CHECK: call i32 @__tgt_target diff --git a/test/OpenMP/target_data_codegen.cpp b/test/OpenMP/target_data_codegen.cpp index a149ba9332b9..7e5e267d13b6 100644 --- a/test/OpenMP/target_data_codegen.cpp +++ b/test/OpenMP/target_data_codegen.cpp @@ -45,8 +45,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x double]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x double]** + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[CBP0]] + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[CP0]] // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 @@ -71,10 +73,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK1-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK1-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK1-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK1: br label %[[IFEND:[^,]+]] // CK1: [[IFELSE]] @@ -103,11 +105,11 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK1-DAG: store float* [[VAR0:%.+]], float** [[CBP0]] + // CK1-DAG: store float* [[VAR0]], float** [[CP0]] // CK1-DAG: store i[[sz]] [[CSVAL0:%[^,]+]], i[[sz]]* [[S0]] - // CK1-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast float* [[VAR0]] to i8* // CK1-DAG: [[CSVAL0]] = mul nuw i[[sz]] %{{[^,]+}}, 4 // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 @@ -128,15 +130,18 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([[ST]]* @gb to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** + // CK1-DAG: store [[ST]]* @gb, [[ST]]** [[CBP0]] + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CP0]] // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[BP1]] - // CK1-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK1-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%.+]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CBP1]] + // CK1-DAG: store double* [[SEC1:%.+]], double** [[CP1]] // CK1-DAG: [[SEC1]] = getelementptr inbounds {{.+}}double* [[SEC11:%[^,]+]], i{{.+}} 0 // CK1-DAG: [[SEC11]] = load double*, double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), @@ -191,19 +196,19 @@ int bar(int arg){ // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* -// CK2-DAG: [[CPVAL0]] = bitcast double** [[SEC0:%[^,]+]] to i8* +// CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** +// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** +// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] +// CK2-DAG: store double** [[SEC0:%.+]], double*** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK2-DAG: [[CBPVAL1]] = bitcast double** [[SEC0]] to i8* -// CK2-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%[^,]+]] to i8* +// CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** +// CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** +// CK2-DAG: store double** [[SEC0]], double*** [[CBP1]] +// CK2-DAG: store double* [[SEC1:%.+]], double** [[CP1]] // CK2-DAG: [[SEC1]] = getelementptr inbounds {{.*}}double* [[SEC11:%[^,]+]], i{{.+}} 1 // CK2-DAG: [[SEC11]] = load double*, double** [[SEC111:%[^,]+]], // CK2-DAG: [[SEC111]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 diff --git a/test/OpenMP/target_data_use_device_ptr_codegen.cpp b/test/OpenMP/target_data_use_device_ptr_codegen.cpp index c4b389a4cbb8..5e275565170e 100644 --- a/test/OpenMP/target_data_use_device_ptr_codegen.cpp +++ b/test/OpenMP/target_data_use_device_ptr_codegen.cpp @@ -33,12 +33,11 @@ void foo(float *&lr, T *&tr) { float *l; T *t; - // CK1-DAG: [[RVAL:%.+]] = bitcast double* [[T:%.+]] to i8* - // CK1-DAG: [[T]] = load double*, double** [[DECL:@g]], + // CK1: [[T:%.+]] = load double*, double** [[DECL:@g]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE00]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to double** + // CK1: store double* [[T]], double** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE00]] // CK1: [[VAL:%.+]] = load double*, double** [[CBP]], // CK1-NOT: store double* [[VAL]], double** [[DECL]], // CK1: store double* [[VAL]], double** [[PVT:%.+]], @@ -53,12 +52,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds double, double* [[TTT]], i32 1 ++g; - // CK1-DAG: [[RVAL:%.+]] = bitcast float* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load float*, float** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load float*, float** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE01]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to float** + // CK1: store float* [[T1]], float** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE01]] // CK1: [[VAL:%.+]] = load float*, float** [[CBP]], // CK1-NOT: store float* [[VAL]], float** [[DECL]], // CK1: store float* [[VAL]], float** [[PVT:%.+]], @@ -85,12 +83,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds float, float* [[TTT]], i32 1 ++l; - // CK1-DAG: [[RVAL:%.+]] = bitcast float* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load float*, float** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load float*, float** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE03]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to float** + // CK1: store float* [[T1]], float** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE03]] // CK1: [[VAL:%.+]] = load float*, float** [[CBP]], // CK1-NOT: store float* [[VAL]], float** [[DECL]], // CK1: store float* [[VAL]], float** [[PVT:%.+]], @@ -109,12 +106,11 @@ void foo(float *&lr, T *&tr) { // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]] // CK1: [[BTHEN]]: - // CK1-DAG: [[RVAL:%.+]] = bitcast float* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load float*, float** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load float*, float** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE04]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to float** + // CK1: store float* [[T1]], float** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE04]] // CK1: [[VAL:%.+]] = load float*, float** [[CBP]], // CK1-NOT: store float* [[VAL]], float** [[DECL]], // CK1: store float* [[VAL]], float** [[PVT:%.+]], @@ -146,13 +142,12 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds float, float* [[TTT]], i32 1 ++l; - // CK1-DAG: [[RVAL:%.+]] = bitcast float* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load float*, float** [[T2:%.+]], - // CK1-DAG: [[T2]] = load float**, float*** [[DECL:%.+]], + // CK1: [[T2:%.+]] = load float**, float*** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load float*, float** [[T2]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE05]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to float** + // CK1: store float* [[T1]], float** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE05]] // CK1: [[VAL:%.+]] = load float*, float** [[CBP]], // CK1: store float* [[VAL]], float** [[PVTV:%.+]], // CK1-NOT: store float** [[PVTV]], float*** [[DECL]], @@ -170,12 +165,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds float, float* [[TTTT]], i32 1 ++lr; - // CK1-DAG: [[RVAL:%.+]] = bitcast i32* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load i32*, i32** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load i32*, i32** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE06]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to i32** + // CK1: store i32* [[T1]], i32** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE06]] // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1-NOT: store i32* [[VAL]], i32** [[DECL]], // CK1: store i32* [[VAL]], i32** [[PVT:%.+]], @@ -190,13 +184,12 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds i32, i32* [[TTT]], i32 1 ++t; - // CK1-DAG: [[RVAL:%.+]] = bitcast i32* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load i32*, i32** [[T2:%.+]], - // CK1-DAG: [[T2]] = load i32**, i32*** [[DECL:%.+]], + // CK1: [[T2:%.+]] = load i32**, i32*** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load i32*, i32** [[T2]], // CK1: [[BP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE07]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to i32** + // CK1: store i32* [[T1]], i32** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE07]] // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1: store i32* [[VAL]], i32** [[PVTV:%.+]], // CK1-NOT: store i32** [[PVTV]], i32*** [[DECL]], @@ -214,12 +207,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds i32, i32* [[TTTT]], i32 1 ++tr; - // CK1-DAG: [[RVAL:%.+]] = bitcast float* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load float*, float** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load float*, float** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* %{{.+}}, i32 0, i32 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE08]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to float** + // CK1: store float* [[T1]], float** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE08]] // CK1: [[VAL:%.+]] = load float*, float** [[CBP]], // CK1-NOT: store float* [[VAL]], float** [[DECL]], // CK1: store float* [[VAL]], float** [[PVT:%.+]], @@ -235,11 +227,11 @@ void foo(float *&lr, T *&tr) { ++l; ++t; - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE09]] // CK1: [[_CBP:%.+]] = bitcast i8** {{%.+}} to float** + // CK1: [[CBP:%.+]] = bitcast i8** {{%.+}} to i32** + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE09]] // CK1: [[_VAL:%.+]] = load float*, float** [[_CBP]], // CK1: store float* [[_VAL]], float** [[_PVT:%.+]], - // CK1: [[CBP:%.+]] = bitcast i8** {{%.+}} to i32** // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1: store i32* [[VAL]], i32** [[PVT:%.+]], // CK1: [[_TT1:%.+]] = load float*, float** [[_PVT]], @@ -257,11 +249,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds i32, i32* [[TTT]], i32 1 ++l; ++t; - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE10]] // CK1: [[_CBP:%.+]] = bitcast i8** {{%.+}} to float** + // CK1: [[CBP:%.+]] = bitcast i8** {{%.+}} to i32** + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE10]] // CK1: [[_VAL:%.+]] = load float*, float** [[_CBP]], // CK1: store float* [[_VAL]], float** [[_PVT:%.+]], - // CK1: [[CBP:%.+]] = bitcast i8** {{%.+}} to i32** // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1: store i32* [[VAL]], i32** [[PVT:%.+]], // CK1: [[_TT1:%.+]] = load float*, float** [[_PVT]], @@ -279,12 +271,11 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds i32, i32* [[TTT]], i32 1 ++l; ++t; - // CK1-DAG: [[RVAL:%.+]] = bitcast i32* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load i32*, i32** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load i32*, i32** [[DECL:%.+]], // CK1: [[BP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE11]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to i32** + // CK1: store i32* [[T1]], i32** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE11]] // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1-NOT: store i32* [[VAL]], i32** [[DECL]], // CK1: store i32* [[VAL]], i32** [[PVT:%.+]], @@ -299,13 +290,12 @@ void foo(float *&lr, T *&tr) { // CK1: getelementptr inbounds i32, i32* [[TTT]], i32 1 ++l; ++t; - // CK1-DAG: [[RVAL:%.+]] = bitcast i32* [[T1:%.+]] to i8* - // CK1-DAG: [[T1]] = load i32*, i32** [[T2:%.+]], - // CK1-DAG: [[T2]] = load i32**, i32*** [[DECL:%.+]], + // CK1: [[T2:%.+]] = load i32**, i32*** [[DECL:%.+]], + // CK1: [[T1:%.+]] = load i32*, i32** [[T2]], // CK1: [[BP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* %{{.+}}, i32 0, i32 0 - // CK1: store i8* [[RVAL]], i8** [[BP]], - // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE12]] // CK1: [[CBP:%.+]] = bitcast i8** [[BP]] to i32** + // CK1: store i32* [[T1]], i32** [[CBP]], + // CK1: call void @__tgt_target_data_begin{{.+}}[[MTYPE12]] // CK1: [[VAL:%.+]] = load i32*, i32** [[CBP]], // CK1: store i32* [[VAL]], i32** [[PVTV:%.+]], // CK1-NOT: store i32** [[PVTV]], i32*** [[DECL]], @@ -356,10 +346,11 @@ struct ST { int *la = 0; // CK2: [[BP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* %{{.+}}, i32 0, i32 1 - // CK2: store i8* [[RVAL:%.+]], i8** [[BP]], + // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double*** + // CK2: store double** [[RVAL:%.+]], double*** [[CBP]], // CK2: call void @__tgt_target_data_begin{{.+}}[[MTYPE00]] - // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double** - // CK2: [[VAL:%.+]] = load double*, double** [[CBP]], + // CK2: [[CBP1:%.+]] = bitcast double*** [[CBP]] to double** + // CK2: [[VAL:%.+]] = load double*, double** [[CBP1]], // CK2: store double* [[VAL]], double** [[PVT:%.+]], // CK2: store double** [[PVT]], double*** [[PVT2:%.+]], // CK2: [[TT1:%.+]] = load double**, double*** [[PVT2]], @@ -376,10 +367,11 @@ struct ST { a++; // CK2: [[BP:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* %{{.+}}, i32 0, i32 2 - // CK2: store i8* [[RVAL:%.+]], i8** [[BP]], + // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double*** + // CK2: store double** [[RVAL:%.+]], double*** [[CBP]], // CK2: call void @__tgt_target_data_begin{{.+}}[[MTYPE01]] - // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double** - // CK2: [[VAL:%.+]] = load double*, double** [[CBP]], + // CK2: [[CBP1:%.+]] = bitcast double*** [[CBP]] to double** + // CK2: [[VAL:%.+]] = load double*, double** [[CBP1]], // CK2: store double* [[VAL]], double** [[PVT:%.+]], // CK2: store double** [[PVT]], double*** [[PVT2:%.+]], // CK2: [[TT1:%.+]] = load double**, double*** [[PVT2]], @@ -397,9 +389,9 @@ struct ST { b++; // CK2: [[BP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* %{{.+}}, i32 0, i32 0 - // CK2: store i8* [[RVAL:%.+]], i8** [[BP]], - // CK2: call void @__tgt_target_data_begin{{.+}}[[MTYPE02]] // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double** + // CK2: store double* [[RVAL:%.+]], double** [[CBP]], + // CK2: call void @__tgt_target_data_begin{{.+}}[[MTYPE02]] // CK2: [[VAL:%.+]] = load double*, double** [[CBP]], // CK2: store double* [[VAL]], double** [[PVT:%.+]], // CK2: store double** [[PVT]], double*** [[PVT2:%.+]], @@ -419,16 +411,17 @@ struct ST { la++; // CK2: [[BP:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* %{{.+}}, i32 0, i32 0 - // CK2: store i8* [[RVAL:%.+]], i8** [[BP]], + // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double** + // CK2: store double* [[RVAL:%.+]], double** [[CBP]], // CK2: [[_BP:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* %{{.+}}, i32 0, i32 3 - // CK2: store i8* [[_RVAL:%.+]], i8** [[_BP]], + // CK2: [[_CBP:%.+]] = bitcast i8** [[_BP]] to double*** + // CK2: store double** [[_RVAL:%.+]], double*** [[_CBP]], // CK2: call void @__tgt_target_data_begin{{.+}}[[MTYPE03]] - // CK2: [[CBP:%.+]] = bitcast i8** [[BP]] to double** // CK2: [[VAL:%.+]] = load double*, double** [[CBP]], // CK2: store double* [[VAL]], double** [[PVT:%.+]], // CK2: store double** [[PVT]], double*** [[PVT2:%.+]], - // CK2: [[_CBP:%.+]] = bitcast i8** [[_BP]] to double** - // CK2: [[_VAL:%.+]] = load double*, double** [[_CBP]], + // CK2: [[_CBP1:%.+]] = bitcast double*** [[_CBP]] to double** + // CK2: [[_VAL:%.+]] = load double*, double** [[_CBP1]], // CK2: store double* [[_VAL]], double** [[_PVT:%.+]], // CK2: store double** [[_PVT]], double*** [[_PVT2:%.+]], // CK2: [[TT1:%.+]] = load double**, double*** [[PVT2]], diff --git a/test/OpenMP/target_enter_data_codegen.cpp b/test/OpenMP/target_enter_data_codegen.cpp index 152cd46b4a2f..683cd976d395 100644 --- a/test/OpenMP/target_enter_data_codegen.cpp +++ b/test/OpenMP/target_enter_data_codegen.cpp @@ -45,8 +45,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x double]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x double]** + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[CBP0]] + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[CP0]] // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 // CK1-NOT: __tgt_target_data_end @@ -67,10 +69,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK1-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK1-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK1-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK1: br label %[[IFEND:[^,]+]] // CK1: [[IFELSE]] @@ -93,11 +95,11 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK1-DAG: store float* [[VAR0:%.+]], float** [[CBP0]] + // CK1-DAG: store float* [[VAR0]], float** [[CP0]] // CK1-DAG: store i[[sz]] [[CSVAL0:%[^,]+]], i[[sz]]* [[S0]] - // CK1-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast float* [[VAR0]] to i8* // CK1-DAG: [[CSVAL0]] = mul nuw i[[sz]] %{{[^,]+}}, 4 // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 // CK1-NOT: __tgt_target_data_end @@ -114,15 +116,18 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([[ST]]* @gb to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** + // CK1-DAG: store [[ST]]* @gb, [[ST]]** [[CBP0]] + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CP0]] // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[BP1]] - // CK1-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK1-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%.+]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CBP1]] + // CK1-DAG: store double* [[SEC1:%.+]], double** [[CP1]] // CK1-DAG: [[SEC1]] = getelementptr inbounds {{.+}}double* [[SEC11:%[^,]+]], i{{.+}} 0 // CK1-DAG: [[SEC11]] = load double*, double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), @@ -174,19 +179,19 @@ int bar(int arg){ // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* -// CK2-DAG: [[CPVAL0]] = bitcast double** [[SEC0:%[^,]+]] to i8* +// CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** +// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** +// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] +// CK2-DAG: store double** [[SEC0:%.+]], double*** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK2-DAG: [[CBPVAL1]] = bitcast double** [[SEC0]] to i8* -// CK2-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%[^,]+]] to i8* +// CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** +// CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** +// CK2-DAG: store double** [[SEC0]], double*** [[CBP1]] +// CK2-DAG: store double* [[SEC1:%.+]], double** [[CP1]] // CK2-DAG: [[SEC1]] = getelementptr inbounds {{.*}}double* [[SEC11:%[^,]+]], i{{.+}} 1 // CK2-DAG: [[SEC11]] = load double*, double** [[SEC111:%[^,]+]], // CK2-DAG: [[SEC111]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 diff --git a/test/OpenMP/target_exit_data_codegen.cpp b/test/OpenMP/target_exit_data_codegen.cpp index d3a38592a610..a82c1c6c4aac 100644 --- a/test/OpenMP/target_exit_data_codegen.cpp +++ b/test/OpenMP/target_exit_data_codegen.cpp @@ -46,8 +46,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[P0]] + // CK1-DAG: [[BPC0:%.+]] = bitcast i8** [[BP0]] to [100 x double]** + // CK1-DAG: [[PC0:%.+]] = bitcast i8** [[P0]] to [100 x double]** + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[BPC0]] + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[PC0]] // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 #pragma omp target exit data if(1+3-5) device(arg) map(from: gc) @@ -68,10 +70,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK1-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK1-DAG: store i32* [[VAL0:%[^,]+]], i32** [[CBP0]] + // CK1-DAG: store i32* [[VAL0]], i32** [[CP0]] // CK1: br label %[[IFEND:[^,]+]] // CK1: [[IFELSE]] @@ -94,11 +96,11 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK1-DAG: store float* [[VAL0:%[^,]+]], float** [[CBP0]] + // CK1-DAG: store float* [[VAL0]], float** [[CP0]] // CK1-DAG: store i[[sz]] [[CSVAL0:%[^,]+]], i[[sz]]* [[S0]] - // CK1-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast float* [[VAR0]] to i8* // CK1-DAG: [[CSVAL0]] = mul nuw i[[sz]] %{{[^,]+}}, 4 // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 #pragma omp target exit data map(always, from: lb) @@ -115,15 +117,18 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([[ST]]* @gb to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** + // CK1-DAG: store [[ST]]* @gb, [[ST]]** [[CBP0]] + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CP0]] // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[BP1]] - // CK1-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK1-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%.+]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CBP1]] + // CK1-DAG: store double* [[SEC1:%[^,]+]], double** [[CP1]] // CK1-DAG: [[SEC1]] = getelementptr inbounds {{.+}}double* [[SEC11:%[^,]+]], i{{.+}} 0 // CK1-DAG: [[SEC11]] = load double*, double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), @@ -175,19 +180,19 @@ int bar(int arg){ // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* -// CK2-DAG: [[CPVAL0]] = bitcast double** [[SEC0:%[^,]+]] to i8* +// CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** +// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** +// CK2-DAG: store [[ST]]* [[VAR0:%[^,]+]], [[ST]]** [[CBP0]] +// CK2-DAG: store double** [[SEC0:%[^,]+]], double*** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK2-DAG: [[CBPVAL1]] = bitcast double** [[SEC0]] to i8* -// CK2-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%[^,]+]] to i8* +// CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** +// CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** +// CK2-DAG: store double** [[SEC0]], double*** [[CBP1]] +// CK2-DAG: store double* [[SEC1:%[^,]+]], double** [[CP1]] // CK2-DAG: [[SEC1]] = getelementptr inbounds {{.*}}double* [[SEC11:%[^,]+]], i{{.+}} 1 // CK2-DAG: [[SEC11]] = load double*, double** [[SEC111:%[^,]+]], // CK2-DAG: [[SEC111]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 diff --git a/test/OpenMP/target_firstprivate_codegen.cpp b/test/OpenMP/target_firstprivate_codegen.cpp index a9af2d02f237..1fb0ef9e848c 100644 --- a/test/OpenMP/target_firstprivate_codegen.cpp +++ b/test/OpenMP/target_firstprivate_codegen.cpp @@ -93,12 +93,12 @@ int foo(int n, double *ptr) { // CHECK-64: store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[CONV]], // CHECK-32: store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[ACAST]], // CHECK: [[ACAST_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[ACAST]], - // CHECK: [[ACAST_TOPTR:%.+]] = inttoptr i{{[0-9]+}} [[ACAST_VAL]] to i8* // CHECK: [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[ACAST_TOPTR]], i8** [[BASE_PTR_GEP]], - // CHECK: [[ACAST_TOPTR2:%.+]] = inttoptr i{{[0-9]+}} [[ACAST_VAL]] to i8* + // CHECK: [[ACAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[ACAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR]], // CHECK: [[PTR_GEP:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[ACAST_TOPTR2]], i8** [[PTR_GEP]], + // CHECK: [[ACAST_TOPTR2:%.+]] = bitcast i8** [[PTR_GEP]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[ACAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR2]], // CHECK: [[BASE_PTR_GEP_ARG:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // CHECK: [[PTR_GEP_ARG:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // CHECK: {{.+}} = call i32 @__tgt_target(i32 -1, {{.+}}, i32 1, i8** [[BASE_PTR_GEP_ARG]], i8** [[PTR_GEP_ARG]], i[[SZ]]* getelementptr inbounds ([1 x i[[SZ]]], [1 x i[[SZ]]]* [[SIZET]], i32 0, i32 0), i32* getelementptr inbounds ([1 x i32], [1 x i32]* [[MAPT]], i32 0, i32 0)) @@ -132,85 +132,87 @@ int foo(int n, double *ptr) { // CHECK: [[CN_SIZE_2:%.+]] = mul{{.+}} i{{[0-9]+}} [[CN_SIZE_1]], 8 // firstprivate(aa) --> base_ptr = aa, ptr = aa, size = 2 (short) - // CHECK: [[A2CAST_TO_INT:%.+]] = inttoptr i{{[0-9]+}} [[A2CAST_VAL]] to i8* // CHECK: [[BASE_PTR_GEP2_0:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[A2CAST_TO_INT]], i8** [[BASE_PTR_GEP2_0]], - // CHECK: [[A2CAST_TO_INT_2:%.+]] = inttoptr i{{[0-9]+}} [[A2CAST_VAL]] to i8* + // CHECK: [[ACAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_0]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A2CAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR]], // CHECK: [[PTR_GEP2_0:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[A2CAST_TO_INT_2]], i8** [[PTR_GEP2_0]], + // CHECK: [[ACAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_0]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A2CAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR]], // CHECK: [[SIZE_GEPA2:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // CHECK: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[SIZE_GEPA2]], // firstprivate(b): base_ptr = &b[0], ptr = &b[0], size = 40 (sizeof(float)*10) - // CHECK: [[BCAST:%.+]] = bitcast [10 x float]* [[B]] to i8* // CHECK: [[BASE_PTR_GEP2_1:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[BCAST]], i8** [[BASE_PTR_GEP2_1]], - // CHECK: [[BCAST2:%.+]] = bitcast [10 x float]* [[B]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_1]] to [10 x float]** + // CHECK: store [10 x float]* [[B]], [10 x float]** [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_1:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[BCAST2]], i8** [[PTR_GEP2_1]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_1]] to [10 x float]** + // CHECK: store [10 x float]* [[B]], [10 x float]** [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPB:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 // CHECK: store i{{[0-9]+}} 40, i{{[0-9]+}}* [[SIZE_GEPB]], // firstprivate(bn), 2 entries, n and bn: (1) base_ptr = n, ptr = n, size = 8 ; (2) base_ptr = &c[0], ptr = &c[0], size = n*sizeof(float) - // CHECK-64: [[N_EXT3_1:%.+]] = inttoptr i{{[0-9]+}} [[N_EXT]] to i8* - // CHECK-32: [[N_EXT3_1:%.+]] = inttoptr i{{[0-9]+}} [[N_ADDR_VAL]] to i8* // CHECK: [[BASE_PTR_GEP2_2:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* [[N_EXT3_1]], i8** [[BASE_PTR_GEP2_2]], - // CHECK-64: [[N_EXT3_2:%.+]] = inttoptr i{{[0-9]+}} [[N_EXT]] to i8* - // CHECK-32: [[N_EXT3_2:%.+]] = inttoptr i{{[0-9]+}} [[N_ADDR_VAL]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_2]] to i{{[0-9]+}}* + // CHECK-64: store i{{[0-9]+}} [[N_EXT]], i{{[0-9]+}}* [[BCAST_TOPTR]], + // CHECK-32: store i{{[0-9]+}} [[N_ADDR_VAL]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_2:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* [[N_EXT3_2]], i8** [[PTR_GEP2_2]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_2]] to i{{[0-9]+}}* + // CHECK-64: store i{{[0-9]+}} [[N_EXT]], i{{[0-9]+}}* [[BCAST_TOPTR]], + // CHECK-32: store i{{[0-9]+}} [[N_ADDR_VAL]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPBN_1:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 // CHECK: store i{{[0-9]+}} {{[0-9]}}, i{{[0-9]+}}* [[SIZE_GEPBN_1]], - // CHECK: [[VLABN_BCAST:%.+]] = bitcast float* [[BN_VLA]] to i8* // CHECK: [[BASE_PTR_GEP2_3:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 3 - // CHECK: store i8* [[VLABN_BCAST]], i8** [[BASE_PTR_GEP2_3]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_3]] to float** + // CHECK: store float* [[BN_VLA]], float** [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPBN_3:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 3 // CHECK: store i{{[0-9]+}} [[BN_SIZE]], i{{[0-9]+}}* [[SIZE_GEPBN_3]] // firstprivate(c): base_ptr = &c[0], ptr = &c[0], size = 400 (5*10*sizeof(double)) - // CHECK: [[C_BCAST:%.+]] = bitcast [5 x [10 x double]]* [[C]] to i8* // CHECK: [[BASE_PTR_GEP2_4:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 - // CHECK: store i8* [[C_BCAST]], i8** [[BASE_PTR_GEP2_4]], - // CHECK: [[C_BCAST2:%.+]] = bitcast [5 x [10 x double]]* [[C]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_4]] to [5 x [10 x double]]** + // CHECK: store [5 x [10 x double]]* [[C]], [5 x [10 x double]]** [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_4:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 - // CHECK: store i8* [[C_BCAST2]], i8** [[PTR_GEP2_4]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_4]] to [5 x [10 x double]]** + // CHECK: store [5 x [10 x double]]* [[C]], [5 x [10 x double]]** [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPC_4:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 // CHECK: store i{{[0-9]+}} 400, i{{[0-9]+}}* [[SIZE_GEPC_4]], // firstprivate(cn), 3 entries, 5, n, cn: (1) base_ptr = 5, ptr = 5, size = 8; (2) (1) base_ptr = n, ptr = n, size = 8; (3) base_ptr = &cn[0], ptr = &cn[0], size = 5*n*sizeof(double) // CHECK: [[BASE_PTR_GEP2_5:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 5 - // CHECK: store i8* inttoptr (i{{[0-9]+}} 5 to i8*), i8** [[BASE_PTR_GEP2_5]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_5]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} 5, i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_5:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 5 - // CHECK: store i8* inttoptr (i{{[0-9]+}} 5 to i8*), i8** [[PTR_GEP2_5]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_5]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} 5, i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPCN_5:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 5 // CHECK: store i{{[0-9]+}} {{[0-9]}}, i{{[0-9]+}}* [[SIZE_GEPCN_5]], - // CHECK-64: [[CN_SZ_2_1:%.+]] = inttoptr i{{[0-9]+}} [[N_EXT2]] to i8* - // CHECK-32: [[CN_SZ_2_1:%.+]] = inttoptr i{{[0-9]+}} [[N_ADDR_VAL2]] to i8* // CHECK: [[BASE_PTR_GEP2_6:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 6 - // CHECK: store i8* [[CN_SZ_2_1]], i8** [[BASE_PTR_GEP2_6]], - // CHECK-64: [[CN_SZ_2_2:%.+]] = inttoptr i{{[0-9]+}} [[N_EXT2]] to i8* - // CHECK-32: [[CN_SZ_2_2:%.+]] = inttoptr i{{[0-9]+}} [[N_ADDR_VAL2]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_6]] to i{{[0-9]+}}* + // CHECK-64: store i{{[0-9]+}} [[N_EXT2]], i{{[0-9]+}}* [[BCAST_TOPTR]], + // CHECK-32: store i{{[0-9]+}} [[N_ADDR_VAL2]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_6:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 6 - // CHECK: store i8* [[CN_SZ_2_2]], i8** [[PTR_GEP2_6]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_6]] to i{{[0-9]+}}* + // CHECK-64: store i{{[0-9]+}} [[N_EXT2]], i{{[0-9]+}}* [[BCAST_TOPTR]], + // CHECK-32: store i{{[0-9]+}} [[N_ADDR_VAL2]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPCN_6:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 6 // CHECK: store i{{[0-9]+}} {{[0-9]}}, i{{[0-9]+}}* [[SIZE_GEPCN_6]], - // CHECK: [[VLA_CN_BCAST:%.+]] = bitcast double* [[CN_VLA]] to i8* // CHECK: [[BASE_PTR_GEP2_7:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 7 - // CHECK: store i8* [[VLA_CN_BCAST]], i8** [[BASE_PTR_GEP2_7]], - // CHECK: [[VLA_CN_BCAST2:%.+]] = bitcast double* [[CN_VLA]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_7]] to double** + // CHECK: store double* [[CN_VLA]], double** [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_7:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 7 - // CHECK: store i8* [[VLA_CN_BCAST2]], i8** [[PTR_GEP2_7]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_7]] to double** + // CHECK: store double* [[CN_VLA]], double** [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPCN_7:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 7 // CHECK: store i{{[0-9]+}} [[CN_SIZE_2]], i{{[0-9]+}}* [[SIZE_GEPCN_7]], // firstprivate(d): base_ptr = &d, ptr = &d, size = 16 - // CHECK: [[D_REF:%.+]] = bitcast [[TT]]* [[D]] to i8* // CHECK: [[BASE_PTR_GEP2_8:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[BASE_PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 8 - // CHECK: store i8* [[D_REF]], i8** [[BASE_PTR_GEP2_8]], - // CHECK: [[D_REF2:%.+]] = bitcast [[TT]]* [[D]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP2_8]] to [[TT]]** + // CHECK: store [[TT]]* [[D]], [[TT]]** [[BCAST_TOPTR]], // CHECK: [[PTR_GEP2_8:%.+]] = getelementptr inbounds [9 x i8*], [9 x i8*]* [[PTR_ARR2]], i{{[0-9]+}} 0, i{{[0-9]+}} 8 - // CHECK: store i8* [[D_REF2]], i8** [[PTR_GEP2_8]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP2_8]] to [[TT]]** + // CHECK: store [[TT]]* [[D]], [[TT]]** [[BCAST_TOPTR]], // CHECK: [[SIZE_GEPCN_8:%.+]] = getelementptr inbounds [9 x i{{[0-9]+}}], [9 x i{{[0-9]+}}]* [[SIZET2]], i{{[0-9]+}} 0, i{{[0-9]+}} 8 // CHECK: store i{{[0-9]+}} {{[0-9]+}}, i{{[0-9]+}}* [[SIZE_GEPCN_8]], @@ -299,13 +301,13 @@ int foo(int n, double *ptr) { ptr[0]++; } // CHECK: [[PTR_ADDR_REF:%.+]] = load double*, double** [[PTR_ADDR]], - // CHECK: [[PTR_ADDR_BCAST:%.+]] = bitcast double* [[PTR_ADDR_REF]] to i8* // CHECK: [[BASE_PTR_GEP3_0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BASE_PTR_ARR3]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[PTR_ADDR_BCAST]], i8** [[BASE_PTR_GEP3_0]], - // CHECK: [[PTR_ADDR_BCAST2:%.+]] = bitcast double* [[PTR_ADDR_REF]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP3_0]] to double** + // CHECK: store double* [[PTR_ADDR_REF]], double** [[BCAST_TOPTR]], // CHECK: [[PTR_GEP3_0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PTR_ARR3]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[PTR_ADDR_BCAST2]], i8** [[PTR_GEP3_0]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTR_GEP3_0]] to double** + // CHECK: store double* [[PTR_ADDR_REF]], double** [[BCAST_TOPTR]], // CHECK: [[BASE_PTR_GEP_ARG3:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BASE_PTR_ARR3]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 // CHECK: [[PTR_GEP_ARG3:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PTR_ARR3]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 @@ -407,38 +409,40 @@ struct S1 { // CHECK: store {{.+}}, {{.+}} // firstprivate(b): base_ptr = b, ptr = b, size = 4 (pass by-value) - // CHECK: [[B_CAST_PTR:%.+]] = inttoptr i{{[0-9]+}} [[B_CAST:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP4_1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BASE_PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[B_CAST_PTR]], i8** [[BASE_PTRS_GEP4_1]], - // CHECK: [[B_CAST_PTR2:%.+]] = inttoptr i{{[0-9]+}} [[B_CAST:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP4_1]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[B_CAST:%.+]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP4_1:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[B_CAST_PTR2]], i8** [[PTRS_GEP4_1]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP4_1]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[B_CAST]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZES_GEP4_1:%.+]] = getelementptr inbounds [5 x i{{[0-9]+}}], [5 x i{{[0-9]+}}]* [[SIZET4]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 // CHECK: store i{{[0-9]+}} 4, i{{[0-9]+}}* [[SIZES_GEP4_1]], // firstprivate(c), 3 entries: 2, n, c // CHECK: [[BASE_PTRS_GEP4_2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BASE_PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* inttoptr (i{{[0-9]+}} 2 to i8*), i8** [[BASE_PTRS_GEP4_2]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP4_2]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP4_2:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* inttoptr (i{{[0-9]+}} 2 to i8*), i8** [[PTRS_GEP4_2]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP4_2]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZES_GEP4_2:%.+]] = getelementptr inbounds [5 x i{{[0-9]+}}], [5 x i{{[0-9]+}}]* [[SIZET4]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 // CHECK-64: store i{{[0-9]+}} 8, i{{[0-9]+}}* [[SIZES_GEP4_2]], // CHECK-32: store i{{[0-9]+}} 4, i{{[0-9]+}}* [[SIZES_GEP4_2]], - // CHECK: [[N_PTR:%.+]] = inttoptr i{{[0-9]+}} [[N:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP4_3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BASE_PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 3 - // CHECK: store i8* [[N_PTR]], i8** [[BASE_PTRS_GEP4_3]], - // CHECK: [[N_PTR2:%.+]] = inttoptr i{{[0-9]+}} [[N:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP4_3]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[N:%.+]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP4_3:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 3 - // CHECK: store i8* [[N_PTR2]], i8** [[PTRS_GEP4_3]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP4_3]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[N]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[SIZES_GEP4_3:%.+]] = getelementptr inbounds [5 x i{{[0-9]+}}], [5 x i{{[0-9]+}}]* [[SIZET4]], i{{[0-9]+}} 0, i{{[0-9]+}} 3 // CHECK-64: store i{{[0-9]+}} 8, i{{[0-9]+}}* [[SIZES_GEP4_3]], // CHECK-32: store i{{[0-9]+}} 4, i{{[0-9]+}}* [[SIZES_GEP4_3]], - // CHECK: [[B_BCAST:%.+]] = bitcast i{{[0-9]+}}* [[B:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP4_4:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[BASE_PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 - // CHECK: store i8* [[B_BCAST]], i8** [[BASE_PTRS_GEP4_4]], - // CHECK: [[B_BCAST2:%.+]] = bitcast i{{[0-9]+}}* [[B:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP4_4]] to i{{[0-9]+}}** + // CHECK: store i{{[0-9]+}}* [[B:%.+]], i{{[0-9]+}}** [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP4_4:%.+]] = getelementptr inbounds [5 x i8*], [5 x i8*]* [[PTRS4]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 - // CHECK: store i8* [[B_BCAST2]], i8** [[PTRS_GEP4_4]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP4_4]] to i{{[0-9]+}}** + // CHECK: store i{{[0-9]+}}* [[B]], i{{[0-9]+}}** [[BCAST_TOPTR]], // CHECK: [[SIZES_GEP4_4:%.+]] = getelementptr inbounds [5 x i{{[0-9]+}}], [5 x i{{[0-9]+}}]* [[SIZET4]], i{{[0-9]+}} 0, i{{[0-9]+}} 4 // CHECK: store i{{[0-9]+}} [[B_SIZE:%.+]], i{{[0-9]+}}* [[SIZES_GEP4_4]], @@ -492,28 +496,28 @@ struct S1 { // CHECK: [[PTRS5:%.+]] = alloca [3 x i8*], // firstprivate(a): by value - // CHECK: [[A_CAST_PTR:%.+]] = inttoptr i{{[0-9]+}} [[A_CAST:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP5_0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASE_PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[A_CAST_PTR]], i8** [[BASE_PTRS_GEP5_0]], - // CHECK: [[A_CAST_PTR2:%.+]] = inttoptr i{{[0-9]+}} [[A_CAST:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP5_0]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A_CAST:%.+]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP5_0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 - // CHECK: store i8* [[A_CAST_PTR2]], i8** [[PTRS_GEP5_0]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP5_0]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A_CAST]], i{{[0-9]+}}* [[BCAST_TOPTR]], // firstprivate(aaa): by value - // CHECK: [[A3_CAST_PTR:%.+]] = inttoptr i{{[0-9]+}} [[A3_CAST:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP5_1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASE_PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[A3_CAST_PTR]], i8** [[BASE_PTRS_GEP5_1]], - // CHECK: [[A3_CAST_PTR2:%.+]] = inttoptr i{{[0-9]+}} [[A3_CAST:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP5_1]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A3_CAST:%.+]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP5_1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 - // CHECK: store i8* [[A3_CAST_PTR2]], i8** [[PTRS_GEP5_1]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP5_1]] to i{{[0-9]+}}* + // CHECK: store i{{[0-9]+}} [[A3_CAST]], i{{[0-9]+}}* [[BCAST_TOPTR]], // firstprivate(b): base_ptr = &b[0], ptr= &b[0] - // CHECK: [[B_BCAST:%.+]] = bitcast [10 x i{{[0-9]+}}]* [[B:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP5_2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASE_PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* [[B_BCAST]], i8** [[BASE_PTRS_GEP5_2]], - // CHECK: [[B_BCAST2:%.+]] = bitcast [10 x i{{[0-9]+}}]* [[B:%.+]] to i8* + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP5_2]] to [10 x i{{[0-9]+}}]** + // CHECK: store [10 x i{{[0-9]+}}]* [[B:%.+]], [10 x i{{[0-9]+}}]** [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP5_2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTRS5]], i{{[0-9]+}} 0, i{{[0-9]+}} 2 - // CHECK: store i8* [[B_BCAST2]], i8** [[PTRS_GEP5_2]], + // CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP5_2]] to [10 x i{{[0-9]+}}]** + // CHECK: store [10 x i{{[0-9]+}}]* [[B]], [10 x i{{[0-9]+}}]** [[BCAST_TOPTR]], // only check that the right sizes and map types are used // CHECK: call i32 @__tgt_target(i32 -1, {{.+}}, i32 3, i8** {{.+}}, i8** {{.+}}, i[[SZ]]* getelementptr inbounds ([3 x i[[SZ]]], [3 x i[[SZ]]]* [[SIZET5]], i32 0, i32 0), i32* getelementptr inbounds ([3 x i32], [3 x i32]* [[MAPT5]], i32 0, i32 0)) @@ -539,20 +543,20 @@ int bar(int n, double *ptr){ // CHECK: [[PTRS6:%.+]] = alloca [2 x i8*], // firstprivate(a): by value -// CHECK: [[AT_CAST_PTR:%.+]] = inttoptr i{{[0-9]+}} [[AT_CAST:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP6_0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTRS6]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 -// CHECK: store i8* [[AT_CAST_PTR]], i8** [[BASE_PTRS_GEP6_0]], -// CHECK: [[AT_CAST_PTR2:%.+]] = inttoptr i{{[0-9]+}} [[AT_CAST:%.+]] to i8* +// CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP6_0]] to i{{[0-9]+}}* +// CHECK: store i{{[0-9]+}} [[AT_CAST:%.+]], i{{[0-9]+}}* [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP6_0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS6]], i{{[0-9]+}} 0, i{{[0-9]+}} 0 -// CHECK: store i8* [[AT_CAST_PTR2]], i8** [[PTRS_GEP6_0]], +// CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP6_0]] to i{{[0-9]+}}* +// CHECK: store i{{[0-9]+}} [[AT_CAST]], i{{[0-9]+}}* [[BCAST_TOPTR]], // firstprivate(b): pointer -// CHECK: [[B_BCAST:%.+]] = bitcast [10 x i{{[0-9]+}}]* [[B:%.+]] to i8* // CHECK: [[BASE_PTRS_GEP6_1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTRS6]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 -// CHECK: store i8* [[B_BCAST]], i8** [[BASE_PTRS_GEP6_1]], -// CHECK: [[B_BCAST2:%.+]] = bitcast [10 x i{{[0-9]+}}]* [[B:%.+]] to i8* +// CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTRS_GEP6_1]] to [10 x i{{[0-9]+}}]** +// CHECK: store [10 x i{{[0-9]+}}]* [[B:%.+]], [10 x i{{[0-9]+}}]** [[BCAST_TOPTR]], // CHECK: [[PTRS_GEP6_1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTRS6]], i{{[0-9]+}} 0, i{{[0-9]+}} 1 -// CHECK: store i8* [[B_BCAST2]], i8** [[PTRS_GEP6_1]], +// CHECK: [[BCAST_TOPTR:%.+]] = bitcast i8** [[PTRS_GEP6_1]] to [10 x i{{[0-9]+}}]** +// CHECK: store [10 x i{{[0-9]+}}]* [[B]], [10 x i{{[0-9]+}}]** [[BCAST_TOPTR]], // CHECK: call i32 @__tgt_target(i32 -1, {{.+}}, i32 2, i8** {{.+}}, i8** {{.+}}, i[[SZ]]* getelementptr inbounds ([2 x i[[SZ]]], [2 x i[[SZ]]]* [[SIZET6]], i32 0, i32 0), i32* getelementptr inbounds ([2 x i32], [2 x i32]* [[MAPT6]], i32 0, i32 0)) diff --git a/test/OpenMP/target_is_device_ptr_codegen.cpp b/test/OpenMP/target_is_device_ptr_codegen.cpp index 6c807294835a..1a54aa18c00b 100644 --- a/test/OpenMP/target_is_device_ptr_codegen.cpp +++ b/test/OpenMP/target_is_device_ptr_codegen.cpp @@ -46,10 +46,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast double* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast double* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK1-DAG: store double* [[VAL:%.+]], double** [[CBP1]] + // CK1-DAG: store double* [[VAL]], double** [[CP1]] // CK1-DAG: [[VAL]] = load double*, double** [[ADDR:@g]], // CK1: call void [[KERNEL:@.+]](double* [[VAL]]) @@ -63,10 +63,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast float* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast float* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to float** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to float** + // CK1-DAG: store float* [[VAL:%.+]], float** [[CBP1]] + // CK1-DAG: store float* [[VAL]], float** [[CP1]] // CK1-DAG: [[VAL]] = load float*, float** [[ADDR:%.+]], // CK1: call void [[KERNEL:@.+]](float* [[VAL]]) @@ -80,10 +80,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast i32* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast i32* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK1-DAG: store i32* [[VAL:%.+]], i32** [[CBP1]] + // CK1-DAG: store i32* [[VAL]], i32** [[CP1]] // CK1-DAG: [[VAL]] = load i32*, i32** [[ADDR:%.+]], // CK1: call void [[KERNEL:@.+]](i32* [[VAL]]) @@ -97,10 +97,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast float* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast float* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to float** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to float** + // CK1-DAG: store float* [[VAL:%.+]], float** [[CBP1]] + // CK1-DAG: store float* [[VAL]], float** [[CP1]] // CK1-DAG: [[VAL]] = load float*, float** [[ADDR:%.+]], // CK1-DAG: [[ADDR]] = load float**, float*** [[ADDR2:%.+]], @@ -115,10 +115,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast i32* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast i32* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK1-DAG: store i32* [[VAL:%.+]], i32** [[CBP1]] + // CK1-DAG: store i32* [[VAL]], i32** [[CP1]] // CK1-DAG: [[VAL]] = load i32*, i32** [[ADDR:%.+]], // CK1-DAG: [[ADDR]] = load i32**, i32*** [[ADDR2:%.+]], @@ -133,10 +133,10 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast i32* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast i32* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK1-DAG: store i32* [[VAL:%.+]], i32** [[CBP1]] + // CK1-DAG: store i32* [[VAL]], i32** [[CP1]] // CK1-DAG: [[VAL]] = load i32*, i32** [[ADDR:%.+]], // CK1-DAG: [[ADDR]] = load i32**, i32*** [[ADDR2:%.+]], @@ -151,19 +151,19 @@ void foo(float *&lr, T *&tr) { // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = bitcast i32* [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = bitcast i32* [[VAL]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK1-DAG: store i32* [[VAL:%.+]], i32** [[CBP1]] + // CK1-DAG: store i32* [[VAL]], i32** [[CP1]] // CK1-DAG: [[VAL]] = load i32*, i32** [[ADDR:%.+]], // CK1-DAG: [[ADDR]] = load i32**, i32*** [[ADDR2:%.+]], // CK1-DAG: [[_BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 1 // CK1-DAG: [[_P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 1 - // CK1-DAG: store i8* [[_VALBP:%.+]], i8** [[_BP1]], - // CK1-DAG: store i8* [[_VALP:%.+]], i8** [[_P1]], - // CK1-DAG: [[_VALBP]] = bitcast float* [[_VAL:%.+]] to i8* - // CK1-DAG: [[_VALP]] = bitcast float* [[_VAL]] to i8* + // CK1-DAG: [[_CBP1:%.+]] = bitcast i8** [[_BP1]] to float** + // CK1-DAG: [[_CP1:%.+]] = bitcast i8** [[_P1]] to float** + // CK1-DAG: store float* [[_VAL:%.+]], float** [[_CBP1]] + // CK1-DAG: store float* [[_VAL]], float** [[_CP1]] // CK1-DAG: [[_VAL]] = load float*, float** [[_ADDR:%.+]], // CK1-DAG: [[_ADDR]] = load float**, float*** [[_ADDR2:%.+]], @@ -215,10 +215,10 @@ struct ST { // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK2-DAG: [[CPVAL0]] = bitcast double** [[SEC0:%.+]] to i8* + // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** + // CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK2-DAG: store double** [[SEC0:%.+]], double*** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 #pragma omp target is_device_ptr(a) { @@ -231,18 +231,18 @@ struct ST { // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK2-DAG: [[CPVAL0]] = bitcast double*** [[SEC0:%.+]] to i8* + // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**** + // CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK2-DAG: store double*** [[SEC0:%.+]], double**** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK2-DAG: [[CBPVAL1]] = bitcast double*** [[SEC0]] to i8* - // CK2-DAG: [[CPVAL1]] = bitcast double** [[SEC1:%.+]] to i8* + // CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double**** + // CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double*** + // CK2-DAG: store double*** [[SEC0]], double**** [[CBP1]] + // CK2-DAG: store double** [[SEC1:%.+]], double*** [[CP1]] // CK2-DAG: [[SEC1]] = load double**, double*** [[SEC0]] #pragma omp target is_device_ptr(b) { @@ -255,26 +255,26 @@ struct ST { // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK2-DAG: [[CPVAL0]] = bitcast double*** [[SEC0:%.+]] to i8* + // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**** + // CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK2-DAG: store double*** [[SEC0:%.+]], double**** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK2-DAG: [[CBPVAL1]] = bitcast double*** [[SEC0]] to i8* - // CK2-DAG: [[CPVAL1]] = bitcast double** [[SEC1:%.+]] to i8* + // CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double**** + // CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double*** + // CK2-DAG: store double*** [[SEC0]], double**** [[CBP1]] + // CK2-DAG: store double** [[SEC1:%.+]], double*** [[CP1]] // CK2-DAG: [[SEC1]] = load double**, double*** [[SEC0]] // CK2-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK2-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK2-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK2-DAG: [[CBPVAL2]] = bitcast [[ST]]* [[VAR2:%.+]] to i8* - // CK2-DAG: [[CPVAL2]] = bitcast double** [[SEC2:%.+]] to i8* + // CK2-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [[ST]]** + // CK2-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double*** + // CK2-DAG: store [[ST]]* [[VAR2:%.+]], [[ST]]** [[CBP2]] + // CK2-DAG: store double** [[SEC2:%.+]], double*** [[CP2]] // CK2-DAG: [[SEC2]] = getelementptr {{.*}}[[ST]]* [[VAR2]], i{{.+}} 0, i{{.+}} 0 #pragma omp target is_device_ptr(a, b) { diff --git a/test/OpenMP/target_map_codegen.cpp b/test/OpenMP/target_map_codegen.cpp index 72c7257a0ea7..4933bf31c2a5 100644 --- a/test/OpenMP/target_map_codegen.cpp +++ b/test/OpenMP/target_map_codegen.cpp @@ -28,10 +28,10 @@ void implicit_maps_integer (int a){ // CK1-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK1-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK1-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK1-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK1-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK1-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK1-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK1-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK1-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK1-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -75,10 +75,10 @@ void implicit_maps_reference (int a, int *b){ // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK2-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK2-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK2-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK2-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK2-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK2-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK2-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK2-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK2-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -95,10 +95,10 @@ void implicit_maps_reference (int a, int *b){ // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK2-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK2-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK2-DAG: [[VALBP]] = bitcast i32* [[VAL:%.+]] to i8* - // CK2-DAG: [[VALP]] = bitcast i32* [[VAL]] to i8* + // CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK2-DAG: store i32* [[VAL:%[^,]+]], i32** [[CBP1]] + // CK2-DAG: store i32* [[VAL]], i32** [[CP1]] // CK2-DAG: [[VAL]] = load i32*, i32** [[ADDR:%.+]], // CK2-DAG: [[ADDR]] = load i32**, i32*** [[ADDR2:%.+]], @@ -151,10 +151,10 @@ void implicit_maps_parameter (int a){ // CK3-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK3-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK3-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK3-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK3-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK3-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK3-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK3-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK3-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK3-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK3-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK3-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK3-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK3-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -203,10 +203,10 @@ void implicit_maps_nested_integer (int a){ // CK4-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK4-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK4-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK4-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK4-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK4-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK4-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK4-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK4-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK4-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK4-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK4-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK4-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK4-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -257,10 +257,10 @@ void implicit_maps_nested_integer_and_enum (int a){ // CK5-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK5-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK5-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK5-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK5-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK5-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK5-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK5-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK5-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK5-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK5-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK5-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK5-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK5-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -302,10 +302,10 @@ void implicit_maps_host_global (int a){ // CK6-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK6-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK6-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK6-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK6-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK6-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK6-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK6-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK6-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK6-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK6-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK6-64-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK6-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK6-64-DAG: store i32 [[GBLVAL:%.+]], i32* [[CADDR]], @@ -355,18 +355,18 @@ void implicit_maps_double (int a){ // CK7-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK7-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK7-64-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK7-64-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK7-64-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK7-64-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK7-64-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK7-64-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK7-64-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK7-64-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK7-64-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK7-64-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to double* // CK7-64-64-DAG: store double {{.+}}, double* [[CADDR]], - // CK7-32-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK7-32-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK7-32-DAG: [[VALBP]] = bitcast double* [[DECL:%.+]] to i8* - // CK7-32-DAG: [[VALP]] = bitcast double* [[DECL]] to i8* + // CK7-32-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double** + // CK7-32-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK7-32-DAG: store double* [[DECL:%[^,]+]], double** [[CBP1]] + // CK7-32-DAG: store double* [[DECL]], double** [[CP1]] // CK7-64: call void [[KERNEL:@.+]](i[[sz]] [[VAL]]) // CK7-32: call void [[KERNEL:@.+]](double* [[DECL]]) @@ -411,10 +411,10 @@ void implicit_maps_float (int a){ // CK8-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK8-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK8-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK8-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK8-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK8-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK8-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK8-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK8-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK8-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK8-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK8-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK8-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to float* // CK8-DAG: store float {{.+}}, float* [[CADDR]], @@ -455,10 +455,10 @@ void implicit_maps_array (int a){ // CK9-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK9-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK9-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK9-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK9-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK9-DAG: [[VALBP]] = bitcast [2 x double]* [[DECL:%.+]] to i8* - // CK9-DAG: [[VALP]] = bitcast [2 x double]* [[DECL]] to i8* + // CK9-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [2 x double]** + // CK9-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [2 x double]** + // CK9-DAG: store [2 x double]* [[DECL:%[^,]+]], [2 x double]** [[CBP1]] + // CK9-DAG: store [2 x double]* [[DECL]], [2 x double]** [[CP1]] // CK9: call void [[KERNEL:@.+]]([2 x double]* [[DECL]]) #pragma omp target @@ -496,10 +496,10 @@ void implicit_maps_pointer (){ // CK10-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK10-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK10-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK10-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK10-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK10-DAG: [[VALBP]] = bitcast double* [[PTR:%.+]] to i8* - // CK10-DAG: [[VALP]] = bitcast double* [[PTR]] to i8* + // CK10-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double** + // CK10-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK10-DAG: store double* [[PTR:%[^,]+]], double** [[CBP1]] + // CK10-DAG: store double* [[PTR]], double** [[CP1]] // CK10: call void [[KERNEL:@.+]](double* [[PTR]]) #pragma omp target @@ -538,10 +538,10 @@ void implicit_maps_double_complex (int a){ // CK11-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK11-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK11-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK11-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK11-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK11-DAG: [[VALBP]] = bitcast { double, double }* [[PTR:%.+]] to i8* - // CK11-DAG: [[VALP]] = bitcast { double, double }* [[PTR]] to i8* + // CK11-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to { double, double }** + // CK11-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to { double, double }** + // CK11-DAG: store { double, double }* [[PTR:%[^,]+]], { double, double }** [[CBP1]] + // CK11-DAG: store { double, double }* [[PTR]], { double, double }** [[CP1]] // CK11: call void [[KERNEL:@.+]]({ double, double }* [[PTR]]) #pragma omp target @@ -584,18 +584,18 @@ void implicit_maps_float_complex (int a){ // CK12-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK12-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK12-64-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK12-64-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK12-64-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK12-64-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK12-64-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK12-64-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK12-64-DAG: store i[[sz]] [[VAL:%[^,]+]], i[[sz]]* [[CBP1]] + // CK12-64-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK12-64-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK12-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to { float, float }* // CK12-64-DAG: store { float, float } {{.+}}, { float, float }* [[CADDR]], - // CK12-32-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK12-32-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK12-32-DAG: [[VALBP]] = bitcast { float, float }* [[DECL:%.+]] to i8* - // CK12-32-DAG: [[VALP]] = bitcast { float, float }* [[DECL]] to i8* + // CK12-32-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to { float, float }** + // CK12-32-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to { float, float }** + // CK12-32-DAG: store { float, float }* [[DECL:%[^,]+]], { float, float }** [[CBP1]] + // CK12-32-DAG: store { float, float }* [[DECL]], { float, float }** [[CP1]] // CK12-64: call void [[KERNEL:@.+]](i[[sz]] [[VAL]]) // CK12-32: call void [[KERNEL:@.+]]({ float, float }* [[DECL]]) @@ -645,27 +645,29 @@ void implicit_maps_variable_length_array (int a){ // CK13-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK13-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 // CK13-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[SS]], i32 0, i32 0 - // CK13-DAG: store i8* inttoptr (i[[sz]] 2 to i8*), i8** [[BP0]], - // CK13-DAG: store i8* inttoptr (i[[sz]] 2 to i8*), i8** [[P0]], + // CK13-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[sz]]* + // CK13-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[sz]]* + // CK13-DAG: store i[[sz]] 2, i[[sz]]* [[CBP0]] + // CK13-DAG: store i[[sz]] 2, i[[sz]]* [[CP0]] // CK13-DAG: store i[[sz]] {{8|4}}, i[[sz]]* [[S0]], // CK13-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 1 // CK13-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 1 // CK13-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[SS]], i32 0, i32 1 - // CK13-DAG: store i8* [[VALBP1:%.+]], i8** [[BP1]], - // CK13-DAG: store i8* [[VALP1:%.+]], i8** [[P1]], - // CK13-DAG: [[VALBP1]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK13-DAG: [[VALP1]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK13-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK13-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK13-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK13-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK13-DAG: store i[[sz]] {{8|4}}, i[[sz]]* [[S1]], // CK13-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 2 // CK13-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 2 // CK13-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[SS]], i32 0, i32 2 - // CK13-DAG: store i8* [[VALBP2:%.+]], i8** [[BP2]], - // CK13-DAG: store i8* [[VALP2:%.+]], i8** [[P2]], + // CK13-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to double** + // CK13-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double** + // CK13-DAG: store double* [[DECL:%.+]], double** [[CBP2]] + // CK13-DAG: store double* [[DECL]], double** [[CP2]] // CK13-DAG: store i[[sz]] [[VALS2:%.+]], i[[sz]]* [[S2]], - // CK13-DAG: [[VALBP2]] = bitcast double* [[DECL:%.+]] to i8* - // CK13-DAG: [[VALP2]] = bitcast double* [[DECL]] to i8* // CK13-DAG: [[VALS2]] = mul nuw i[[sz]] %{{.+}}, 8 // CK13: call void [[KERNEL:@.+]](i[[sz]] {{.+}}, i[[sz]] {{.+}}, double* [[DECL]]) @@ -730,17 +732,17 @@ void implicit_maps_class (int a){ // CK14-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK14-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK14-DAG: store i8* [[VALBP0:%.+]], i8** [[BP0]], - // CK14-DAG: store i8* [[VALP0:%.+]], i8** [[P0]], - // CK14-DAG: [[VALBP0]] = bitcast [[ST]]* [[DECL:%.+]] to i8* - // CK14-DAG: [[VALP0]] = bitcast [[ST]]* [[DECL]] to i8* + // CK14-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK14-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK14-DAG: store [[ST]]* [[DECL:%.+]], [[ST]]** [[CBP0]] + // CK14-DAG: store [[ST]]* [[DECL]], [[ST]]** [[CP0]] // CK14-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 1 // CK14-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 1 - // CK14-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK14-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK14-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK14-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK14-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK14-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK14-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK14-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK14-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK14-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK14-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -822,17 +824,17 @@ void implicit_maps_templated_class (int a){ // CK15-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK15-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK15-DAG: store i8* [[VALBP0:%.+]], i8** [[BP0]], - // CK15-DAG: store i8* [[VALP0:%.+]], i8** [[P0]], - // CK15-DAG: [[VALBP0]] = bitcast [[ST]]* [[DECL:%.+]] to i8* - // CK15-DAG: [[VALP0]] = bitcast [[ST]]* [[DECL]] to i8* + // CK15-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK15-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK15-DAG: store [[ST]]* [[DECL:%.+]], [[ST]]** [[CBP0]] + // CK15-DAG: store [[ST]]* [[DECL]], [[ST]]** [[CP0]] // CK15-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 1 // CK15-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 1 - // CK15-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK15-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK15-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK15-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK15-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK15-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK15-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK15-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK15-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK15-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK15-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -847,17 +849,17 @@ void implicit_maps_templated_class (int a){ // CK15-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK15-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK15-DAG: store i8* [[VALBP0:%.+]], i8** [[BP0]], - // CK15-DAG: store i8* [[VALP0:%.+]], i8** [[P0]], - // CK15-DAG: [[VALBP0]] = bitcast [[ST]]* [[DECL:%.+]] to i8* - // CK15-DAG: [[VALP0]] = bitcast [[ST]]* [[DECL]] to i8* + // CK15-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK15-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK15-DAG: store [[ST]]* [[DECL:%.+]], [[ST]]** [[CBP0]] + // CK15-DAG: store [[ST]]* [[DECL]], [[ST]]** [[CP0]] // CK15-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 1 // CK15-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 1 - // CK15-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK15-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK15-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK15-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK15-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK15-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK15-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK15-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK15-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK15-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK15-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -923,10 +925,10 @@ void implicit_maps_templated_function (int a){ // CK16-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK16-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK16-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK16-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK16-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK16-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK16-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK16-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK16-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK16-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK16-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK16-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK16-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -971,10 +973,10 @@ void implicit_maps_struct (int a){ // CK17-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK17-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK17-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK17-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK17-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK17-DAG: [[VALBP]] = bitcast [[ST]]* [[DECL:%.+]] to i8* - // CK17-DAG: [[VALP]] = bitcast [[ST]]* [[DECL]] to i8* + // CK17-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[ST]]** + // CK17-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[ST]]** + // CK17-DAG: store [[ST]]* [[DECL:%.+]], [[ST]]** [[CBP1]] + // CK17-DAG: store [[ST]]* [[DECL]], [[ST]]** [[CP1]] // CK17: call void [[KERNEL:@.+]]([[ST]]* [[DECL]]) #pragma omp target @@ -1023,10 +1025,10 @@ void implicit_maps_template_type_capture (int a){ // CK18-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK18-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK18-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK18-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK18-DAG: [[VALBP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* - // CK18-DAG: [[VALP]] = inttoptr i[[sz]] [[VAL:%.+]] to i8* + // CK18-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[sz]]* + // CK18-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[sz]]* + // CK18-DAG: store i[[sz]] [[VAL:%.+]], i[[sz]]* [[CBP1]] + // CK18-DAG: store i[[sz]] [[VAL]], i[[sz]]* [[CP1]] // CK18-DAG: [[VAL]] = load i[[sz]], i[[sz]]* [[ADDR:%.+]], // CK18-64-DAG: [[CADDR:%.+]] = bitcast i[[sz]]* [[ADDR]] to i32* // CK18-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -1181,10 +1183,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK19: call void [[CALL00:@.+]](i32* {{[^,]+}}) #pragma omp target map(alloc:a) @@ -1202,10 +1204,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [100 x i32]* [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x i32]** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store [100 x i32]* [[VAR0]], [100 x i32]** [[CP0]] // CK19: call void [[CALL01:@.+]]([100 x i32]* {{[^,]+}}) #pragma omp target map(to:arra) @@ -1220,10 +1222,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} 20 // CK19: call void [[CALL02:@.+]]([100 x i32]* {{[^,]+}}) @@ -1239,10 +1241,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 // CK19: call void [[CALL03:@.+]]([100 x i32]* {{[^,]+}}) @@ -1258,10 +1260,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 // CK19: call void [[CALL04:@.+]]([100 x i32]* {{[^,]+}}) @@ -1277,10 +1279,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} 15 // CK19: call void [[CALL05:@.+]]([100 x i32]* {{[^,]+}}) @@ -1298,11 +1300,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: store i{{.+}} [[CSVAL0:%[^,]+]], i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* // CK19-DAG: [[CSVAL0]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} %{{.*}} @@ -1321,11 +1323,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: store i{{.+}} [[CSVAL0:%[^,]+]], i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* // CK19-DAG: [[CSVAL0]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 @@ -1342,10 +1344,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [100 x i32]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [100 x i32]* [[VAR0:%.+]], [100 x i32]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%[^,]+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[100 x i32]* [[VAR0]], i{{.+}} 0, i{{.+}} %{{.*}} // CK19: call void [[CALL08:@.+]]([100 x i32]* {{[^,]+}}) @@ -1364,10 +1366,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32** [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32** [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32*** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32*** + // CK19-DAG: store i32** [[VAR0:%.+]], i32*** [[CBP0]] + // CK19-DAG: store i32** [[VAR0]], i32*** [[CP0]] // CK19: call void [[CALL09:@.+]](i32** {{[^,]+}}) #pragma omp target map(from:pa) @@ -1382,10 +1384,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 20 // CK19-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -1403,10 +1405,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 0 // CK19-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -1424,10 +1426,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 15 // CK19-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -1447,11 +1449,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: store i{{.+}} [[CSVAL0:%[^,]+]], i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* // CK19-DAG: [[CSVAL0]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} %{{.*}} @@ -1472,11 +1474,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: store i{{.+}} [[CSVAL0:%[^,]+]], i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* // CK19-DAG: [[CSVAL0]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 0 @@ -1495,10 +1497,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} %{{.*}} // CK19-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -1521,20 +1523,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: store i{{.+}} {{8|4}}, i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[VAR1]], i32** [[CP1]] // CK19-DAG: store i{{.+}} [[CSVAL1:%[^,]+]], i{{.+}}* [[S1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[VAR1]] to i8* // CK19-DAG: [[CSVAL1]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19: call void [[CALL16:@.+]](i{{.+}} {{[^,]+}}, i32* {{[^,]+}}) @@ -1550,17 +1552,17 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} 20 // CK19: call void [[CALL17:@.+]](i{{.+}} {{[^,]+}}, i32* {{[^,]+}}) @@ -1576,17 +1578,17 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} 0 // CK19: call void [[CALL18:@.+]](i{{.+}} {{[^,]+}}, i32* {{[^,]+}}) @@ -1604,20 +1606,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: store i{{.+}} {{8|4}}, i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: store i{{.+}} [[CSVAL1:%[^,]+]], i{{.+}}* [[S1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* // CK19-DAG: [[CSVAL1]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} 0 @@ -1634,17 +1636,17 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} 15 // CK19: call void [[CALL20:@.+]](i{{.+}} {{[^,]+}}, i32* {{[^,]+}}) @@ -1662,20 +1664,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: store i{{.+}} {{8|4}}, i{{.+}}* [[S0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: store i{{.+}} [[CSVAL1:%[^,]+]], i{{.+}}* [[S1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* // CK19-DAG: [[CSVAL1]] = mul nuw i{{.+}} %{{.*}}, 4 // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} %{{.+}} @@ -1692,17 +1694,17 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = inttoptr i[[Z]] %{{.+}} to i8* - // CK19-DAG: [[CPVAL0]] = inttoptr i[[Z]] %{{.+}}to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] {{%.+}}, i[[Z]]* [[CP0]] // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK19-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK19-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32* [[VAR1]], i{{.+}} %{{.+}} // CK19: call void [[CALL22:@.+]](i{{.+}} {{[^,]+}}, i32* {{[^,]+}}) @@ -1719,10 +1721,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK19: call void [[CALL23:@.+]](i32* {{[^,]+}}) #pragma omp target map(always, tofrom: a) @@ -1741,10 +1743,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [4 x [5 x [6 x i32]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [4 x [5 x [6 x i32]]]* [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [4 x [5 x [6 x i32]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [4 x [5 x [6 x i32]]]** + // CK19-DAG: store [4 x [5 x [6 x i32]]]* [[VAR0:%.+]], [4 x [5 x [6 x i32]]]** [[CBP0]] + // CK19-DAG: store [4 x [5 x [6 x i32]]]* [[VAR0]], [4 x [5 x [6 x i32]]]** [[CP0]] // CK19: call void [[CALL24:@.+]]([4 x [5 x [6 x i32]]]* {{[^,]+}}) #pragma omp target map(tofrom: marr) @@ -1759,10 +1761,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [4 x [5 x [6 x i32]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [4 x [5 x [6 x i32]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [4 x [5 x [6 x i32]]]* [[VAR0:%.+]], [4 x [5 x [6 x i32]]]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[6 x i32]* [[SEC00:[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[SEC00]] = getelementptr {{.*}}[5 x [6 x i32]]* [[SEC000:[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[SEC000]] = getelementptr {{.*}}[4 x [5 x [6 x i32]]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 @@ -1780,10 +1782,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [4 x [5 x [6 x i32]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [4 x [5 x [6 x i32]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [4 x [5 x [6 x i32]]]* [[VAR0:%.+]], [4 x [5 x [6 x i32]]]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[6 x i32]* [[SEC00:[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[SEC00]] = getelementptr {{.*}}[5 x [6 x i32]]* [[SEC000:[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[SEC000]] = getelementptr {{.*}}[4 x [5 x [6 x i32]]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 @@ -1801,10 +1803,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [4 x [5 x [6 x i32]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [4 x [5 x [6 x i32]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store [4 x [5 x [6 x i32]]]* [[VAR0:%.+]], [4 x [5 x [6 x i32]]]** [[CBP0]] + // CK19-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.*}}[6 x i32]* [[SEC00:[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK19-DAG: [[SEC00]] = getelementptr {{.*}}[5 x [6 x i32]]* [[SEC000:[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[SEC000]] = getelementptr {{.*}}[4 x [5 x [6 x i32]]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 @@ -1822,20 +1824,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32*** [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32*** [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32**** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32**** + // CK19-DAG: store i32*** [[VAR0:%.+]], i32**** [[CBP0]] + // CK19-DAG: store i32*** [[SEC0:%.+]], i32**** [[CP0]] // CK19-DAG: [[VAR0]] = load i32***, i32**** [[PTR:%[^,]+]], // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32*** [[SEC00:[^,]+]], i{{.+}} 1 // CK19-DAG: [[SEC00]] = load i32***, i32**** [[PTR]], // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32*** [[SEC0]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32** [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32**** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32*** + // CK19-DAG: store i32*** [[SEC0]], i32**** [[CBP1]] + // CK19-DAG: store i32** [[SEC1:%.+]], i32*** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32** [[SEC11:[^,]+]], i{{.+}} 2 // CK19-DAG: [[SEC11]] = load i32**, i32*** [[SEC111:%[^,]+]], // CK19-DAG: [[SEC111]] = getelementptr {{.*}}i32*** [[SEC1111:[^,]+]], i{{.+}} 1 @@ -1843,10 +1845,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK19-DAG: [[CBPVAL2]] = bitcast i32** [[SEC1]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast i32* [[SEC2:%.+]] to i8* + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to i32*** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to i32** + // CK19-DAG: store i32** [[SEC1]], i32*** [[CBP2]] + // CK19-DAG: store i32* [[SEC2:%.+]], i32** [[CP2]] // CK19-DAG: [[SEC2]] = getelementptr {{.*}}i32* [[SEC22:[^,]+]], i{{.+}} 2 // CK19-DAG: [[SEC22]] = load i32*, i32** [[SEC222:%[^,]+]], // CK19-DAG: [[SEC222]] = getelementptr {{.*}}i32** [[SEC2222:[^,]+]], i{{.+}} 2 @@ -1867,20 +1869,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast i32*** [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast i32*** [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32**** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32**** + // CK19-DAG: store i32*** [[VAR0:%.+]], i32**** [[CBP0]] + // CK19-DAG: store i32*** [[SEC0:%.+]], i32**** [[CP0]] // CK19-DAG: [[VAR0]] = load i32***, i32**** [[PTR:%[^,]+]], // CK19-DAG: [[SEC0]] = getelementptr {{.*}}i32*** [[SEC00:[^,]+]], i{{.+}} 1 // CK19-DAG: [[SEC00]] = load i32***, i32**** [[PTR]], // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast i32*** [[SEC0]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast i32** [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32**** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32*** + // CK19-DAG: store i32*** [[SEC0]], i32**** [[CBP1]] + // CK19-DAG: store i32** [[SEC1:%.+]], i32*** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}i32** [[SEC11:[^,]+]], i{{.+}} 2 // CK19-DAG: [[SEC11]] = load i32**, i32*** [[SEC111:%[^,]+]], // CK19-DAG: [[SEC111]] = getelementptr {{.*}}i32*** [[SEC1111:[^,]+]], i{{.+}} 1 @@ -1888,10 +1890,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK19-DAG: [[CBPVAL2]] = bitcast i32** [[SEC1]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast i32* [[SEC2:%.+]] to i8* + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to i32*** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to i32** + // CK19-DAG: store i32** [[SEC1]], i32*** [[CBP2]] + // CK19-DAG: store i32* [[SEC2:%.+]], i32** [[CP2]] // CK19-DAG: [[SEC2]] = getelementptr {{.*}}i32* [[SEC22:[^,]+]], i{{.+}} 3 // CK19-DAG: [[SEC22]] = load i32*, i32** [[SEC222:%[^,]+]], // CK19-DAG: [[SEC222]] = getelementptr {{.*}}i32** [[SEC2222:[^,]+]], i{{.+}} 2 @@ -1917,40 +1919,42 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 23 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 23 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 23, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 23, i[[Z]]* [[CP0]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* // CK19-64-DAG: [[VAR1]] = zext i32 %{{[^,]+}} to i64 // CK19-64-DAG: [[VAR11]] = zext i32 %{{[^,]+}} to i64 // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to i[[Z]]* + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR2:%.+]], i[[Z]]* [[CBP2]] + // CK19-DAG: store i[[Z]] [[VAR22:%.+]], i[[Z]]* [[CP2]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S2]] - // CK19-DAG: [[CBPVAL2]] = inttoptr i[[Z]] [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = inttoptr i[[Z]] [[VAR22:%.+]] to i8* // CK19-64-DAG: [[VAR2]] = zext i32 %{{[^,]+}} to i64 // CK19-64-DAG: [[VAR22]] = zext i32 %{{[^,]+}} to i64 // // CK19-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK19-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 // CK19-DAG: [[S3:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 3 - // CK19-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] - // CK19-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] + // CK19-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to double** + // CK19-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to double** + // CK19-DAG: store double* [[VAR3:%.+]], double** [[CBP3]] + // CK19-DAG: store double* [[VAR3]], double** [[CP3]] // CK19-DAG: store i[[Z]] [[CSVAL3:%[^,]+]], i[[Z]]* [[S3]] - // CK19-DAG: [[CBPVAL3]] = bitcast double* [[VAR3:%.+]] to i8* - // CK19-DAG: [[CPVAL3]] = bitcast double* [[VAR3]] to i8* // CK19-DAG: [[CSVAL3]] = mul nuw i[[Z]] %{{[^,]+}}, {{8|4}} // CK19: call void [[CALL30:@.+]](i[[Z]] 23, i[[Z]] %{{[^,]+}}, i[[Z]] %{{[^,]+}}, double* %{{[^,]+}}) @@ -1966,29 +1970,31 @@ void explicit_maps_single (int ii){ // // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 23 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 23 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 23, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 23, i[[Z]]* [[CP0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK19-DAG: [[CBPVAL2]] = inttoptr i[[Z]] [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = inttoptr i[[Z]] [[VAR22:%.+]] to i8* + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to i[[Z]]* + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR2:%.+]], i[[Z]]* [[CBP2]] + // CK19-DAG: store i[[Z]] [[VAR22:%.+]], i[[Z]]* [[CP2]] // // CK19-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK19-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 - // CK19-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] - // CK19-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] - // CK19-DAG: [[CBPVAL3]] = bitcast double* [[VAR3:%.+]] to i8* - // CK19-DAG: [[CPVAL3]] = bitcast double* [[SEC3:%.+]] to i8* + // CK19-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to double** + // CK19-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to double** + // CK19-DAG: store double* [[VAR3:%.+]], double** [[CBP3]] + // CK19-DAG: store double* [[SEC3:%.+]], double** [[CP3]] // CK19-DAG: [[SEC3]] = getelementptr {{.*}}double* [[SEC33:%.+]], i[[Z]] 0 // CK19-DAG: [[SEC33]] = getelementptr {{.*}}double* [[SEC333:%.+]], i[[Z]] [[IDX3:%.+]] // CK19-DAG: [[IDX3]] = mul nsw i[[Z]] %{{[^,]+}}, %{{[^,]+}} @@ -2013,10 +2019,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0]], [11 x [12 x [13 x double]]]** [[CP0]] // CK19: call void [[CALL32:@.+]]([11 x [12 x [13 x double]]]* {{[^,]+}}) #pragma omp target map(marras) @@ -2031,10 +2037,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [12 x [13 x double]]* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [12 x [13 x double]]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [12 x [13 x double]]* [[SEC0:%.+]], [12 x [13 x double]]** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.+}}[11 x [12 x [13 x double]]]* [[VAR0]], i[[Z]] 0, i[[Z]] 0 // CK19: call void [[CALL33:@.+]]([11 x [12 x [13 x double]]]* {{[^,]+}}) @@ -2050,10 +2056,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [12 x [13 x double]]* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [12 x [13 x double]]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [12 x [13 x double]]* [[SEC0:%.+]], [12 x [13 x double]]** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.+}}[11 x [12 x [13 x double]]]* [[VAR0]], i[[Z]] 0, i[[Z]] 0 // CK19: call void [[CALL34:@.+]]([11 x [12 x [13 x double]]]* {{[^,]+}}) @@ -2072,11 +2078,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [13 x double]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [13 x double]* [[SEC0:%.+]], [13 x double]** [[CP0]] // CK19-DAG: store i[[Z]] [[CSVAL0:%[^,]+]], i[[Z]]* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [13 x double]* [[SEC0:%.+]] to i8* // CK19-DAG: [[SEC0]] = getelementptr {{.+}}[12 x [13 x double]]* [[SEC00:%[^,]+]], i[[Z]] 0, i[[Z]] 0 // CK19-DAG: [[SEC00]] = getelementptr {{.+}}[11 x [12 x [13 x double]]]* [[VAR0]], i[[Z]] 0, i[[Z]] 1 // CK19-DAG: [[CSVAL0]] = mul nuw i[[Z]] %{{[^,]+}}, 104 @@ -2094,10 +2100,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [13 x double]* [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [13 x double]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [13 x double]* [[SEC0:%.+]], [13 x double]** [[CP0]] // CK19-DAG: [[SEC0]] = getelementptr {{.+}}[13 x double]* [[SEC00:%[^,]+]], i{{.+}} 0 // CK19-DAG: [[SEC00]] = getelementptr {{.+}}[12 x [13 x double]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[SEC000]] = getelementptr {{.+}}[11 x [12 x [13 x double]]]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 @@ -2117,27 +2123,29 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CP0]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [13 x double]** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [13 x double]** + // CK19-DAG: store [13 x double]* [[VAR2:%.+]], [13 x double]** [[CBP2]] + // CK19-DAG: store [13 x double]* [[VAR2]], [13 x double]** [[CP2]] // CK19-DAG: store i[[Z]] [[CSVAL2:%[^,]+]], i[[Z]]* [[S2]] - // CK19-DAG: [[CBPVAL2]] = bitcast [13 x double]* [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast [13 x double]* [[VAR2]] to i8* // CK19-DAG: [[CSVAL2]] = mul nuw i[[Z]] %{{[^,]+}}, 104 // CK19: call void [[CALL37:@.+]](i[[Z]] 11, i[[Z]] %{{[^,]+}}, [13 x double]* %{{[^,]+}}) @@ -2155,27 +2163,29 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CP0]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [13 x double]** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [13 x double]** + // CK19-DAG: store [13 x double]* [[VAR2:%.+]], [13 x double]** [[CBP2]] + // CK19-DAG: store [13 x double]* [[SEC2:%.+]], [13 x double]** [[CP2]] // CK19-DAG: store i[[Z]] [[CSVAL2:%[^,]+]], i[[Z]]* [[S2]] - // CK19-DAG: [[CBPVAL2]] = bitcast [13 x double]* [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast [13 x double]* [[SEC2:%.+]] to i8* // CK19-DAG: [[SEC2]] = getelementptr {{.+}}[13 x double]* [[VAR2]], i[[Z]] [[SEC22:%[^,]+]] // CK19-DAG: [[SEC22]] = mul nsw i[[Z]] 0, %{{[^,]+}} // CK19-DAG: [[CSVAL2]] = mul nuw i[[Z]] %{{[^,]+}}, 104 @@ -2195,27 +2205,29 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CP0]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [13 x double]** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [13 x double]** + // CK19-DAG: store [13 x double]* [[VAR2:%.+]], [13 x double]** [[CBP2]] + // CK19-DAG: store [13 x double]* [[SEC2:%.+]], [13 x double]** [[CP2]] // CK19-DAG: store i[[Z]] [[CSVAL2:%[^,]+]], i[[Z]]* [[S2]] - // CK19-DAG: [[CBPVAL2]] = bitcast [13 x double]* [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast [13 x double]* [[SEC2:%.+]] to i8* // CK19-DAG: [[SEC2]] = getelementptr {{.+}}[13 x double]* [[VAR2]], i[[Z]] [[SEC22:%[^,]+]] // CK19-DAG: [[SEC22]] = mul nsw i[[Z]] 0, %{{[^,]+}} // CK19-DAG: [[CSVAL2]] = mul nuw i[[Z]] %{{[^,]+}}, 104 @@ -2235,27 +2247,29 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CP0]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[S1:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // CK19-DAG: store i[[Z]] {{8|4}}, i[[Z]]* [[S1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[S2:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [13 x double]** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [13 x double]** + // CK19-DAG: store [13 x double]* [[VAR2:%.+]], [13 x double]** [[CBP2]] + // CK19-DAG: store [13 x double]* [[SEC2:%.+]], [13 x double]** [[CP2]] // CK19-DAG: store i[[Z]] [[CSVAL2:%[^,]+]], i[[Z]]* [[S2]] - // CK19-DAG: [[CBPVAL2]] = bitcast [13 x double]* [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast [13 x double]* [[SEC2:%.+]] to i8* // CK19-DAG: [[SEC2]] = getelementptr {{.+}}[13 x double]* [[SEC22:%[^,]+]], i[[Z]] 0 // CK19-DAG: [[SEC22]] = getelementptr {{.+}}[13 x double]* [[VAR2]], i[[Z]] [[SEC222:%[^,]+]] // CK19-DAG: [[SEC222]] = mul nsw i[[Z]] 1, %{{[^,]+}} @@ -2273,22 +2287,24 @@ void explicit_maps_single (int ii){ // // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[BP0]] - // CK19-DAG: store i8* inttoptr (i[[Z]] 11 to i8*), i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i[[Z]]* + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i[[Z]]* + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CBP0]] + // CK19-DAG: store i[[Z]] 11, i[[Z]]* [[CP0]] // // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = inttoptr i[[Z]] [[VAR1:%.+]] to i8* - // CK19-DAG: [[CPVAL1]] = inttoptr i[[Z]] [[VAR11:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK19-DAG: store i[[Z]] [[VAR1:%.+]], i[[Z]]* [[CBP1]] + // CK19-DAG: store i[[Z]] [[VAR11:%.+]], i[[Z]]* [[CP1]] // // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK19-DAG: [[CBPVAL2]] = bitcast [13 x double]* [[VAR2:%.+]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast [13 x double]* [[SEC2:%.+]] to i8* + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [13 x double]** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [13 x double]** + // CK19-DAG: store [13 x double]* [[VAR2:%.+]], [13 x double]** [[CBP2]] + // CK19-DAG: store [13 x double]* [[SEC2:%.+]], [13 x double]** [[CP2]] // CK19-DAG: [[SEC2]] = getelementptr {{.+}}[13 x double]* [[SEC22:%[^,]+]], i[[Z]] 0 // CK19-DAG: [[SEC22]] = getelementptr {{.+}}[13 x double]* [[VAR2]], i[[Z]] [[SEC222:%[^,]+]] // CK19-DAG: [[SEC222]] = mul nsw i[[Z]] 0, %{{[^,]+}} @@ -2306,20 +2322,20 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK19-DAG: [[CBPVAL0]] = bitcast double*** [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast double*** [[SEC0:%.+]] to i8* + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to double**** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**** + // CK19-DAG: store double*** [[VAR0:%.+]], double**** [[CBP0]] + // CK19-DAG: store double*** [[SEC0:%.+]], double**** [[CP0]] // CK19-DAG: [[VAR0]] = load double***, double**** [[PTR:%[^,]+]], // CK19-DAG: [[SEC0]] = getelementptr {{.*}}double*** [[SEC00:[^,]+]], i{{.+}} 0 // CK19-DAG: [[SEC00]] = load double***, double**** [[PTR]], // CK19-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK19-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK19-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK19-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK19-DAG: [[CBPVAL1]] = bitcast double*** [[SEC0]] to i8* - // CK19-DAG: [[CPVAL1]] = bitcast double** [[SEC1:%.+]] to i8* + // CK19-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double**** + // CK19-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double*** + // CK19-DAG: store double*** [[SEC0]], double**** [[CBP1]] + // CK19-DAG: store double** [[SEC1:%.+]], double*** [[CP1]] // CK19-DAG: [[SEC1]] = getelementptr {{.*}}double** [[SEC11:[^,]+]], i{{.+}} 2 // CK19-DAG: [[SEC11]] = load double**, double*** [[SEC111:%[^,]+]], // CK19-DAG: [[SEC111]] = getelementptr {{.*}}double*** [[SEC1111:[^,]+]], i{{.+}} 0 @@ -2327,10 +2343,10 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK19-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK19-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK19-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK19-DAG: [[CBPVAL2]] = bitcast double** [[SEC1]] to i8* - // CK19-DAG: [[CPVAL2]] = bitcast double* [[SEC2:%.+]] to i8* + // CK19-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to double*** + // CK19-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double** + // CK19-DAG: store double** [[SEC1]], double*** [[CBP2]] + // CK19-DAG: store double* [[SEC2:%.+]], double** [[CP2]] // CK19-DAG: [[SEC2]] = getelementptr {{.*}}double* [[SEC22:[^,]+]], i{{.+}} 0 // CK19-DAG: [[SEC22]] = load double*, double** [[SEC222:%[^,]+]], // CK19-DAG: [[SEC222]] = getelementptr {{.*}}double** [[SEC2222:[^,]+]], i{{.+}} 2 @@ -2354,11 +2370,11 @@ void explicit_maps_single (int ii){ // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK19-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK19-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK19-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [11 x [12 x [13 x double]]]** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [13 x double]** + // CK19-DAG: store [11 x [12 x [13 x double]]]* [[VAR0:%.+]], [11 x [12 x [13 x double]]]** [[CBP0]] + // CK19-DAG: store [13 x double]* [[SEC0:%.+]], [13 x double]** [[CP0]] // CK19-DAG: store i[[Z]] [[CSVAL0:%[^,]+]], i[[Z]]* [[S0]] - // CK19-DAG: [[CBPVAL0]] = bitcast [11 x [12 x [13 x double]]]* [[VAR0:%.+]] to i8* - // CK19-DAG: [[CPVAL0]] = bitcast [13 x double]* [[SEC0:%.+]] to i8* // CK19-DAG: [[SEC0]] = getelementptr {{.+}}[12 x [13 x double]]* [[SEC00:%[^,]+]], i[[Z]] 0, i[[Z]] 0 // CK19-DAG: [[SEC00]] = getelementptr {{.+}}[11 x [12 x [13 x double]]]* [[VAR0]], i[[Z]] 0, i[[Z]] 1 // CK19-DAG: [[CSVAL0]] = mul nuw i[[Z]] %{{[^,]+}}, 104 @@ -2453,10 +2469,10 @@ void explicit_maps_references_and_function_args (int a, float b, int (&c)[10], f // CK20-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK20-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK20-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK20-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK20-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK20-DAG: [[CPVAL0]] = bitcast i32* [[RVAR00:%.+]] to i8* + // CK20-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK20-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK20-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK20-DAG: store i32* [[RVAR00:%.+]], i32** [[CP0]] // CK20-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK20-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -2473,10 +2489,10 @@ void explicit_maps_references_and_function_args (int a, float b, int (&c)[10], f // CK20-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK20-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK20-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK20-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK20-DAG: [[CBPVAL0]] = bitcast [10 x i32]* [[RVAR0:%.+]] to i8* - // CK20-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK20-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [10 x i32]** + // CK20-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK20-DAG: store [10 x i32]* [[RVAR0:%.+]], [10 x i32]** [[CBP0]] + // CK20-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK20-DAG: [[SEC0]] = getelementptr {{.*}}[10 x i32]* [[RVAR00:%.+]], i{{.+}} 0, i{{.+}} 0 // CK20-DAG: [[RVAR0]] = load [10 x i32]*, [10 x i32]** [[VAR0:%[^,]+]] // CK20-DAG: [[RVAR00]] = load [10 x i32]*, [10 x i32]** [[VAR0]] @@ -2494,10 +2510,10 @@ void explicit_maps_references_and_function_args (int a, float b, int (&c)[10], f // CK20-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK20-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK20-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK20-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK20-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK20-DAG: [[CPVAL0]] = bitcast float* [[VAR0]] to i8* + // CK20-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK20-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK20-DAG: store float* [[VAR0:%.+]], float** [[CBP0]] + // CK20-DAG: store float* [[VAR0]], float** [[CP0]] // CK20: call void [[CALL02:@.+]](float* {{[^,]+}}) #pragma omp target map(from:b) @@ -2512,10 +2528,10 @@ void explicit_maps_references_and_function_args (int a, float b, int (&c)[10], f // CK20-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK20-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK20-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK20-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK20-DAG: [[CBPVAL0]] = bitcast float* [[RVAR0:%.+]] to i8* - // CK20-DAG: [[CPVAL0]] = bitcast float* [[SEC0:%.+]] to i8* + // CK20-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK20-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK20-DAG: store float* [[RVAR0:%.+]], float** [[CBP0]] + // CK20-DAG: store float* [[SEC0:%.+]], float** [[CP0]] // CK20-DAG: [[RVAR0]] = load float*, float** [[VAR0:%[^,]+]] // CK20-DAG: [[SEC0]] = getelementptr {{.*}}float* [[RVAR00:%.+]], i{{.+}} 2 // CK20-DAG: [[RVAR00]] = load float*, float** [[VAR0]] @@ -2580,10 +2596,10 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK21-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK21-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK21-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0:%.+]], i{{.+}} 0, i{{.+}} 0 // CK21: call void [[CALL00:@.+]]([[ST]]* {{[^,]+}}) @@ -2599,10 +2615,10 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK21-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK21-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK21-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK21-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 0 // CK21-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -2620,18 +2636,18 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast float** [[SEC0:%.+]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float*** + // CK21-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK21-DAG: store float** [[SEC0:%.+]], float*** [[CP0]] // CK21-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 // CK21-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK21-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK21-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK21-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK21-DAG: [[CBPVAL1]] = bitcast float** [[SEC0]] to i8* - // CK21-DAG: [[CPVAL1]] = bitcast float* [[SEC1:%.+]] to i8* + // CK21-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to float*** + // CK21-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to float** + // CK21-DAG: store float** [[SEC0]], float*** [[CBP1]] + // CK21-DAG: store float* [[SEC1:%.+]], float** [[CP1]] // CK21-DAG: [[SEC1]] = getelementptr {{.*}}float* [[RVAR1:%[^,]+]], i{{.+}} 123 // CK21-DAG: [[RVAR1]] = load float*, float** [[SEC1_:%[^,]+]] // CK21-DAG: [[SEC1_]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 @@ -2649,10 +2665,10 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast [123 x float]* [[VAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast [123 x float]* [[VAR0]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [123 x float]** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [123 x float]** + // CK21-DAG: store [123 x float]* [[VAR0:%.+]], [123 x float]** [[CBP0]] + // CK21-DAG: store [123 x float]* [[VAR0]], [123 x float]** [[CP0]] // CK21: call void [[CALL03:@.+]]([123 x float]* {{[^,]+}}) #pragma omp target map(from:la) @@ -2667,10 +2683,10 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK21-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK21-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK21: call void [[CALL04:@.+]](i32* {{[^,]+}}) #pragma omp target map(from:arg) @@ -2686,18 +2702,18 @@ struct CC { // CK21-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK21-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK21-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK21-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK21-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK21-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK21-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK21-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK21-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK21-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 // CK21-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK21-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK21-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK21-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK21-DAG: [[CBPVAL1]] = bitcast [[ST]]* [[VAR1:%.+]] to i8* - // CK21-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK21-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[ST]]** + // CK21-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK21-DAG: store [[ST]]* [[VAR1:%.+]], [[ST]]** [[CBP1]] + // CK21-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK21-DAG: [[SEC1]] = getelementptr {{.*}}[[ST]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK21: call void [[CALL05:@.+]]([[ST]]* {{[^,]+}}) @@ -2809,8 +2825,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast (i32* @a to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast (i32* @a to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK22-DAG: store i32* @a, i32** [[CBP0]] + // CK22-DAG: store i32* @a, i32** [[CP0]] // CK22: call void [[CALL00:@.+]](i32* {{[^,]+}}) #pragma omp target map(a) @@ -2823,8 +2841,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x i32]* @c to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([100 x i32]* @c to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x i32]** + // CK22-DAG: store [100 x i32]* @c, [100 x i32]** [[CBP0]] + // CK22-DAG: store [100 x i32]* @c, [100 x i32]** [[CP0]] // CK22: call void [[CALL01:@.+]]([100 x i32]* {{[^,]+}}) #pragma omp target map(c) @@ -2837,8 +2857,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast (i32** @d to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast (i32** @d to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32*** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32*** + // CK22-DAG: store i32** @d, i32*** [[CBP0]] + // CK22-DAG: store i32** @d, i32*** [[CP0]] // CK22: call void [[CALL02:@.+]](i32** {{[^,]+}}) #pragma omp target map(d) @@ -2851,8 +2873,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x i32]* @c to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast (i32* getelementptr inbounds ([100 x i32], [100 x i32]* @c, i{{.+}} 0, i{{.+}} 1) to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x i32]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK22-DAG: store [100 x i32]* @c, [100 x i32]** [[CBP0]] + // CK22-DAG: store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @c, i{{.+}} 0, i{{.+}} 1), i32** [[CP0]] // CK22: call void [[CALL03:@.+]]([100 x i32]* {{[^,]+}}) #pragma omp target map(c[1:4]) @@ -2865,10 +2889,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK22-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK22-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK22-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK22-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK22-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK22-DAG: [[RVAR0]] = load i32*, i32** @d // CK22-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 2 // CK22-DAG: [[RVAR00]] = load i32*, i32** @d @@ -2884,8 +2908,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([[ST]]* @sa to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[ST]]* @sa to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK22-DAG: store [[ST]]* @sa, [[ST]]** [[CBP0]] + // CK22-DAG: store [[ST]]* @sa, [[ST]]** [[CP0]] // CK22: call void [[CALL05:@.+]]([[ST]]* {{[^,]+}}) #pragma omp target map(sa) @@ -2898,8 +2924,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x [[ST]]]* @sc to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([100 x [[ST]]]* @sc to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x [[ST]]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x [[ST]]]** + // CK22-DAG: store [100 x [[ST]]]* @sc, [100 x [[ST]]]** [[CBP0]] + // CK22-DAG: store [100 x [[ST]]]* @sc, [100 x [[ST]]]** [[CP0]] // CK22: call void [[CALL06:@.+]]([100 x [[ST]]]* {{[^,]+}}) #pragma omp target map(sc) @@ -2912,8 +2940,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([[ST]]** @sd to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[ST]]** @sd to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]*** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]*** + // CK22-DAG: store [[ST]]** @sd, [[ST]]*** [[CBP0]] + // CK22-DAG: store [[ST]]** @sd, [[ST]]*** [[CP0]] // CK22: call void [[CALL07:@.+]]([[ST]]** {{[^,]+}}) #pragma omp target map(sd) @@ -2926,8 +2956,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x [[ST]]]* @sc to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[ST]]* getelementptr inbounds ([100 x [[ST]]], [100 x [[ST]]]* @sc, i{{.+}} 0, i{{.+}} 1) to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x [[ST]]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK22-DAG: store [100 x [[ST]]]* @sc, [100 x [[ST]]]** [[CBP0]] + // CK22-DAG: store [[ST]]* getelementptr inbounds ([100 x [[ST]]], [100 x [[ST]]]* @sc, i{{.+}} 0, i{{.+}} 1), [[ST]]** [[CP0]] // CK22: call void [[CALL08:@.+]]([100 x [[ST]]]* {{[^,]+}}) #pragma omp target map(sc[1:4]) @@ -2940,10 +2972,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK22-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK22-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[RVAR0:%.+]] to i8* - // CK22-DAG: [[CPVAL0]] = bitcast [[ST]]* [[SEC0:%.+]] to i8* + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK22-DAG: store [[ST]]* [[RVAR0:%.+]], [[ST]]** [[CBP0]] + // CK22-DAG: store [[ST]]* [[SEC0:%.+]], [[ST]]** [[CP0]] // CK22-DAG: [[RVAR0]] = load [[ST]]*, [[ST]]** @sd // CK22-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[RVAR00:%.+]], i{{.+}} 2 // CK22-DAG: [[RVAR00]] = load [[ST]]*, [[ST]]** @sd @@ -2959,8 +2991,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([[STT]]* @sta to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[STT]]* @sta to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[STT]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[STT]]** + // CK22-DAG: store [[STT]]* @sta, [[STT]]** [[CBP0]] + // CK22-DAG: store [[STT]]* @sta, [[STT]]** [[CP0]] // CK22: call void [[CALL10:@.+]]([[STT]]* {{[^,]+}}) #pragma omp target map(sta) @@ -2973,8 +3007,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x [[STT]]]* @stc to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([100 x [[STT]]]* @stc to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x [[STT]]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x [[STT]]]** + // CK22-DAG: store [100 x [[STT]]]* @stc, [100 x [[STT]]]** [[CBP0]] + // CK22-DAG: store [100 x [[STT]]]* @stc, [100 x [[STT]]]** [[CP0]] // CK22: call void [[CALL11:@.+]]([100 x [[STT]]]* {{[^,]+}}) #pragma omp target map(stc) @@ -2987,8 +3023,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([[STT]]** @std to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[STT]]** @std to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[STT]]*** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[STT]]*** + // CK22-DAG: store [[STT]]** @std, [[STT]]*** [[CBP0]] + // CK22-DAG: store [[STT]]** @std, [[STT]]*** [[CP0]] // CK22: call void [[CALL12:@.+]]([[STT]]** {{[^,]+}}) #pragma omp target map(std) @@ -3001,8 +3039,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* bitcast ([100 x [[STT]]]* @stc to i8*), i8** [[BP0]] - // CK22-DAG: store i8* bitcast ([[STT]]* getelementptr inbounds ([100 x [[STT]]], [100 x [[STT]]]* @stc, i{{.+}} 0, i{{.+}} 1) to i8*), i8** [[P0]] + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x [[STT]]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[STT]]** + // CK22-DAG: store [100 x [[STT]]]* @stc, [100 x [[STT]]]** [[CBP0]] + // CK22-DAG: store [[STT]]* getelementptr inbounds ([100 x [[STT]]], [100 x [[STT]]]* @stc, i{{.+}} 0, i{{.+}} 1), [[STT]]** [[CP0]] // CK22: call void [[CALL13:@.+]]([100 x [[STT]]]* {{[^,]+}}) #pragma omp target map(stc[1:4]) @@ -3015,10 +3055,10 @@ int explicit_maps_globals(void){ // CK22-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK22-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK22-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK22-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK22-DAG: [[CBPVAL0]] = bitcast [[STT]]* [[RVAR0:%.+]] to i8* - // CK22-DAG: [[CPVAL0]] = bitcast [[STT]]* [[SEC0:%.+]] to i8* + // CK22-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[STT]]** + // CK22-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[STT]]** + // CK22-DAG: store [[STT]]* [[RVAR0:%.+]], [[STT]]** [[CBP0]] + // CK22-DAG: store [[STT]]* [[SEC0:%.+]], [[STT]]** [[CP0]] // CK22-DAG: [[RVAR0]] = load [[STT]]*, [[STT]]** @std // CK22-DAG: [[SEC0]] = getelementptr {{.*}}[[STT]]* [[RVAR00:%.+]], i{{.+}} 2 // CK22-DAG: [[RVAR00]] = load [[STT]]*, [[STT]]** @std @@ -3088,10 +3128,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast i32* [[VAR00:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK23-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK23-DAG: store i32* [[VAR00:%.+]], i32** [[CP0]] // CK23-DAG: [[VAR0]] = load i32*, i32** [[CAP0:%[^,]+]] // CK23-DAG: [[CAP0]] = getelementptr inbounds [[SA]], [[SA]] // CK23-DAG: [[VAR00]] = load i32*, i32** [[CAP00:%[^,]+]] @@ -3107,10 +3147,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast float* [[VAR00:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK23-DAG: store float* [[VAR0:%.+]], float** [[CBP0]] + // CK23-DAG: store float* [[VAR00:%.+]], float** [[CP0]] // CK23-DAG: [[VAR0]] = load float*, float** [[CAP0:%[^,]+]] // CK23-DAG: [[CAP0]] = getelementptr inbounds [[SA]], [[SA]] // CK23-DAG: [[VAR00]] = load float*, float** [[CAP00:%[^,]+]] @@ -3126,10 +3166,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast [100 x float]* [[VAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast [100 x float]* [[VAR00:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x float]** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [100 x float]** + // CK23-DAG: store [100 x float]* [[VAR0:%.+]], [100 x float]** [[CBP0]] + // CK23-DAG: store [100 x float]* [[VAR00:%.+]], [100 x float]** [[CP0]] // CK23-DAG: [[VAR0]] = load [100 x float]*, [100 x float]** [[CAP0:%[^,]+]] // CK23-DAG: [[CAP0]] = getelementptr inbounds [[SA]], [[SA]] // CK23-DAG: [[VAR00]] = load [100 x float]*, [100 x float]** [[CAP00:%[^,]+]] @@ -3146,10 +3186,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast float** [[VAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast float** [[VAR00:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float*** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float*** + // CK23-DAG: store float** [[VAR0:%.+]], float*** [[CBP0]] + // CK23-DAG: store float** [[VAR00:%.+]], float*** [[CP0]] // CK23-DAG: [[VAR0]] = load float**, float*** [[CAP0:%[^,]+]] // CK23-DAG: [[CAP0]] = getelementptr inbounds [[SA]], [[SA]] // CK23-DAG: [[VAR00]] = load float**, float*** [[CAP00:%[^,]+]] @@ -3165,10 +3205,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast [100 x float]* [[VAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast float* [[SEC0:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [100 x float]** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK23-DAG: store [100 x float]* [[VAR0:%.+]], [100 x float]** [[CBP0]] + // CK23-DAG: store float* [[SEC0:%.+]], float** [[CP0]] // CK23-DAG: [[SEC0]] = getelementptr {{.*}}[100 x float]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 2 // CK23-DAG: [[VAR0]] = load [100 x float]*, [100 x float]** [[CAP0:%[^,]+]] // CK23-DAG: [[CAP0]] = getelementptr inbounds [[SA]], [[SA]] @@ -3186,10 +3226,10 @@ int explicit_maps_inside_captured(int a){ // CK23-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK23-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK23-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK23-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK23-DAG: [[CBPVAL0]] = bitcast float* [[RVAR0:%.+]] to i8* - // CK23-DAG: [[CPVAL0]] = bitcast float* [[SEC0:%.+]] to i8* + // CK23-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK23-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK23-DAG: store float* [[RVAR0:%.+]], float** [[CBP0]] + // CK23-DAG: store float* [[SEC0:%.+]], float** [[CP0]] // CK23-DAG: [[RVAR0]] = load float*, float** [[VAR0:%[^,]+]] // CK23-DAG: [[SEC0]] = getelementptr {{.*}}float* [[RVAR00:%.+]], i{{.+}} 2 // CK23-DAG: [[RVAR00]] = load float*, float** [[VAR00:%[^,]+]] @@ -3328,10 +3368,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 0 // CK24: call void [[CALL01:@.+]]([[SC]]* {{[^,]+}}) @@ -3345,10 +3385,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]* [[SEC0:%.+]], [[SA]]** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 @@ -3363,10 +3403,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SA]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SB]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 @@ -3382,10 +3422,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x i32]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 3 @@ -3400,18 +3440,18 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast [[SB]]* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SB]]** +// CK24-DAG: store [[SB]]** [[SEC0]], [[SB]]*** [[CBP1]] +// CK24-DAG: store [[SB]]* [[SEC1:%.+]], [[SB]]** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 @@ -3427,10 +3467,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SA]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[10 x [[SA]]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SB]]* [[SEC0000:%[^,]+]], i{{.+}} 0, i{{.+}} 2 @@ -3447,20 +3487,20 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x [[SA]]*]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SB]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SA]]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SA]]*, [[SA]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[10 x [[SA]]*]* [[SEC1111:%[^,]+]], i{{.+}} 0, i{{.+}} 3 @@ -3478,18 +3518,18 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SB]]** [[SEC0]], [[SB]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 @@ -3505,19 +3545,19 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SA]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SA]]*, [[SA]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SB]]* [[SEC1111:[^,]+]], i{{.+}} 0, i{{.+}} 4 @@ -3534,10 +3574,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x i32]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SA]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SB]]* [[SEC0000:%[^,]+]], i{{.+}} 0, i{{.+}} 1 @@ -3554,19 +3594,19 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[10 x i32]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC11]] = getelementptr {{.*}}[[SA]]* [[SEC111:%[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[SEC111]] = load [[SA]]*, [[SA]]** [[SEC1111:%[^,]+]], @@ -3584,28 +3624,28 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast [[SA]]** [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SA]]*** +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CBP1]] +// CK24-DAG: store [[SA]]** [[SEC1:%.+]], [[SA]]*** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR0]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 -// CK24-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] -// CK24-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] -// CK24-DAG: [[CBPVAL2]] = bitcast [[SA]]** [[SEC1]] to i8* -// CK24-DAG: [[CPVAL2]] = bitcast [[SA]]** [[SEC2:%.+]] to i8* +// CK24-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [[SA]]*** +// CK24-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [[SA]]*** +// CK24-DAG: store [[SA]]** [[SEC1:%.+]], [[SA]]*** [[CBP2]] +// CK24-DAG: store [[SA]]** [[SEC2:%.+]], [[SA]]*** [[CP2]] // CK24-DAG: [[SEC2]] = getelementptr {{.*}}[[SA]]* [[SEC22:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC22]] = load [[SA]]*, [[SA]]** [[SEC222:%[^,]+]], // CK24-DAG: [[SEC222]] = getelementptr {{.*}}[[SB]]* [[SEC2222:%[^,]+]], i{{.+}} 0, i{{.+}} 4 @@ -3614,10 +3654,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 -// CK24-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] -// CK24-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] -// CK24-DAG: [[CBPVAL3]] = bitcast [[SA]]** [[SEC2]] to i8* -// CK24-DAG: [[CPVAL3]] = bitcast i32* [[SEC3:%.+]] to i8* +// CK24-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to [[SA]]*** +// CK24-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to i32** +// CK24-DAG: store [[SA]]** [[SEC2]], [[SA]]*** [[CBP3]] +// CK24-DAG: store i32* [[SEC3:%.+]], i32** [[CP3]] // CK24-DAG: [[SEC3]] = getelementptr {{.*}}[[SA]]* [[SEC33:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC33]] = load [[SA]]*, [[SA]]** [[SEC333:%[^,]+]], // CK24-DAG: [[SEC333]] = getelementptr {{.*}}[[SA]]* [[SEC3333:%[^,]+]], i{{.+}} 0, i{{.+}} 1 @@ -3640,10 +3680,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[VAR0]] = load [[SC]]*, [[SC]]** %{{.+}} @@ -3660,10 +3700,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]* [[SEC0:%.+]], [[SA]]** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 1 @@ -3681,10 +3721,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SA]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SB]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 1 @@ -3703,10 +3743,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x i32]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 3 @@ -3724,18 +3764,18 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast [[SB]]* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SB]]** +// CK24-DAG: store [[SB]]** [[SEC0]], [[SB]]*** [[CBP1]] +// CK24-DAG: store [[SB]]* [[SEC1:%.+]], [[SB]]** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR000:%.+]], i{{.+}} 0, i{{.+}} 2 @@ -3755,10 +3795,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SA]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[10 x [[SA]]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SB]]* [[SEC0000:%[^,]+]], i{{.+}} 0, i{{.+}} 2 @@ -3778,20 +3818,20 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x [[SA]]*]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SB]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SA]]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SA]]*, [[SA]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[10 x [[SA]]*]* [[SEC1111:%[^,]+]], i{{.+}} 0, i{{.+}} 3 @@ -3813,18 +3853,18 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SB]]** [[SEC0]], [[SB]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR000:%.+]], i{{.+}} 0, i{{.+}} 2 @@ -3844,19 +3884,19 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SA]]* [[SEC11:%[^,]+]], i{{.+}} 0 // CK24-DAG: [[SEC11]] = load [[SA]]*, [[SA]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SB]]* [[SEC1111:[^,]+]], i{{.+}} 0, i{{.+}} 4 @@ -3877,10 +3917,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[10 x i32]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SA]]* [[SEC000:%[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[SEC000]] = getelementptr {{.*}}[[SB]]* [[SEC0000:%[^,]+]], i{{.+}} 0, i{{.+}} 1 @@ -3900,19 +3940,19 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SA]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SA]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SA]]** [[SEC0:%.+]], [[SA]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SB]]* [[SEC00:%[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC00]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SA]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SA]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** +// CK24-DAG: store [[SA]]** [[SEC0]], [[SA]]*** [[CBP1]] +// CK24-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[10 x i32]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC11]] = getelementptr {{.*}}[[SA]]* [[SEC111:%[^,]+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[SEC111]] = load [[SA]]*, [[SA]]** [[SEC1111:%[^,]+]], @@ -3934,28 +3974,28 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK24-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK24-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK24-DAG: [[CBPVAL0]] = bitcast [[SC]]* [[VAR0:%.+]] to i8* -// CK24-DAG: [[CPVAL0]] = bitcast [[SB]]** [[SEC0:%.+]] to i8* +// CK24-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SC]]** +// CK24-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SB]]*** +// CK24-DAG: store [[SC]]* [[VAR0:%.+]], [[SC]]** [[CBP0]] +// CK24-DAG: store [[SB]]** [[SEC0:%.+]], [[SB]]*** [[CP0]] // CK24-DAG: [[SEC0]] = getelementptr {{.*}}[[SC]]* [[VAR00:%.+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK24-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK24-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK24-DAG: [[CBPVAL1]] = bitcast [[SB]]** [[SEC0]] to i8* -// CK24-DAG: [[CPVAL1]] = bitcast [[SA]]** [[SEC1:%.+]] to i8* +// CK24-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SB]]*** +// CK24-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SA]]*** +// CK24-DAG: store [[SB]]** [[SEC0]], [[SB]]*** [[CBP1]] +// CK24-DAG: store [[SA]]** [[SEC1:%.+]], [[SA]]*** [[CP1]] // CK24-DAG: [[SEC1]] = getelementptr {{.*}}[[SB]]* [[SEC11:%[^,]+]], i{{.+}} 0, i{{.+}} 4 // CK24-DAG: [[SEC11]] = load [[SB]]*, [[SB]]** [[SEC111:%[^,]+]], // CK24-DAG: [[SEC111]] = getelementptr {{.*}}[[SC]]* [[VAR000:%.+]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK24-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 -// CK24-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] -// CK24-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] -// CK24-DAG: [[CBPVAL2]] = bitcast [[SA]]** [[SEC1]] to i8* -// CK24-DAG: [[CPVAL2]] = bitcast [[SA]]** [[SEC2:%.+]] to i8* +// CK24-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [[SA]]*** +// CK24-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to [[SA]]*** +// CK24-DAG: store [[SA]]** [[SEC1]], [[SA]]*** [[CBP2]] +// CK24-DAG: store [[SA]]** [[SEC2:%.+]], [[SA]]*** [[CP2]] // CK24-DAG: [[SEC2]] = getelementptr {{.*}}[[SA]]* [[SEC22:%[^,]+]], i{{.+}} 0, i{{.+}} 1 // CK24-DAG: [[SEC22]] = load [[SA]]*, [[SA]]** [[SEC222:%[^,]+]], // CK24-DAG: [[SEC222]] = getelementptr {{.*}}[[SB]]* [[SEC2222:%[^,]+]], i{{.+}} 0, i{{.+}} 4 @@ -3964,10 +4004,10 @@ int explicit_maps_struct_fields(int a){ // CK24-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK24-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 -// CK24-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] -// CK24-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] -// CK24-DAG: [[CBPVAL3]] = bitcast [[SA]]** [[SEC2]] to i8* -// CK24-DAG: [[CPVAL3]] = bitcast i32* [[SEC3:%.+]] to i8* +// CK24-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to [[SA]]*** +// CK24-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to i32** +// CK24-DAG: store [[SA]]** [[SEC2]], [[SA]]*** [[CBP3]] +// CK24-DAG: store i32* [[SEC3:%.+]], i32** [[CP3]] // CK24-DAG: [[SEC3]] = getelementptr {{.*}}[[SA]]* [[SEC33:%[^,]+]], i{{.+}} 0, i{{.+}} 0 // CK24-DAG: [[SEC33]] = load [[SA]]*, [[SA]]** [[SEC333:%[^,]+]], // CK24-DAG: [[SEC333]] = getelementptr {{.*}}[[SA]]* [[SEC3333:%[^,]+]], i{{.+}} 0, i{{.+}} 1 @@ -4047,10 +4087,10 @@ struct CC { // CK25-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK25-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK25-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK25-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK25-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK25-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK25-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK25-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK25-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK25-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK25-DAG: [[SEC0]] = getelementptr {{.*}}[[ST]]* [[VAR0:%.+]], i{{.+}} 0, i{{.+}} 0 // CK25: call void [[CALL00:@.+]]([[ST]]* {{[^,]+}}) @@ -4068,10 +4108,10 @@ struct CC { // CK25-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK25-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK25-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK25-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK25-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK25-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK25-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK25-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK25-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK25-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK25: call void [[CALL01:@.+]](i32* {{[^,]+}}) #pragma omp target map(to:arg) @@ -4151,17 +4191,17 @@ struct CC { // CK26-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK26-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK26-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK26-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK26-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK26-DAG: [[CPVAL0]] = bitcast [[ST]]* [[VAR0]] to i8* + // CK26-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK26-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK26-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK26-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]] // CK26-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK26-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK26-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK26-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK26-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK26-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK26-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK26-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK26-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK26-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK26-DAG: [[VAR1]] = load i32*, i32** [[PVT:%.+]], // CK26-DAG: [[SEC1]] = load i32*, i32** [[PVT]], @@ -4178,17 +4218,17 @@ struct CC { // CK26-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK26-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK26-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK26-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK26-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK26-DAG: [[CPVAL0]] = bitcast [[ST]]* [[VAR0]] to i8* + // CK26-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK26-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK26-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK26-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]] // CK26-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK26-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK26-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK26-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK26-DAG: [[CBPVAL1]] = bitcast float* [[VAR1:%.+]] to i8* - // CK26-DAG: [[CPVAL1]] = bitcast float* [[SEC1:%.+]] to i8* + // CK26-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to float** + // CK26-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to float** + // CK26-DAG: store float* [[VAR1:%.+]], float** [[CBP1]] + // CK26-DAG: store float* [[SEC1:%.+]], float** [[CP1]] // CK26-DAG: [[VAR1]] = load float*, float** [[PVT:%.+]], // CK26-DAG: [[SEC1]] = load float*, float** [[PVT]], @@ -4205,17 +4245,17 @@ struct CC { // CK26-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK26-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK26-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK26-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK26-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK26-DAG: [[CPVAL0]] = bitcast [[ST]]* [[VAR0]] to i8* + // CK26-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK26-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK26-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK26-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]] // CK26-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK26-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK26-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK26-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK26-DAG: [[CBPVAL1]] = bitcast i32* [[VAR1:%.+]] to i8* - // CK26-DAG: [[CPVAL1]] = bitcast i32* [[SEC1:%.+]] to i8* + // CK26-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i32** + // CK26-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i32** + // CK26-DAG: store i32* [[VAR1:%.+]], i32** [[CBP1]] + // CK26-DAG: store i32* [[SEC1:%.+]], i32** [[CP1]] // CK26-DAG: [[VAR1]] = load i32*, i32** [[PVT:%.+]], // CK26-DAG: [[SEC1]] = load i32*, i32** [[PVT]], @@ -4232,17 +4272,17 @@ struct CC { // CK26-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK26-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK26-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK26-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK26-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* - // CK26-DAG: [[CPVAL0]] = bitcast [[ST]]* [[VAR0]] to i8* + // CK26-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK26-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]** + // CK26-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]] + // CK26-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]] // CK26-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK26-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK26-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK26-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK26-DAG: [[CBPVAL1]] = bitcast float* [[VAR1:%.+]] to i8* - // CK26-DAG: [[CPVAL1]] = bitcast float* [[SEC1:%.+]] to i8* + // CK26-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to float** + // CK26-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to float** + // CK26-DAG: store float* [[VAR1:%.+]], float** [[CBP1]] + // CK26-DAG: store float* [[SEC1:%.+]], float** [[CP1]] // CK26-DAG: [[VAR1]] = load float*, float** [[PVT:%.+]], // CK26-DAG: [[SEC1]] = load float*, float** [[PVT]], @@ -4335,10 +4375,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK27-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK27-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK27: call void [[CALL00:@.+]](i32* {{[^,]+}}) #pragma omp target @@ -4353,10 +4393,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK27-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK27-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK27-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK27-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 0 // CK27-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -4374,10 +4414,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK27-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK27-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK27-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK27-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} 0 // CK27-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -4395,10 +4435,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast i32* [[RVAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast i32* [[SEC0:%.+]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK27-DAG: store i32* [[RVAR0:%.+]], i32** [[CBP0]] + // CK27-DAG: store i32* [[SEC0:%.+]], i32** [[CP0]] // CK27-DAG: [[RVAR0]] = load i32*, i32** [[VAR0:%[^,]+]] // CK27-DAG: [[SEC0]] = getelementptr {{.*}}i32* [[RVAR00:%.+]], i{{.+}} %{{.+}} // CK27-DAG: [[RVAR00]] = load i32*, i32** [[VAR0]] @@ -4428,10 +4468,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK27-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK27-DAG: store i32* [[VAR0]], i32** [[CP0]] // CK27: call void [[CALL05:@.+]](i32* {{[^,]+}}) #pragma omp target firstprivate(pvtPtr) @@ -4453,10 +4493,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0 // CK27-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0 // CK27-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0 - // CK27-DAG: store i8* [[VALBP:%.+]], i8** [[BP1]], - // CK27-DAG: store i8* [[VALP:%.+]], i8** [[P1]], - // CK27-DAG: [[VALBP]] = inttoptr i[[Z]] [[VAL:%.+]] to i8* - // CK27-DAG: [[VALP]] = inttoptr i[[Z]] [[VAL:%.+]] to i8* + // CK27-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to i[[Z]]* + // CK27-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to i[[Z]]* + // CK27-DAG: store i[[Z]] [[VAL:%.+]], i[[Z]]* [[CBP1]] + // CK27-DAG: store i[[Z]] [[VAL]], i[[Z]]* [[CP1]] // CK27-DAG: [[VAL]] = load i[[Z]], i[[Z]]* [[ADDR:%.+]], // CK27-64-DAG: [[CADDR:%.+]] = bitcast i[[Z]]* [[ADDR]] to i32* // CK27-64-DAG: store i32 {{.+}}, i32* [[CADDR]], @@ -4482,10 +4522,10 @@ void zero_size_section_and_private_maps (int ii){ // CK27-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK27-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK27-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK27-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK27-DAG: [[CBPVAL0]] = bitcast [10 x i32]* [[VAR0:%.+]] to i8* - // CK27-DAG: [[CPVAL0]] = bitcast [10 x i32]* [[VAR0]] to i8* + // CK27-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [10 x i32]** + // CK27-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [10 x i32]** + // CK27-DAG: store [10 x i32]* [[VAR0:%.+]], [10 x i32]** [[CBP0]] + // CK27-DAG: store [10 x i32]* [[VAR0]], [10 x i32]** [[CP0]] // CK27: call void [[CALL09:@.+]]([10 x i32]* {{[^,]+}}) #pragma omp target firstprivate(pvtArr) @@ -4529,10 +4569,10 @@ void explicit_maps_pointer_references (int *p){ // CK28-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK28-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK28-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK28-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK28-DAG: [[CBPVAL0]] = bitcast i32** [[VAR0:%.+]] to i8* - // CK28-DAG: [[CPVAL0]] = bitcast i32** [[VAR1:%.+]] to i8* + // CK28-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32*** + // CK28-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32*** + // CK28-DAG: store i32** [[VAR0:%.+]], i32*** [[CBP0]] + // CK28-DAG: store i32** [[VAR1:%.+]], i32*** [[CP0]] // CK28-DAG: [[VAR0]] = load i32**, i32*** [[VAR00:%.+]], // CK28-DAG: [[VAR1]] = load i32**, i32*** [[VAR11:%.+]], @@ -4549,10 +4589,10 @@ void explicit_maps_pointer_references (int *p){ // CK28-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK28-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK28-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK28-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK28-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK28-DAG: [[CPVAL0]] = bitcast i32* [[VAR1:%.+]] to i8* + // CK28-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK28-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK28-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK28-DAG: store i32* [[VAR1:%.+]], i32** [[CP0]] // CK28-DAG: [[VAR0]] = load i32*, i32** [[VAR00:%.+]], // CK28-DAG: [[VAR00]] = load i32**, i32*** [[VAR000:%.+]], // CK28-DAG: [[VAR1]] = getelementptr inbounds i32, i32* [[VAR11:%.+]], i{{64|32}} 2 @@ -4609,36 +4649,36 @@ struct SSB{ // CK29-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK29-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK29-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK29-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK29-DAG: [[CBPVAL0]] = bitcast [[SSB]]* [[VAR0:%.+]] to i8* - // CK29-DAG: [[CPVAL0]] = bitcast [[SSA]]** [[VAR00:%.+]] to i8* + // CK29-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SSB]]** + // CK29-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SSA]]** + // CK29-DAG: store [[SSB]]* [[VAR0:%.+]], [[SSB]]** [[CBP0]] + // CK29-DAG: store [[SSA]]** [[VAR00:%.+]], [[SSA]]*** [[CP0]] // CK29-DAG: [[VAR0]] = load [[SSB]]*, [[SSB]]** % // CK29-DAG: [[VAR00]] = getelementptr inbounds [[SSB]], [[SSB]]* [[VAR0]], i32 0, i32 0 // CK29-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK29-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK29-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK29-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK29-DAG: [[CBPVAL1]] = bitcast [[SSA]]** [[VAR00]] to i8* - // CK29-DAG: [[CPVAL1]] = bitcast double*** [[VAR1:%.+]] to i8* + // CK29-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SSA]]*** + // CK29-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double**** + // CK29-DAG: store [[SSA]]** [[VAR00]], [[SSA]]*** [[CBP1]] + // CK29-DAG: store double*** [[VAR1:%.+]], double**** [[CP1]] // CK29-DAG: [[VAR1]] = getelementptr inbounds [[SSA]], [[SSA]]* %{{.+}}, i32 0, i32 1 // CK29-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK29-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK29-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK29-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK29-DAG: [[CBPVAL2]] = bitcast double*** [[VAR1]] to i8* - // CK29-DAG: [[CPVAL2]] = bitcast double** [[VAR2:%.+]] to i8* + // CK29-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to double**** + // CK29-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double*** + // CK29-DAG: store double*** [[VAR1]], double**** [[CBP2]] + // CK29-DAG: store double** [[VAR2:%.+]], double*** [[CP2]] // CK29-DAG: [[VAR2]] = load double**, double*** [[VAR22:%.+]], // CK29-DAG: [[VAR22]] = getelementptr inbounds [[SSA]], [[SSA]]* %{{.+}}, i32 0, i32 1 // CK29-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK29-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 - // CK29-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] - // CK29-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] - // CK29-DAG: [[CBPVAL3]] = bitcast double** [[VAR2]] to i8* - // CK29-DAG: [[CPVAL3]] = bitcast double* [[VAR3:%.+]] to i8* + // CK29-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to double*** + // CK29-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to double** + // CK29-DAG: store double** [[VAR2]], double*** [[CBP3]] + // CK29-DAG: store double* [[VAR3:%.+]], double** [[CP3]] // CK29-DAG: [[VAR3]] = getelementptr inbounds double, double* [[VAR33:%.+]], i{{.+}} 0 // CK29-DAG: [[VAR33]] = load double*, double** %{{.+}}, @@ -4656,34 +4696,34 @@ struct SSB{ // CK29-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK29-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK29-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK29-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK29-DAG: [[CBPVAL0]] = bitcast [[SSB]]* [[VAR0:%.+]] to i8* - // CK29-DAG: [[CPVAL0]] = bitcast [[SSA]]*** [[VAR00:%.+]] to i8* + // CK29-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SSB]]** + // CK29-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SSA]]**** + // CK29-DAG: store [[SSB]]* [[VAR0:%.+]], [[SSB]]** [[CBP0]] + // CK29-DAG: store [[SSA]]*** [[VAR00:%.+]], [[SSA]]**** [[CP0]] // CK29-DAG: [[VAR00]] = getelementptr inbounds [[SSB]], [[SSB]]* [[VAR0]], i32 0, i32 1 // CK29-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK29-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK29-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK29-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK29-DAG: [[CBPVAL1]] = bitcast [[SSA]]*** [[VAR00]] to i8* - // CK29-DAG: [[CPVAL1]] = bitcast [[SSA]]** [[VAR1:%.+]] to i8* + // CK29-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SSA]]**** + // CK29-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SSA]]*** + // CK29-DAG: store [[SSA]]*** [[VAR00]], [[SSA]]**** [[CBP1]] + // CK29-DAG: store [[SSA]]** [[VAR1:%.+]], [[SSA]]*** [[CP1]] // CK29-DAG: [[VAR1]] = load [[SSA]]**, [[SSA]]*** [[VAR00]], // CK29-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK29-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK29-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK29-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK29-DAG: [[CBPVAL2]] = bitcast [[SSA]]** [[VAR1]] to i8* - // CK29-DAG: [[CPVAL2]] = bitcast double** [[VAR2:%.+]] to i8* + // CK29-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [[SSA]]*** + // CK29-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double*** + // CK29-DAG: store [[SSA]]** [[VAR1]], [[SSA]]*** [[CBP2]] + // CK29-DAG: store double** [[VAR2:%.+]], double*** [[CP2]] // CK29-DAG: [[VAR2]] = getelementptr inbounds [[SSA]], [[SSA]]* %{{.+}}, i32 0, i32 0 // CK29-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK29-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 - // CK29-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] - // CK29-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] - // CK29-DAG: [[CBPVAL3]] = bitcast double** [[VAR2]] to i8* - // CK29-DAG: [[CPVAL3]] = bitcast double* [[VAR3:%.+]] to i8* + // CK29-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to double*** + // CK29-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to double** + // CK29-DAG: store double** [[VAR2]], double*** [[CBP3]] + // CK29-DAG: store double* [[VAR3:%.+]], double** [[CP3]] // CK29-DAG: [[VAR3]] = getelementptr inbounds double, double* [[VAR33:%.+]], i{{.+}} 0 // CK29-DAG: [[VAR33]] = load double*, double** %{{.+}}, @@ -4701,42 +4741,42 @@ struct SSB{ // CK29-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK29-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK29-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK29-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK29-DAG: [[CBPVAL0]] = bitcast [[SSB]]* [[VAR0:%.+]] to i8* - // CK29-DAG: [[CPVAL0]] = bitcast [[SSA]]*** [[VAR00:%.+]] to i8* + // CK29-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[SSB]]** + // CK29-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[SSA]]**** + // CK29-DAG: store [[SSB]]* [[VAR0:%.+]], [[SSB]]** [[CBP0]] + // CK29-DAG: store [[SSA]]*** [[VAR00:%.+]], [[SSA]]**** [[CP0]] // CK29-DAG: [[VAR00]] = getelementptr inbounds [[SSB]], [[SSB]]* [[VAR0]], i32 0, i32 1 // CK29-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK29-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK29-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] - // CK29-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK29-DAG: [[CBPVAL1]] = bitcast [[SSA]]*** [[VAR00]] to i8* - // CK29-DAG: [[CPVAL1]] = bitcast [[SSA]]** [[VAR1:%.+]] to i8* + // CK29-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to [[SSA]]**** + // CK29-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to [[SSA]]*** + // CK29-DAG: store [[SSA]]*** [[VAR00]], [[SSA]]**** [[CBP1]] + // CK29-DAG: store [[SSA]]** [[VAR1:%.+]], [[SSA]]*** [[CP1]] // CK29-DAG: [[VAR1]] = load [[SSA]]**, [[SSA]]*** [[VAR00]], // CK29-DAG: [[BP2:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 2 // CK29-DAG: [[P2:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 2 - // CK29-DAG: store i8* [[CBPVAL2:%[^,]+]], i8** [[BP2]] - // CK29-DAG: store i8* [[CPVAL2:%[^,]+]], i8** [[P2]] - // CK29-DAG: [[CBPVAL2]] = bitcast [[SSA]]** [[VAR1]] to i8* - // CK29-DAG: [[CPVAL2]] = bitcast double*** [[VAR2:%.+]] to i8* + // CK29-DAG: [[CBP2:%.+]] = bitcast i8** [[BP2]] to [[SSA]]*** + // CK29-DAG: [[CP2:%.+]] = bitcast i8** [[P2]] to double**** + // CK29-DAG: store [[SSA]]** [[VAR1]], [[SSA]]*** [[CBP2]] + // CK29-DAG: store double*** [[VAR2:%.+]], double**** [[CP2]] // CK29-DAG: [[VAR2]] = getelementptr inbounds [[SSA]], [[SSA]]* %{{.+}}, i32 0, i32 1 // CK29-DAG: [[BP3:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 3 // CK29-DAG: [[P3:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 3 - // CK29-DAG: store i8* [[CBPVAL3:%[^,]+]], i8** [[BP3]] - // CK29-DAG: store i8* [[CPVAL3:%[^,]+]], i8** [[P3]] - // CK29-DAG: [[CBPVAL3]] = bitcast double*** [[VAR2]] to i8* - // CK29-DAG: [[CPVAL3]] = bitcast double** [[VAR3:%.+]] to i8* + // CK29-DAG: [[CBP3:%.+]] = bitcast i8** [[BP3]] to double**** + // CK29-DAG: [[CP3:%.+]] = bitcast i8** [[P3]] to double*** + // CK29-DAG: store double*** [[VAR2]], double**** [[CBP3]] + // CK29-DAG: store double** [[VAR3:%.+]], double*** [[CP3]] // CK29-DAG: [[VAR3]] = load double**, double*** [[VAR2]], // CK29-DAG: [[BP4:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 4 // CK29-DAG: [[P4:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 4 - // CK29-DAG: store i8* [[CBPVAL4:%[^,]+]], i8** [[BP4]] - // CK29-DAG: store i8* [[CPVAL4:%[^,]+]], i8** [[P4]] - // CK29-DAG: [[CBPVAL4]] = bitcast double** [[VAR3]] to i8* - // CK29-DAG: [[CPVAL4]] = bitcast double* [[VAR4:%.+]] to i8* + // CK29-DAG: [[CBP4:%.+]] = bitcast i8** [[BP4]] to double*** + // CK29-DAG: [[CP4:%.+]] = bitcast i8** [[P4]] to double** + // CK29-DAG: store double** [[VAR3]], double*** [[CBP4]] + // CK29-DAG: store double* [[VAR4:%.+]], double** [[CP4]] // CK29-DAG: [[VAR4]] = getelementptr inbounds double, double* [[VAR44:%.+]], i{{.+}} 0 // CK29-DAG: [[VAR44]] = load double*, double** diff --git a/test/OpenMP/target_parallel_codegen.cpp b/test/OpenMP/target_parallel_codegen.cpp index 0801f631ee17..3063ab16abc8 100644 --- a/test/OpenMP/target_parallel_codegen.cpp +++ b/test/OpenMP/target_parallel_codegen.cpp @@ -121,10 +121,10 @@ int foo(int n) { // CHECK-DAG: [[P]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR:%[^,]+]], i32 0, i32 0 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]] // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR]], i32 0, i32 [[IDX0]] - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0]], + // CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]], // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK: [[RET2:%.+]] = load i32, i32* [[RHV]], align 4 @@ -148,17 +148,17 @@ int foo(int n) { // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0 - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0]], + // CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]], // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1 - // CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] - // CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] - // CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P1]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1]], + // CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]], // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -232,56 +232,58 @@ int foo(int n) { // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. - // CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR0:%.+]], + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR0:%.+]], + // CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: [[P1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: store i8* [[BP1]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P1]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CBPADDR1:%.+]], + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CPADDR1:%.+]], + // CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CBPADDR2:%.+]], + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CPADDR2:%.+]], + // CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: [[P3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CBPADDR3:%.+]], + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CPADDR3:%.+]], + // CHECK-DAG: [[CBPADDR3]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR3]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: [[P4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CBPADDR4:%.+]], + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CPADDR4:%.+]], + // CHECK-DAG: [[CBPADDR4]] = bitcast i8** {{%[^,]+}} to [10 x float]** + // CHECK-DAG: [[CPADDR4]] = bitcast i8** {{%[^,]+}} to [10 x float]** // CHECK-DAG: store i[[SZ]] 40, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: [[P5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP5]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P5]], i8** {{%[^,]+}} + // CHECK-DAG: store float* %{{.+}}, float** [[CBPADDR5:%.+]], + // CHECK-DAG: store float* %{{.+}}, float** [[CPADDR5:%.+]], + // CHECK-DAG: [[CBPADDR5]] = bitcast i8** {{%[^,]+}} to float** + // CHECK-DAG: [[CPADDR5]] = bitcast i8** {{%[^,]+}} to float** // CHECK-DAG: store i[[SZ]] [[BNSIZE]], i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: [[P6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP6]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P6]], i8** {{%[^,]+}} + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CBPADDR6:%.+]], + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CPADDR6:%.+]], + // CHECK-DAG: [[CBPADDR6]] = bitcast i8** {{%[^,]+}} to [5 x [10 x double]]** + // CHECK-DAG: [[CPADDR6]] = bitcast i8** {{%[^,]+}} to [5 x [10 x double]]** // CHECK-DAG: store i[[SZ]] 400, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: [[P7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP7]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P7]], i8** {{%[^,]+}} + // CHECK-DAG: store double* %{{.+}}, double** [[CBPADDR7:%.+]], + // CHECK-DAG: store double* %{{.+}}, double** [[CPADDR7:%.+]], + // CHECK-DAG: [[CBPADDR7]] = bitcast i8** {{%[^,]+}} to double** + // CHECK-DAG: [[CPADDR7]] = bitcast i8** {{%[^,]+}} to double** // CHECK-DAG: store i[[SZ]] [[CNSIZE]], i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: [[P8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP8]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P8]], i8** {{%[^,]+}} + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CBPADDR8:%.+]], + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CPADDR8:%.+]], + // CHECK-DAG: [[CBPADDR8]] = bitcast i8** {{%[^,]+}} to [[TT]]** + // CHECK-DAG: [[CPADDR8]] = bitcast i8** {{%[^,]+}} to [[TT]]** // CHECK-DAG: store i[[SZ]] {{12|16}}, i[[SZ]]* {{%[^,]+}} // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 @@ -550,32 +552,34 @@ int bar(int n){ // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. -// CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR0:%.+]], +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR0:%.+]], +// CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CBPADDR1:%.+]], +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CPADDR1:%.+]], +// CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: [[P2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: store i8* [[BP2]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P2]], i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CBPADDR2:%.+]], +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CPADDR2:%.+]], +// CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: [[P3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CBPADDR3:%.+]], +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CPADDR3:%.+]], +// CHECK-DAG: [[CBPADDR3]] = bitcast i8** {{%[^,]+}} to [[S1]]** +// CHECK-DAG: [[CPADDR3]] = bitcast i8** {{%[^,]+}} to [[S1]]** // CHECK-DAG: store i[[SZ]] 8, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: [[P4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} +// CHECK-DAG: store i16* %{{.+}}, i16** [[CBPADDR4:%.+]], +// CHECK-DAG: store i16* %{{.+}}, i16** [[CPADDR4:%.+]], +// CHECK-DAG: [[CBPADDR4]] = bitcast i8** {{%[^,]+}} to i16** +// CHECK-DAG: [[CPADDR4]] = bitcast i8** {{%[^,]+}} to i16** // CHECK-DAG: store i[[SZ]] [[CSIZE]], i[[SZ]]* {{%[^,]+}} // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 @@ -600,29 +604,31 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0]], +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]], // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1]], +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]], // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] +// CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL2:%.+]], i[[SZ]]* [[CBPADDR2]], +// CHECK-DAG: store i[[SZ]] [[VAL2]], i[[SZ]]* [[CPADDR2]], // CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 3 // CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 3 -// CHECK-DAG: store i8* [[BP3:%[^,]+]], i8** [[BPADDR3]] -// CHECK-DAG: store i8* [[P3:%[^,]+]], i8** [[PADDR3]] -// CHECK-DAG: [[BP3]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P3]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: [[CBPADDR3:%.+]] = bitcast i8** [[BPADDR3]] to [10 x i32]** +// CHECK-DAG: [[CPADDR3:%.+]] = bitcast i8** [[PADDR3]] to [10 x i32]** +// CHECK-DAG: store [10 x i32]* [[VAL3:%.+]], [10 x i32]** [[CBPADDR3]], +// CHECK-DAG: store [10 x i32]* [[VAL3]], [10 x i32]** [[CPADDR3]], // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -652,24 +658,24 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0]], +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]], // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* +// CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* +// CHECK-DAG: store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1]], +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]], // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] -// CHECK-DAG: [[BP2]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P2]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to [10 x i32]** +// CHECK-DAG: [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to [10 x i32]** +// CHECK-DAG: store [10 x i32]* [[VAL2:%.+]], [10 x i32]** [[CBPADDR2]], +// CHECK-DAG: store [10 x i32]* [[VAL2]], [10 x i32]** [[CPADDR2]], // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] diff --git a/test/OpenMP/target_teams_codegen.cpp b/test/OpenMP/target_teams_codegen.cpp index 4b08a6015afe..208cda6bb350 100644 --- a/test/OpenMP/target_teams_codegen.cpp +++ b/test/OpenMP/target_teams_codegen.cpp @@ -121,10 +121,10 @@ int foo(int n) { // CHECK-DAG: [[P]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR:%[^,]+]], i32 0, i32 0 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]] // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[PR]], i32 0, i32 [[IDX0]] - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]] + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK: [[RET2:%.+]] = load i32, i32* [[RHV]], align 4 @@ -148,17 +148,17 @@ int foo(int n) { // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0 - // CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] - // CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] - // CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P0]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]] + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]] // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1 - // CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] - // CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] - // CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] %{{.+}} to i8* - // CHECK-DAG: [[P1]] = inttoptr i[[SZ]] %{{.+}} to i8* + // CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]* + // CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]* + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR1]] + // CHECK-DAG: store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR1]] // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -232,56 +232,58 @@ int foo(int n) { // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. - // CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* - // CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR0:%.+]], + // CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR0:%.+]], + // CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: [[P1:%[^,]+]] = inttoptr i[[SZ]] [[VLA1]] to i8* - // CHECK-DAG: store i8* [[BP1]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P1]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CBPADDR1:%.+]], + // CHECK-DAG: store i[[SZ]] [[VLA1]], i[[SZ]]* [[CPADDR1:%.+]], + // CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} - // CHECK-DAG: store i8* inttoptr (i[[SZ]] 5 to i8*), i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CBPADDR2:%.+]], + // CHECK-DAG: store i[[SZ]] 5, i[[SZ]]* [[CPADDR2:%.+]], + // CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: [[P3:%[^,]+]] = inttoptr i[[SZ]] [[A_CVAL]] to i8* - // CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CBPADDR3:%.+]], + // CHECK-DAG: store i[[SZ]] [[A_CVAL]], i[[SZ]]* [[CPADDR3:%.+]], + // CHECK-DAG: [[CBPADDR3]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* + // CHECK-DAG: [[CPADDR3]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: [[P4:%[^,]+]] = bitcast [10 x float]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CBPADDR4:%.+]], + // CHECK-DAG: store [10 x float]* %{{.+}}, [10 x float]** [[CPADDR4:%.+]], + // CHECK-DAG: [[CBPADDR4]] = bitcast i8** {{%[^,]+}} to [10 x float]** + // CHECK-DAG: [[CPADDR4]] = bitcast i8** {{%[^,]+}} to [10 x float]** // CHECK-DAG: store i[[SZ]] 40, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: [[P5:%[^,]+]] = bitcast float* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP5]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P5]], i8** {{%[^,]+}} + // CHECK-DAG: store float* %{{.+}}, float** [[CBPADDR5:%.+]], + // CHECK-DAG: store float* %{{.+}}, float** [[CPADDR5:%.+]], + // CHECK-DAG: [[CBPADDR5]] = bitcast i8** {{%[^,]+}} to float** + // CHECK-DAG: [[CPADDR5]] = bitcast i8** {{%[^,]+}} to float** // CHECK-DAG: store i[[SZ]] [[BNSIZE]], i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: [[P6:%[^,]+]] = bitcast [5 x [10 x double]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP6]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P6]], i8** {{%[^,]+}} + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CBPADDR6:%.+]], + // CHECK-DAG: store [5 x [10 x double]]* %{{.+}}, [5 x [10 x double]]** [[CPADDR6:%.+]], + // CHECK-DAG: [[CBPADDR6]] = bitcast i8** {{%[^,]+}} to [5 x [10 x double]]** + // CHECK-DAG: [[CPADDR6]] = bitcast i8** {{%[^,]+}} to [5 x [10 x double]]** // CHECK-DAG: store i[[SZ]] 400, i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: [[P7:%[^,]+]] = bitcast double* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP7]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P7]], i8** {{%[^,]+}} + // CHECK-DAG: store double* %{{.+}}, double** [[CBPADDR7:%.+]], + // CHECK-DAG: store double* %{{.+}}, double** [[CPADDR7:%.+]], + // CHECK-DAG: [[CBPADDR7]] = bitcast i8** {{%[^,]+}} to double** + // CHECK-DAG: [[CPADDR7]] = bitcast i8** {{%[^,]+}} to double** // CHECK-DAG: store i[[SZ]] [[CNSIZE]], i[[SZ]]* {{%[^,]+}} - // CHECK-DAG: [[BP8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: [[P8:%[^,]+]] = bitcast [[TT]]* %{{.+}} to i8* - // CHECK-DAG: store i8* [[BP8]], i8** {{%[^,]+}} - // CHECK-DAG: store i8* [[P8]], i8** {{%[^,]+}} + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CBPADDR8:%.+]], + // CHECK-DAG: store [[TT]]* %{{.+}}, [[TT]]** [[CPADDR8:%.+]], + // CHECK-DAG: [[CBPADDR8]] = bitcast i8** {{%[^,]+}} to [[TT]]** + // CHECK-DAG: [[CPADDR8]] = bitcast i8** {{%[^,]+}} to [[TT]]** // CHECK-DAG: store i[[SZ]] {{12|16}}, i[[SZ]]* {{%[^,]+}} // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 @@ -550,32 +552,34 @@ int bar(int n){ // The names below are not necessarily consistent with the names used for the // addresses above as some are repeated. -// CHECK-DAG: [[BP0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: [[P0:%[^,]+]] = inttoptr i[[SZ]] [[VLA0]] to i8* -// CHECK-DAG: store i8* [[BP0]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P0]], i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CBPADDR0:%.+]], +// CHECK-DAG: store i[[SZ]] [[VLA0]], i[[SZ]]* [[CPADDR0:%.+]], +// CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} -// CHECK-DAG: store i8* inttoptr (i[[SZ]] 2 to i8*), i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CBPADDR1:%.+]], +// CHECK-DAG: store i[[SZ]] 2, i[[SZ]]* [[CPADDR1:%.+]], +// CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] {{4|8}}, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: [[P2:%[^,]+]] = inttoptr i[[SZ]] [[B_CVAL]] to i8* -// CHECK-DAG: store i8* [[BP2]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P2]], i8** {{%[^,]+}} +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CBPADDR2:%.+]], +// CHECK-DAG: store i[[SZ]] [[B_CVAL]], i[[SZ]]* [[CPADDR2:%.+]], +// CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: store i[[SZ]] 4, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: [[P3:%[^,]+]] = bitcast [[S1]]* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP3]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P3]], i8** {{%[^,]+}} +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CBPADDR3:%.+]], +// CHECK-DAG: store [[S1]]* %{{.+}}, [[S1]]** [[CPADDR3:%.+]], +// CHECK-DAG: [[CBPADDR3]] = bitcast i8** {{%[^,]+}} to [[S1]]** +// CHECK-DAG: [[CPADDR3]] = bitcast i8** {{%[^,]+}} to [[S1]]** // CHECK-DAG: store i[[SZ]] 8, i[[SZ]]* {{%[^,]+}} -// CHECK-DAG: [[BP4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: [[P4:%[^,]+]] = bitcast i16* %{{.+}} to i8* -// CHECK-DAG: store i8* [[BP4]], i8** {{%[^,]+}} -// CHECK-DAG: store i8* [[P4]], i8** {{%[^,]+}} +// CHECK-DAG: store i16* %{{.+}}, i16** [[CBPADDR4:%.+]], +// CHECK-DAG: store i16* %{{.+}}, i16** [[CPADDR4:%.+]], +// CHECK-DAG: [[CBPADDR4]] = bitcast i8** {{%[^,]+}} to i16** +// CHECK-DAG: [[CPADDR4]] = bitcast i8** {{%[^,]+}} to i16** // CHECK-DAG: store i[[SZ]] [[CSIZE]], i[[SZ]]* {{%[^,]+}} // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 @@ -600,29 +604,31 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0:%.+]], +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0:%.+]], +// CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1:%.+]], +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1:%.+]], +// CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] +// CHECK-DAG: store i[[SZ]] [[VAL2:%.+]], i[[SZ]]* [[CBPADDR2:%.+]], +// CHECK-DAG: store i[[SZ]] [[VAL2]], i[[SZ]]* [[CPADDR2:%.+]], +// CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: [[BPADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[BP]], i32 0, i32 3 // CHECK-DAG: [[PADDR3:%.+]] = getelementptr inbounds [4 x i8*], [4 x i8*]* [[P]], i32 0, i32 3 -// CHECK-DAG: store i8* [[BP3:%[^,]+]], i8** [[BPADDR3]] -// CHECK-DAG: store i8* [[P3:%[^,]+]], i8** [[PADDR3]] -// CHECK-DAG: [[BP3]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P3]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: store [10 x i32]* %{{.+}}, [10 x i32]** [[CBPADDR3:%.+]], +// CHECK-DAG: store [10 x i32]* %{{.+}}, [10 x i32]** [[CPADDR3:%.+]], +// CHECK-DAG: [[CBPADDR3]] = bitcast i8** {{%[^,]+}} to [10 x i32]** +// CHECK-DAG: [[CPADDR3]] = bitcast i8** {{%[^,]+}} to [10 x i32]** // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] @@ -652,24 +658,24 @@ int bar(int n){ // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 0 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 0 -// CHECK-DAG: store i8* [[BP0:%[^,]+]], i8** [[BPADDR0]] -// CHECK-DAG: store i8* [[P0:%[^,]+]], i8** [[PADDR0]] -// CHECK-DAG: [[BP0]] = inttoptr i[[SZ]] [[VAL0:%.+]] to i8* -// CHECK-DAG: [[P0]] = inttoptr i[[SZ]] [[VAL0]] to i8* +// CHECK-DAG: store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0:%.+]], +// CHECK-DAG: store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0:%.+]], +// CHECK-DAG: [[CBPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR0]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 1 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 1 -// CHECK-DAG: store i8* [[BP1:%[^,]+]], i8** [[BPADDR1]] -// CHECK-DAG: store i8* [[P1:%[^,]+]], i8** [[PADDR1]] -// CHECK-DAG: [[BP1]] = inttoptr i[[SZ]] [[VAL1:%.+]] to i8* -// CHECK-DAG: [[P1]] = inttoptr i[[SZ]] [[VAL1]] to i8* +// CHECK-DAG: store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1:%.+]], +// CHECK-DAG: store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1:%.+]], +// CHECK-DAG: [[CBPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* +// CHECK-DAG: [[CPADDR1]] = bitcast i8** {{%[^,]+}} to i[[SZ]]* // CHECK-DAG: [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 2 // CHECK-DAG: [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 2 -// CHECK-DAG: store i8* [[BP2:%[^,]+]], i8** [[BPADDR2]] -// CHECK-DAG: store i8* [[P2:%[^,]+]], i8** [[PADDR2]] -// CHECK-DAG: [[BP2]] = bitcast [10 x i32]* %{{.+}} to i8* -// CHECK-DAG: [[P2]] = bitcast [10 x i32]* %{{.+}} to i8* +// CHECK-DAG: store [10 x i32]* [[VAL2:%.+]], [10 x i32]** [[CBPADDR2:%.+]], +// CHECK-DAG: store [10 x i32]* [[VAL2]], [10 x i32]** [[CPADDR2:%.+]], +// CHECK-DAG: [[CBPADDR2]] = bitcast i8** {{%[^,]+}} to [10 x i32]** +// CHECK-DAG: [[CPADDR2]] = bitcast i8** {{%[^,]+}} to [10 x i32]** // CHECK: store i32 [[RET]], i32* [[RHV:%.+]], align 4 // CHECK-NEXT: br label %[[IFEND:.+]] diff --git a/test/OpenMP/target_update_codegen.cpp b/test/OpenMP/target_update_codegen.cpp index f74ed4997537..f1e61a54c6e2 100644 --- a/test/OpenMP/target_update_codegen.cpp +++ b/test/OpenMP/target_update_codegen.cpp @@ -45,8 +45,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast ([100 x double]* @gc to i8*), i8** [[P0]] + // CK1-DAG: [[BPC0:%.+]] = bitcast i8** [[BP0]] to [100 x double]** + // CK1-DAG: [[PC0:%.+]] = bitcast i8** [[P0]] to [100 x double]** + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[BPC0]] + // CK1-DAG: store [100 x double]* @gc, [100 x double]** [[PC0]] // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 #pragma omp target update if(1+3-5) device(arg) from(gc) @@ -66,10 +68,10 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] - // CK1-DAG: [[CBPVAL0]] = bitcast i32* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast i32* [[VAR0]] to i8* + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK1-DAG: store i32* [[VAL0:%[^,]+]], i32** [[CBP0]] + // CK1-DAG: store i32* [[VAL0]], i32** [[CP0]] // CK1: br label %[[IFEND:[^,]+]] // CK1: [[IFELSE]] @@ -91,11 +93,11 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[S0:%.+]] = getelementptr inbounds {{.+}}[[S]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] - // CK1-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to float** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to float** + // CK1-DAG: store float* [[VAL0:%[^,]+]], float** [[CBP0]] + // CK1-DAG: store float* [[VAL0]], float** [[CP0]] // CK1-DAG: store i[[sz]] [[CSVAL0:%[^,]+]], i[[sz]]* [[S0]] - // CK1-DAG: [[CBPVAL0]] = bitcast float* [[VAR0:%.+]] to i8* - // CK1-DAG: [[CPVAL0]] = bitcast float* [[VAR0]] to i8* // CK1-DAG: [[CSVAL0]] = mul nuw i[[sz]] %{{[^,]+}}, 4 // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 // CK1-NOT: __tgt_target_data_end @@ -112,16 +114,19 @@ void foo(int arg) { // CK1-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK1-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 - // CK1-DAG: store i8* bitcast ([[ST]]* @gb to i8*), i8** [[BP0]] - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[P0]] + // CK1-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** + // CK1-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** + // CK1-DAG: store [[ST]]* @gb, [[ST]]** [[CBP0]] + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CP0]] // CK1-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK1-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 - // CK1-DAG: store i8* bitcast (double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1) to i8*), i8** [[BP1]] - // CK1-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] - // CK1-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%.+]] to i8* - // CK1-DAG: [[SEC1]] = getelementptr inbounds {{.+}}double* [[SEC11:%[^,]+]], i{{.+}} 0 + // CK1-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** + // CK1-DAG: store double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), double*** [[CBP1]] + // CK1-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** + // CK1-DAG: store double* [[VAL1:%[^,]+]], double** [[CP1]] + // CK1-DAG: [[VAL1]] = getelementptr inbounds {{.+}}double* [[SEC11:%.+]], i{{.+}} 0 // CK1-DAG: [[SEC11]] = load double*, double** getelementptr inbounds ([[ST]], [[ST]]* @gb, i32 0, i32 1), // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1 @@ -172,19 +177,19 @@ int bar(int arg){ // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 -// CK2-DAG: store i8* [[CBPVAL0:%[^,]+]], i8** [[BP0]] -// CK2-DAG: store i8* [[CPVAL0:%[^,]+]], i8** [[P0]] -// CK2-DAG: [[CBPVAL0]] = bitcast [[ST]]* [[VAR0:%.+]] to i8* -// CK2-DAG: [[CPVAL0]] = bitcast double** [[SEC0:%[^,]+]] to i8* +// CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]** +// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double*** +// CK2-DAG: store [[ST]]* [[VAR0:%[^,]+]], [[ST]]** [[CBP0]] +// CK2-DAG: store double** [[SEC0:%[^,]+]], double*** [[CP0]] // CK2-DAG: [[SEC0]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 // CK2-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 1 // CK2-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 1 -// CK2-DAG: store i8* [[CBPVAL1:%[^,]+]], i8** [[BP1]] -// CK2-DAG: store i8* [[CPVAL1:%[^,]+]], i8** [[P1]] -// CK2-DAG: [[CBPVAL1]] = bitcast double** [[SEC0]] to i8* -// CK2-DAG: [[CPVAL1]] = bitcast double* [[SEC1:%[^,]+]] to i8* +// CK2-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to double*** +// CK2-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to double** +// CK2-DAG: store double** [[CBPVAL1:%[^,]+]], double*** [[CBP1]] +// CK2-DAG: store double* [[SEC1:%[^,]+]], double** [[CP1]] // CK2-DAG: [[SEC1]] = getelementptr inbounds {{.*}}double* [[SEC11:%[^,]+]], i{{.+}} 1 // CK2-DAG: [[SEC11]] = load double*, double** [[SEC111:%[^,]+]], // CK2-DAG: [[SEC111]] = getelementptr inbounds {{.*}}[[ST]]* [[VAR0]], i32 0, i32 1 From da1f3cf54166a2718e6ab7a28ddf2a10babe3345 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 29 Jun 2017 17:58:59 +0000 Subject: [PATCH 121/214] Fixed -Wexceptions derived-to-base false positives ...as introduced with recent "Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier". (The equivalent of the goodReference case hit when building LibreOffice.) (These warnings are apparently only emitted when no errors have yet been encountered, so it didn't work to add the test code to the end of the existing clang/test/SemaCXX/exceptions.cpp.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306715 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/AnalysisBasedWarnings.cpp | 6 ++++- test/SemaCXX/exception-warnings.cpp | 36 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/exception-warnings.cpp diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 934e13e72d05..fd2d07957c2b 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -305,10 +305,14 @@ static bool isThrowCaught(const CXXThrowExpr *Throw, CaughtType = CaughtType->castAs() ->getPointeeType() ->getUnqualifiedDesugaredType(); + if (ThrowType->isPointerType() && CaughtType->isPointerType()) { + ThrowType = ThrowType->getPointeeType()->getUnqualifiedDesugaredType(); + CaughtType = CaughtType->getPointeeType()->getUnqualifiedDesugaredType(); + } if (CaughtType == ThrowType) return true; const CXXRecordDecl *CaughtAsRecordType = - CaughtType->getPointeeCXXRecordDecl(); + CaughtType->getAsCXXRecordDecl(); const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl(); if (CaughtAsRecordType && ThrowTypeAsRecordType) return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType); diff --git a/test/SemaCXX/exception-warnings.cpp b/test/SemaCXX/exception-warnings.cpp new file mode 100644 index 000000000000..f6c646e5a40e --- /dev/null +++ b/test/SemaCXX/exception-warnings.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s + +struct B {}; +struct D: B {}; +void goodPlain() throw () { + try { + throw D(); + } catch (B) {} +} +void goodReference() throw () { + try { + throw D(); + } catch (B &) {} +} +void goodPointer() throw () { + D d; + try { + throw &d; + } catch (B *) {} +} +void badPlain() throw () { // expected-note {{non-throwing function declare here}} + try { + throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D) {} +} +void badReference() throw () { // expected-note {{non-throwing function declare here}} + try { + throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D &) {} +} +void badPointer() throw () { // expected-note {{non-throwing function declare here}} + B b; + try { + throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D *) {} +} From 6703d83ed551908566145c3c607e8d70da86d710 Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Thu, 29 Jun 2017 18:47:45 +0000 Subject: [PATCH 122/214] CodeGen: Fix invalid bitcast for coerced function argument Clang assumes coerced function argument is in address space 0, which is not always true and results in invalid bitcasts. This patch fixes failure in OpenCL conformance test api/get_kernel_arg_info with amdgcn---amdgizcl triple, where non-zero alloca address space is used. Differential Revision: https://reviews.llvm.org/D34777 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306721 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 5 +- test/CodeGenOpenCL/addr-space-struct-arg.cl | 52 +++++++++++++++++++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 8795e4a89989..13a156c7bbd7 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1297,7 +1297,7 @@ static void CreateCoercedStore(llvm::Value *Src, // If store is legal, just bitcast the src pointer. if (SrcSize <= DstSize) { - Dst = CGF.Builder.CreateBitCast(Dst, llvm::PointerType::getUnqual(SrcTy)); + Dst = CGF.Builder.CreateElementBitCast(Dst, SrcTy); BuildAggStore(CGF, Src, Dst, DstIsVolatile); } else { // Otherwise do coercion through memory. This is stupid, but @@ -2412,8 +2412,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, Address AddrToStoreInto = Address::invalid(); if (SrcSize <= DstSize) { - AddrToStoreInto = - Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(STy)); + AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy); } else { AddrToStoreInto = CreateTempAlloca(STy, Alloca.getAlignment(), "coerce"); diff --git a/test/CodeGenOpenCL/addr-space-struct-arg.cl b/test/CodeGenOpenCL/addr-space-struct-arg.cl index d711f78d4ef0..6ea0aff0a074 100644 --- a/test/CodeGenOpenCL/addr-space-struct-arg.cl +++ b/test/CodeGenOpenCL/addr-space-struct-arg.cl @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple i686-pc-darwin | FileCheck %s +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -check-prefixes=COM,X86 %s +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn-amdhsa-amd-amdgizcl | FileCheck -check-prefixes=COM,AMD %s typedef struct { int cells[9]; @@ -8,16 +9,57 @@ typedef struct { int cells[16]; } Mat4X4; +struct StructOneMember { + int2 x; +}; + +struct StructTwoMember { + int2 x; + int2 y; +}; + +// COM-LABEL: define void @foo Mat4X4 __attribute__((noinline)) foo(Mat3X3 in) { Mat4X4 out; return out; } +// COM-LABEL: define {{.*}} void @ker +// Expect two mem copies: one for the argument "in", and one for +// the return value. +// X86: call void @llvm.memcpy.p0i8.p1i8.i32(i8* +// X86: call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* +// AMD: call void @llvm.memcpy.p5i8.p1i8.i64(i8 addrspace(5)* +// AMD: call void @llvm.memcpy.p1i8.p5i8.i64(i8 addrspace(1)* kernel void ker(global Mat3X3 *in, global Mat4X4 *out) { out[0] = foo(in[1]); } -// Expect two mem copies: one for the argument "in", and one for -// the return value. -// CHECK: call void @llvm.memcpy.p0i8.p1i8.i32(i8* -// CHECK: call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* +// AMD-LABEL: define void @FuncOneMember(%struct.StructOneMember addrspace(5)* byval align 8 %u) +void FuncOneMember(struct StructOneMember u) { + u.x = (int2)(0, 0); +} + +// AMD-LABEL: define amdgpu_kernel void @KernelOneMember +// AMD-SAME: (<2 x i32> %[[u_coerce:.*]]) +// AMD: %[[u:.*]] = alloca %struct.StructOneMember, align 8, addrspace(5) +// AMD: %[[coerce_dive:.*]] = getelementptr inbounds %struct.StructOneMember, %struct.StructOneMember addrspace(5)* %[[u]], i32 0, i32 0 +// AMD: store <2 x i32> %[[u_coerce]], <2 x i32> addrspace(5)* %[[coerce_dive]] +// AMD: call void @FuncOneMember(%struct.StructOneMember addrspace(5)* byval align 8 %[[u]]) +kernel void KernelOneMember(struct StructOneMember u) { + FuncOneMember(u); +} + +// AMD-LABEL: define void @FuncTwoMember(%struct.StructTwoMember addrspace(5)* byval align 8 %u) +void FuncTwoMember(struct StructTwoMember u) { + u.x = (int2)(0, 0); +} + +// AMD-LABEL: define amdgpu_kernel void @KernelTwoMember +// AMD-SAME: (%struct.StructTwoMember %[[u_coerce:.*]]) +// AMD: %[[u:.*]] = alloca %struct.StructTwoMember, align 8, addrspace(5) +// AMD: store %struct.StructTwoMember %[[u_coerce]], %struct.StructTwoMember addrspace(5)* %[[u]] +// AMD: call void @FuncTwoMember(%struct.StructTwoMember addrspace(5)* byval align 8 %[[u]]) +kernel void KernelTwoMember(struct StructTwoMember u) { + FuncTwoMember(u); +} From eaa720dff62b59b0e93fdc32b08fd1f39a5b5492 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Thu, 29 Jun 2017 18:48:40 +0000 Subject: [PATCH 123/214] [Sema] Issue diagnostics if a new/delete expression generates a call to a c++17 aligned allocation/deallocation function that is unavailable in the standard library on Apple platforms. The aligned functions are implemented only in the following versions or later versions of the OSes, so clang issues diagnostics if the deployment target being targeted is older than these: macosx: 10.13 ios: 11.0 tvos: 11.0 watchos: 4.0 The diagnostics are issued whenever the aligned functions are selected except when the selected function has a definition in the same file. If there is a user-defined function available somewhere else, option -Wno-aligned-allocation-unavailable can be used to silence the diagnostics. rdar://problem/32664169 Differential Revision: https://reviews.llvm.org/D34574 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306722 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 5 +- include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Basic/DiagnosticSemaKinds.td | 6 + include/clang/Basic/LangOptions.def | 1 + include/clang/Driver/CC1Options.td | 3 + lib/AST/Decl.cpp | 7 +- lib/Driver/ToolChains/Darwin.cpp | 21 ++++ lib/Driver/ToolChains/Darwin.h | 8 ++ lib/Frontend/CompilerInvocation.cpp | 2 + lib/Sema/SemaExprCXX.cpp | 26 +++++ .../Driver/unavailable_aligned_allocation.cpp | 54 +++++++++ .../unavailable_aligned_allocation.cpp | 109 ++++++++++++++++++ 12 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 test/Driver/unavailable_aligned_allocation.cpp create mode 100644 test/SemaCXX/unavailable_aligned_allocation.cpp diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 30552be9b381..08b34a75aa60 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2019,7 +2019,10 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, /// These functions have special behavior under C++1y [expr.new]: /// An implementation is allowed to omit a call to a replaceable global /// allocation function. [...] - bool isReplaceableGlobalAllocationFunction() const; + /// + /// If this function is an aligned allocation/deallocation function, return + /// true through IsAligned. + bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const; /// Compute the language linkage. LanguageLinkage getLanguageLinkage() const; diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 464c2425a1f1..3a0564806b32 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -311,6 +311,7 @@ def : DiagGroup<"nonportable-cfstrings">; def NonVirtualDtor : DiagGroup<"non-virtual-dtor">; def : DiagGroup<"effc++", [NonVirtualDtor]>; def OveralignedType : DiagGroup<"over-aligned">; +def AlignedAllocationUnavailable : DiagGroup<"aligned-allocation-unavailable">; def OldStyleCast : DiagGroup<"old-style-cast">; def : DiagGroup<"old-style-definition">; def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6224f13ce762..7b1671bb8777 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -6407,6 +6407,12 @@ def warn_overaligned_type : Warning< "type %0 requires %1 bytes of alignment and the default allocator only " "guarantees %2 bytes">, InGroup, DefaultIgnore; +def warn_aligned_allocation_unavailable :Warning< + "aligned %select{allocation|deallocation}0 function of type '%1' possibly " + "unavailable on %2">, InGroup, DefaultError; +def note_silence_unligned_allocation_unavailable : Note< + "if you supply your own aligned allocation functions, use " + "-Wno-aligned-allocation-unavailable to silence this diagnostic">; def err_conditional_void_nonvoid : Error< "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand " diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 60c8a68cd2e9..dfdad108922a 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -199,6 +199,7 @@ LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental LANGOPT(SizedDeallocation , 1, 0, "sized deallocation") LANGOPT(AlignedAllocation , 1, 0, "aligned allocation") +LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable") LANGOPT(NewAlignOverride , 32, 0, "maximum alignment guaranteed by '::operator new(size_t)'") LANGOPT(ConceptsTS , 1, 0, "enable C++ Extensions for Concepts") BENIGN_LANGOPT(ModulesCodegen , 1, 0, "Modules code generation") diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index c478cfc7833e..ab790c8a0a4b 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -568,6 +568,9 @@ def find_pch_source_EQ : Joined<["-"], "find-pch-source=">, def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">, HelpText<"Disable inclusion of timestamp in precompiled headers">; +def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">, + HelpText<"Aligned allocation/deallocation functions are unavailable">; + //===----------------------------------------------------------------------===// // Language Options //===----------------------------------------------------------------------===// diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9862f4f26473..8677b1155a60 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2630,7 +2630,7 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const { return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy); } -bool FunctionDecl::isReplaceableGlobalAllocationFunction() const { +bool FunctionDecl::isReplaceableGlobalAllocationFunction(bool *IsAligned) const { if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName) return false; if (getDeclName().getCXXOverloadedOperator() != OO_New && @@ -2676,8 +2676,11 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction() const { // In C++17, the next parameter can be a 'std::align_val_t' for aligned // new/delete. - if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) + if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) { + if (IsAligned) + *IsAligned = true; Consume(); + } // Finally, if this is not a sized delete, the final parameter can // be a 'const std::nothrow_t&'. diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index e41b50c40b28..bfe685e70df7 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1667,6 +1667,27 @@ void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); } +bool Darwin::isAlignedAllocationUnavailable() const { + switch (TargetPlatform) { + case MacOS: // Earlier than 10.13. + return TargetVersion < VersionTuple(10U, 13U, 0U); + case IPhoneOS: + case IPhoneOSSimulator: + case TvOS: + case TvOSSimulator: // Earlier than 11.0. + return TargetVersion < VersionTuple(11U, 0U, 0U); + case WatchOS: + case WatchOSSimulator: // Earlier than 4.0. + return TargetVersion < VersionTuple(4U, 0U, 0U); + } +} + +void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + if (isAlignedAllocationUnavailable()) + CC1Args.push_back("-faligned-alloc-unavailable"); +} + DerivedArgList * Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const { diff --git a/lib/Driver/ToolChains/Darwin.h b/lib/Driver/ToolChains/Darwin.h index 16ed04286ac0..ffcdf9a71a46 100644 --- a/lib/Driver/ToolChains/Darwin.h +++ b/lib/Driver/ToolChains/Darwin.h @@ -384,6 +384,14 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO { return TargetVersion < VersionTuple(V0, V1, V2); } + /// Return true if c++17 aligned allocation/deallocation functions are not + /// implemented in the c++ standard library of the deployment target we are + /// targeting. + bool isAlignedAllocationUnavailable() const; + + void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + StringRef getPlatformFamily() const; static StringRef getSDKName(StringRef isysroot); StringRef getOSLibraryNameSuffix() const; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c49fda975241..7996da33adce 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2106,6 +2106,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.AlignedAllocation = Args.hasFlag(OPT_faligned_allocation, OPT_fno_aligned_allocation, Opts.AlignedAllocation); + Opts.AlignedAllocationUnavailable = + Opts.AlignedAllocation && Args.hasArg(OPT_aligned_alloc_unavailable); Opts.NewAlignOverride = getLastArgIntValue(Args, OPT_fnew_alignment_EQ, 0, Diags); if (Opts.NewAlignOverride && !llvm::isPowerOf2_32(Opts.NewAlignOverride)) { diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 71c4c8070e77..a9cf3ec7990b 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1646,6 +1646,27 @@ static bool isLegalArrayNewInitializer(CXXNewExpr::InitializationStyle Style, return false; } +// Emit a diagnostic if an aligned allocation/deallocation function that is not +// implemented in the standard library is selected. +static void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, + SourceLocation Loc, bool IsDelete, + Sema &S) { + if (!S.getLangOpts().AlignedAllocationUnavailable) + return; + + // Return if there is a definition. + if (FD.isDefined()) + return; + + bool IsAligned = false; + if (FD.isReplaceableGlobalAllocationFunction(&IsAligned) && IsAligned) { + S.Diag(Loc, diag::warn_aligned_allocation_unavailable) + << IsDelete << FD.getType().getAsString() + << S.getASTContext().getTargetInfo().getTriple().str(); + S.Diag(Loc, diag::note_silence_unligned_allocation_unavailable); + } +} + ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, @@ -2023,11 +2044,13 @@ Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, if (DiagnoseUseOfDecl(OperatorNew, StartLoc)) return ExprError(); MarkFunctionReferenced(StartLoc, OperatorNew); + diagnoseUnavailableAlignedAllocation(*OperatorNew, StartLoc, false, *this); } if (OperatorDelete) { if (DiagnoseUseOfDecl(OperatorDelete, StartLoc)) return ExprError(); MarkFunctionReferenced(StartLoc, OperatorDelete); + diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true, *this); } // C++0x [expr.new]p17: @@ -3243,6 +3266,9 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, PDiag(diag::err_access_dtor) << PointeeElem); } } + + diagnoseUnavailableAlignedAllocation(*OperatorDelete, StartLoc, true, + *this); } CXXDeleteExpr *Result = new (Context) CXXDeleteExpr( diff --git a/test/Driver/unavailable_aligned_allocation.cpp b/test/Driver/unavailable_aligned_allocation.cpp new file mode 100644 index 000000000000..cd75c08165d7 --- /dev/null +++ b/test/Driver/unavailable_aligned_allocation.cpp @@ -0,0 +1,54 @@ +// RUN: %clang -target x86_64-apple-macosx10.12 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target arm64-apple-ios10 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target arm64-apple-tvos10 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target thumbv7-apple-watchos3 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.13 -mios-simulator-version-min=10 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.13 -mtvos-simulator-version-min=10 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.13 -mwatchos-simulator-version-min=3 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=UNAVAILABLE +// +// UNAVAILABLE: "-faligned-alloc-unavailable" + +// RUN: %clang -target x86_64-apple-macosx10.13 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target arm64-apple-ios11 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target arm64-apple-tvos11 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target armv7k-apple-watchos4 -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-unknown-linux-gnu -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.12 -mios-simulator-version-min=11 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.12 -mtvos-simulator-version-min=11 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// RUN: %clang -target x86_64-apple-macosx10.12 -mwatchos-simulator-version-min=4 \ +// RUN: -c -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=AVAILABLE +// +// AVAILABLE-NOT: "-faligned-alloc-unavailable" diff --git a/test/SemaCXX/unavailable_aligned_allocation.cpp b/test/SemaCXX/unavailable_aligned_allocation.cpp new file mode 100644 index 000000000000..2ae5d2e2c704 --- /dev/null +++ b/test/SemaCXX/unavailable_aligned_allocation.cpp @@ -0,0 +1,109 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s + +namespace std { + typedef decltype(sizeof(0)) size_t; + enum class align_val_t : std::size_t {}; + struct nothrow_t {}; + nothrow_t nothrow; +} + +void *operator new(std::size_t __sz, const std::nothrow_t&) noexcept; +void *operator new[](std::size_t __sz, const std::nothrow_t&) noexcept; + +void *operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept; +void *operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept; +void operator delete(void *, std::align_val_t, const std::nothrow_t&); +void operator delete[](void *, std::align_val_t, const std::nothrow_t&); +void operator delete(void*, std::size_t, std::align_val_t) noexcept; +void operator delete[](void*, std::size_t, std::align_val_t) noexcept; + +void *operator new(std::size_t, std::align_val_t, long long); + +struct alignas(256) OveralignedS { + int x[16]; +}; + +struct S { + int x[16]; +}; + +void test() { + auto *p = new S; + delete p; + p = new (std::nothrow) S; + + auto *pa = new S[4]; + delete[] pa; + pa = new (std::nothrow) S[4]; +} + +void testOveraligned() { + auto *p = new OveralignedS; + p = new ((std::align_val_t)8) OveralignedS; + delete p; + p = new (std::nothrow) OveralignedS; + + auto *pa = new OveralignedS[4]; + pa = new ((std::align_val_t)8) OveralignedS[4]; + delete[] pa; + pa = new (std::nothrow) OveralignedS[4]; + // No error here since it is not calling a replaceable allocation function. + p = new ((std::align_val_t)8, 10LL) OveralignedS; +} + +#ifdef NO_ERRORS +// expected-no-diagnostics +#else +// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} +// expected-note@-17 {{if you supply your own aligned allocation functions}} +// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-19 {{if you supply your own aligned allocation functions}} + +// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} +// expected-note@-21 {{if you supply your own aligned allocation functions}} +// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-23 {{if you supply your own aligned allocation functions}} + +// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-25 {{if you supply your own aligned allocation functions}} + +// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} +// expected-note@-27 {{if you supply your own aligned allocation functions}} +// expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} +// expected-note@-29 {{if you supply your own aligned allocation functions}} + +// expected-error@-29 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} +// expected-note@-30 {{if you supply your own aligned allocation functions}} +// expected-error@-31 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-32 {{if you supply your own aligned allocation functions}} + +// expected-error@-33 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} +// expected-note@-34 {{if you supply your own aligned allocation functions}} +// expected-error@-35 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-36 {{if you supply your own aligned allocation functions}} + +// expected-error@-37 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} +// expected-note@-38 {{if you supply your own aligned allocation functions}} + +// expected-error@-39 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} +// expected-note@-40 {{if you supply your own aligned allocation functions}} +// expected-error@-41 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} +// expected-note@-42 {{if you supply your own aligned allocation functions}} + +#endif + +// No errors if user-defined aligned allocation functions are available. +void *operator new(std::size_t __sz, std::align_val_t) { + static char array[256]; + return &array; +} + +void operator delete(void *p, std::align_val_t) { +} + +void testOveraligned2() { + auto p = new ((std::align_val_t)8) OveralignedS; + delete p; +} From 3636b96e18fc7810790b329c0629b0f9f4d2338b Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Thu, 29 Jun 2017 18:49:16 +0000 Subject: [PATCH 124/214] [OpenMP] Fix test for revision D29645. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306724 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Driver/openmp-offload.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index 567f3fdf2239..7a0d62073b6b 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -592,10 +592,8 @@ /// ########################################################################### -/// Check -fopenmp-is-device is also passed when generating the *.i and *.s intermediate files. -// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -save-temps -no-canonical-prefixes %s 2>&1 \ +/// Check -fopenmp-is-device is passed when compiling for the device. +// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s -// CHK-FOPENMP-IS-DEVICE: clang{{.*}}.i" {{.*}}" "-fopenmp-is-device" -// CHK-FOPENMP-IS-DEVICE-NEXT: clang{{.*}}.bc" {{.*}}.i" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" -// CHK-FOPENMP-IS-DEVICE-NEXT: clang{{.*}}.s" {{.*}}.bc" "-fopenmp-is-device" +// CHK-FOPENMP-IS-DEVICE: clang{{.*}} "-aux-triple" "powerpc64le-unknown-linux-gnu" {{.*}}.c" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" From f832c35ecbbbe989774fd6b1e4fd84a8199b5dcd Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 29 Jun 2017 19:42:35 +0000 Subject: [PATCH 125/214] [ASTReader] Add test for previous change r306583 / 145692e. Summary: Add a test for the change to ASTReader that reproduces the logic for consolidating multiple ObjC interface definitions to the case of multiple ObjC protocol definitions. This test is a modified copy of the test that accompanied the original change to interfaces, in 2ba1979. Reviewers: bruno Reviewed By: bruno Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34788 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306732 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Inputs/lookup-assert-protocol/Base.h | 3 +++ .../Inputs/lookup-assert-protocol/Derive.h | 4 ++++ test/Modules/Inputs/lookup-assert-protocol/H3.h | 1 + .../Inputs/lookup-assert-protocol/module.map | 4 ++++ test/Modules/lookup-assert-protocol.m | 17 +++++++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 test/Modules/Inputs/lookup-assert-protocol/Base.h create mode 100644 test/Modules/Inputs/lookup-assert-protocol/Derive.h create mode 100644 test/Modules/Inputs/lookup-assert-protocol/H3.h create mode 100644 test/Modules/Inputs/lookup-assert-protocol/module.map create mode 100644 test/Modules/lookup-assert-protocol.m diff --git a/test/Modules/Inputs/lookup-assert-protocol/Base.h b/test/Modules/Inputs/lookup-assert-protocol/Base.h new file mode 100644 index 000000000000..5c9506fa5cd3 --- /dev/null +++ b/test/Modules/Inputs/lookup-assert-protocol/Base.h @@ -0,0 +1,3 @@ +@protocol BaseProtocol +- (void) test; +@end diff --git a/test/Modules/Inputs/lookup-assert-protocol/Derive.h b/test/Modules/Inputs/lookup-assert-protocol/Derive.h new file mode 100644 index 000000000000..fdcde6158a7c --- /dev/null +++ b/test/Modules/Inputs/lookup-assert-protocol/Derive.h @@ -0,0 +1,4 @@ +#include "Base.h" +@protocol DerivedProtocol +- (void) test2; +@end diff --git a/test/Modules/Inputs/lookup-assert-protocol/H3.h b/test/Modules/Inputs/lookup-assert-protocol/H3.h new file mode 100644 index 000000000000..3d8f878905df --- /dev/null +++ b/test/Modules/Inputs/lookup-assert-protocol/H3.h @@ -0,0 +1 @@ +#include "Base.h" diff --git a/test/Modules/Inputs/lookup-assert-protocol/module.map b/test/Modules/Inputs/lookup-assert-protocol/module.map new file mode 100644 index 000000000000..e8a89eb095a4 --- /dev/null +++ b/test/Modules/Inputs/lookup-assert-protocol/module.map @@ -0,0 +1,4 @@ +module X { + header "H3.h" + export * +} diff --git a/test/Modules/lookup-assert-protocol.m b/test/Modules/lookup-assert-protocol.m new file mode 100644 index 000000000000..3c093f1bf156 --- /dev/null +++ b/test/Modules/lookup-assert-protocol.m @@ -0,0 +1,17 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/lookup-assert-protocol %s -verify +// expected-no-diagnostics + +#include "Derive.h" +#import + +__attribute__((objc_root_class)) +@interface Thing +@end + +@implementation Thing +- (void)test { +} +- (void)test2 { +} +@end From f4236bfdbdb6f8236a2efdc5cda5d7fa40786b9f Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Thu, 29 Jun 2017 19:52:33 +0000 Subject: [PATCH 126/214] [libFuzzer] Do not link in libFuzzer with -fsanitize=fuzzer when producing a shared object https://reviews.llvm.org/D34791 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306733 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/CommonArgs.cpp | 3 ++- lib/Driver/ToolChains/Darwin.cpp | 2 +- test/Driver/fuzzer.c | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index 1991b2ecd8fa..e8bb703054de 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -617,7 +617,8 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols); // Inject libfuzzer dependencies. - if (TC.getSanitizerArgs().needsFuzzer()) { + if (TC.getSanitizerArgs().needsFuzzer() + && !Args.hasArg(options::OPT_shared)) { addLibFuzzerRuntime(TC, Args, CmdArgs); } diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index bfe685e70df7..13cda0d0a1fe 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1053,7 +1053,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); if (Sanitize.needsTsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); - if (Sanitize.needsFuzzer()) + if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) AddFuzzerLinkArgs(Args, CmdArgs); if (Sanitize.needsStatsRt()) { StringRef OS = isTargetMacOS() ? "osx" : "iossim"; diff --git a/test/Driver/fuzzer.c b/test/Driver/fuzzer.c index e534a73a647f..35bf4315c9f4 100644 --- a/test/Driver/fuzzer.c +++ b/test/Driver/fuzzer.c @@ -15,6 +15,10 @@ // // CHECK-LIBCXX-DARWIN: -lc++ +// Check that we don't link in libFuzzer.a when producing a shared object. +// RUN: %clang -fsanitize=fuzzer %s -shared -o %t.so -### 2>&1 | FileCheck --check-prefixes=CHECK-NOLIB-SO %s +// CHECK-NOLIB-SO-NOT: libLLVMFuzzer.a + int LLVMFuzzerTestOneInput(const char *Data, long Size) { return 0; } From 78aa30a644eaec1893db971c86ee10b3c0fe6781 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Thu, 29 Jun 2017 19:58:20 +0000 Subject: [PATCH 127/214] [libFuzzer] Add Fuzzer to the list of sanitizers which support coverage. Without this change, additional coverage flags specified after -fsanitize=fuzzer would get discarded. https://reviews.llvm.org/D34794 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306734 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/SanitizerArgs.cpp | 2 +- test/Driver/fuzzer.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index 3a30f2a289b0..7a442c83e158 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -32,7 +32,7 @@ enum : SanitizerMask { RequiresPIE = DataFlow, NeedsUnwindTables = Address | Thread | Memory | DataFlow, SupportsCoverage = Address | KernelAddress | Memory | Leak | Undefined | - Integer | Nullability | DataFlow, + Integer | Nullability | DataFlow | Fuzzer, RecoverableByDefault = Undefined | Integer | Nullability, Unrecoverable = Unreachable | Return, LegacyFsanitizeRecoverMask = Undefined | Integer, diff --git a/test/Driver/fuzzer.c b/test/Driver/fuzzer.c index 35bf4315c9f4..989b3b9f6348 100644 --- a/test/Driver/fuzzer.c +++ b/test/Driver/fuzzer.c @@ -15,10 +15,14 @@ // // CHECK-LIBCXX-DARWIN: -lc++ + // Check that we don't link in libFuzzer.a when producing a shared object. // RUN: %clang -fsanitize=fuzzer %s -shared -o %t.so -### 2>&1 | FileCheck --check-prefixes=CHECK-NOLIB-SO %s // CHECK-NOLIB-SO-NOT: libLLVMFuzzer.a +// RUN: %clang -fsanitize=fuzzer -fsanitize-coverage=trace-pc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-MSG %s +// CHECK-MSG-NOT: argument unused during compilation + int LLVMFuzzerTestOneInput(const char *Data, long Size) { return 0; } From 158a1fe17bb242d8c0555c81de2eb226ad62c9da Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Thu, 29 Jun 2017 20:44:20 +0000 Subject: [PATCH 128/214] Insert llvm_unreachable at the end of a function to silence gcc's -Werror=return-type error. This is an attempt to fix the following failing bot: http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306739 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Darwin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 13cda0d0a1fe..b1f359e8a1fc 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1680,6 +1680,7 @@ bool Darwin::isAlignedAllocationUnavailable() const { case WatchOSSimulator: // Earlier than 4.0. return TargetVersion < VersionTuple(4U, 0U, 0U); } + llvm_unreachable("Unsupported platform"); } void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, From adea55fa1f7fb934e35dfa1e656233f8d507f761 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 29 Jun 2017 22:31:16 +0000 Subject: [PATCH 129/214] Fix openmp-offload.c test on Windows git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306751 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Driver/openmp-offload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index 7a0d62073b6b..8b7929ff3586 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -593,7 +593,7 @@ /// ########################################################################### /// Check -fopenmp-is-device is passed when compiling for the device. -// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \ +// RUN: %clang -### -target powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s -// CHK-FOPENMP-IS-DEVICE: clang{{.*}} "-aux-triple" "powerpc64le-unknown-linux-gnu" {{.*}}.c" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" +// CHK-FOPENMP-IS-DEVICE: clang{{.*}} "-aux-triple" "powerpc64le--linux" {{.*}}.c" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" From 820a5338833931da294b354a4a31d3b713dc23d9 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Thu, 29 Jun 2017 22:53:04 +0000 Subject: [PATCH 130/214] [ODRHash] Improve typedef handling. Follow typedef chains to find the root type when processing types, and also keep track of qualifiers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306753 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ODRHash.cpp | 15 ++++++++++++++- test/Modules/odr_hash.cpp | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index 05bed658f3fc..5c8d151e0818 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -430,6 +430,13 @@ class ODRTypeVisitor : public TypeVisitor { Hash.AddQualType(T); } + void AddType(const Type *T) { + Hash.AddBoolean(T); + if (T) { + Hash.AddType(T); + } + } + void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) { Hash.AddNestedNameSpecifier(NNS); } @@ -517,7 +524,13 @@ class ODRTypeVisitor : public TypeVisitor { void VisitTypedefType(const TypedefType *T) { AddDecl(T->getDecl()); - AddQualType(T->getDecl()->getUnderlyingType().getCanonicalType()); + QualType UnderlyingType = T->getDecl()->getUnderlyingType(); + VisitQualifiers(UnderlyingType.getQualifiers()); + while (const TypedefType *Underlying = + dyn_cast(UnderlyingType.getTypePtr())) { + UnderlyingType = Underlying->getDecl()->getUnderlyingType(); + } + AddType(UnderlyingType.getTypePtr()); VisitType(T); } diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index c94940c73eb6..f01c4e836a30 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -1762,6 +1762,22 @@ struct S2 { #else S2 s2; #endif + +#if defined(FIRST) +using A3 = const int; +using B3 = volatile A3; +struct S3 { + B3 x = 1; +}; +#elif defined(SECOND) +using A3 = volatile const int; +using B3 = A3; +struct S3 { + B3 x = 1; +}; +#else +S3 s3; +#endif } // Keep macros contained to one file. From e4158c49f4b27bfcf3efd2290483f2479cfacafa Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Thu, 29 Jun 2017 23:08:38 +0000 Subject: [PATCH 131/214] [ThinkLTO] Invoke build(Thin)?LTOPreLinkDefaultPipeline. Previously it doesn't actually invoke the designated new PM builder functions. This patch moves NameAnonGlobalPass out from PassBuilder, as Chandler points out that PassBuilder is used for non-O0 builds, and for optimizations only. Differential Revision: https://reviews.llvm.org/D34728 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306756 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/BackendUtil.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index bd01902a032b..2621f035f4e4 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -54,6 +54,7 @@ #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" +#include "llvm/Transforms/Utils/NameAnonGlobals.h" #include "llvm/Transforms/Utils/SymbolRewriter.h" #include using namespace clang; @@ -881,17 +882,28 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( ModulePassManager MPM; if (!CodeGenOpts.DisableLLVMPasses) { + bool IsThinLTO = CodeGenOpts.EmitSummaryIndex; + bool IsLTO = CodeGenOpts.PrepareForLTO; + if (CodeGenOpts.OptimizationLevel == 0) { // Build a minimal pipeline based on the semantics required by Clang, // which is just that always inlining occurs. MPM.addPass(AlwaysInlinerPass()); + if (IsThinLTO) + MPM.addPass(NameAnonGlobalPass()); } else { - // Otherwise, use the default pass pipeline. We also have to map our - // optimization levels into one of the distinct levels used to configure - // the pipeline. + // Map our optimization levels into one of the distinct levels used to + // configure the pipeline. PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); - MPM = PB.buildPerModuleDefaultPipeline(Level); + if (IsThinLTO) { + MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level); + MPM.addPass(NameAnonGlobalPass()); + } else if (IsLTO) { + MPM = PB.buildLTOPreLinkDefaultPipeline(Level); + } else { + MPM = PB.buildPerModuleDefaultPipeline(Level); + } } } From ae1ed388cd6e265fdbb773a11f6797dee9d16fd6 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Thu, 29 Jun 2017 23:10:13 +0000 Subject: [PATCH 132/214] [NewPM] Add Clang cc1 flag -fdebug-pass-manager for printing debug information. Differential Revision: https://reviews.llvm.org/D34790 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306757 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 4 ++ include/clang/Frontend/CodeGenOptions.def | 2 + lib/CodeGen/BackendUtil.cpp | 11 +++-- lib/Frontend/CompilerInvocation.cpp | 4 ++ test/CodeGen/lto-newpm-pipeline.c | 53 +++++++++++++++++++++++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/lto-newpm-pipeline.c diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index ab790c8a0a4b..a0973a2a5a06 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -323,6 +323,10 @@ def flto_unit: Flag<["-"], "flto-unit">, def fno_lto_unit: Flag<["-"], "fno-lto-unit">; def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">, HelpText<"Write minimized bitcode to for the ThinLTO thin link only">; +def fdebug_pass_manager : Flag<["-"], "fdebug-pass-manager">, + HelpText<"Prints debug information for the new pass manager">; +def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">, + HelpText<"Disables debug printing for the new pass manager">; //===----------------------------------------------------------------------===// // Dependency Output Options diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index f3deb05ec6df..827a06735595 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -57,6 +57,8 @@ CODEGENOPT(DisableLifetimeMarkers, 1, 0) ///< Don't emit any lifetime markers CODEGENOPT(DisableO0ImplyOptNone , 1, 0) ///< Don't annonate function with optnone at O0 CODEGENOPT(ExperimentalNewPassManager, 1, 0) ///< Enables the new, experimental ///< pass manager. +CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new + ///< pass manager. CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled. CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. CODEGENOPT(EmitDeclMetadata , 1, 0) ///< Emit special metadata indicating what diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 2621f035f4e4..67ccbcd63a0e 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -879,7 +879,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); - ModulePassManager MPM; + ModulePassManager MPM(CodeGenOpts.DebugPassManager); if (!CodeGenOpts.DisableLLVMPasses) { bool IsThinLTO = CodeGenOpts.EmitSummaryIndex; @@ -897,12 +897,15 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); if (IsThinLTO) { - MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level); + MPM = PB.buildThinLTOPreLinkDefaultPipeline( + Level, CodeGenOpts.DebugPassManager); MPM.addPass(NameAnonGlobalPass()); } else if (IsLTO) { - MPM = PB.buildLTOPreLinkDefaultPipeline(Level); + MPM = PB.buildLTOPreLinkDefaultPipeline(Level, + CodeGenOpts.DebugPassManager); } else { - MPM = PB.buildPerModuleDefaultPipeline(Level); + MPM = PB.buildPerModuleDefaultPipeline(Level, + CodeGenOpts.DebugPassManager); } } } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 7996da33adce..6b0a5f9d87a0 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -476,6 +476,10 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager, /* Default */ false); + Opts.DebugPassManager = + Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager, + /* Default */ false); + if (Arg *A = Args.getLastArg(OPT_fveclib)) { StringRef Name = A->getValue(); if (Name == "Accelerate") diff --git a/test/CodeGen/lto-newpm-pipeline.c b/test/CodeGen/lto-newpm-pipeline.c new file mode 100644 index 000000000000..10112da6d508 --- /dev/null +++ b/test/CodeGen/lto-newpm-pipeline.c @@ -0,0 +1,53 @@ +// REQUIRES: x86-registered-target + +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O0 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-O0 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O0 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-O0 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O1 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O1 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O2 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O2 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O3 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O3 %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -Os %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -Os %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -Oz %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-FULL-OPTIMIZED +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -Oz %s 2>&1 | FileCheck %s \ +// RUN: -check-prefix=CHECK-THIN-OPTIMIZED + +// CHECK-FULL-O0: Starting llvm::Module pass manager run. +// CHECK-FULL-O0: Running pass: AlwaysInlinerPass +// CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass +// CHECK-FULL-O0: Finished llvm::Module pass manager run. + +// CHECK-THIN-O0: Starting llvm::Module pass manager run. +// CHECK-THIN-O0: Running pass: AlwaysInlinerPass +// CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass +// CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass +// CHECK-THIN-O0: Finished llvm::Module pass manager run. + +// TODO: The LTO pre-link pipeline currently invokes +// buildPerModuleDefaultPipeline(), which contains LoopVectorizePass. +// This may change as the pipeline gets implemented. +// CHECK-FULL-OPTIMIZED: Starting llvm::Function pass manager run. +// CHECK-FULL-OPTIMIZED: Running pass: LoopVectorizePass +// CHECK-FULL-OPTIMIZED: Running pass: BitcodeWriterPass + +// The ThinLTO pre-link pipeline shouldn't contain passes like +// LoopVectorizePass. +// CHECK-THIN-OPTIMIZED: Starting llvm::Function pass manager run. +// CHECK-THIN-OPTIMIZED-NOT: Running pass: LoopVectorizePass +// CHECK-THIN-OPTIMIZED: Running pass: NameAnonGlobalPass +// CHECK-THIN-OPTIMIZED: Running pass: ThinLTOBitcodeWriterPass + +void Foo() {} From fe7b37a8ff38f40535f98de2e7b72bdd185cd1ae Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 29 Jun 2017 23:20:54 +0000 Subject: [PATCH 133/214] [clang-format] Switch to case-insensitive header matching and use it to improve support for LLVM-style include sorting. This really is a collection of improvements to the rules for LLVM include sorting: - We have gmock headers now, so it adds support for those to one of the categories. - LLVM does use 'FooTest.cpp' files to test 'Foo.h' so it adds that suffix for finding a main header. - At times the test file's case may not match the header file's case, so switch to case-insensitive regex matching of header names. With this set of changes, I can't spot any misbehaviors when re-sorting all of LLVM's unittest '#include' lines. Thanks to Eric and Daniel for help testing and refining the patch during review! Differential Revision: https://reviews.llvm.org/D33932 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306759 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 2 +- lib/Format/Format.cpp | 12 +++++++----- unittests/Format/SortIncludesTest.cpp | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index c1b62477ed1c..5b587a4db099 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -966,7 +966,7 @@ struct FormatStyle { /// IncludeCategories: /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/' /// Priority: 2 - /// - Regex: '^(<|"(gtest|isl|json)/)' + /// - Regex: '^(<|"(gtest|gmock|isl|json)/)' /// Priority: 3 /// - Regex: '.*' /// Priority: 1 diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 7659d56adf25..94147fcbd2a6 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -579,9 +579,9 @@ FormatStyle getLLVMStyle() { LLVMStyle.ForEachMacros.push_back("Q_FOREACH"); LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH"); LLVMStyle.IncludeCategories = {{"^\"(llvm|llvm-c|clang|clang-c)/", 2}, - {"^(<|\"(gtest|isl|json)/)", 3}, + {"^(<|\"(gtest|gmock|isl|json)/)", 3}, {".*", 1}}; - LLVMStyle.IncludeIsMainRegex = "$"; + LLVMStyle.IncludeIsMainRegex = "(Test)?$"; LLVMStyle.IndentCaseLabels = false; LLVMStyle.IndentWrappedFunctionNames = false; LLVMStyle.IndentWidth = 2; @@ -1409,7 +1409,7 @@ class IncludeCategoryManager { : Style(Style), FileName(FileName) { FileStem = llvm::sys::path::stem(FileName); for (const auto &Category : Style.IncludeCategories) - CategoryRegexs.emplace_back(Category.Regex); + CategoryRegexs.emplace_back(Category.Regex, llvm::Regex::IgnoreCase); IsMainFile = FileName.endswith(".c") || FileName.endswith(".cc") || FileName.endswith(".cpp") || FileName.endswith(".c++") || FileName.endswith(".cxx") || FileName.endswith(".m") || @@ -1437,9 +1437,11 @@ class IncludeCategoryManager { return false; StringRef HeaderStem = llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1)); - if (FileStem.startswith(HeaderStem)) { + if (FileStem.startswith(HeaderStem) || + FileStem.startswith_lower(HeaderStem)) { llvm::Regex MainIncludeRegex( - (HeaderStem + Style.IncludeIsMainRegex).str()); + (HeaderStem + Style.IncludeIsMainRegex).str(), + llvm::Regex::IgnoreCase); if (MainIncludeRegex.match(FileStem)) return true; } diff --git a/unittests/Format/SortIncludesTest.cpp b/unittests/Format/SortIncludesTest.cpp index c3c56a813041..1128ed829ff2 100644 --- a/unittests/Format/SortIncludesTest.cpp +++ b/unittests/Format/SortIncludesTest.cpp @@ -266,6 +266,29 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { "a.cc")); } +TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) { + // Setup an regex for main includes so we can cover those as well. + Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; + + // Ensure both main header detection and grouping work in a case insensitive + // manner. + EXPECT_EQ("#include \"llvm/A.h\"\n" + "#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"LLVM/z.h\"\n" + "#include \"llvm/X.h\"\n" + "#include \"GTest/GTest.h\"\n" + "#include \"gmock/gmock.h\"\n", + sort("#include \"c.h\"\n" + "#include \"b.h\"\n" + "#include \"GTest/GTest.h\"\n" + "#include \"llvm/A.h\"\n" + "#include \"gmock/gmock.h\"\n" + "#include \"llvm/X.h\"\n" + "#include \"LLVM/z.h\"\n", + "a_TEST.cc")); +} + TEST_F(SortIncludesTest, NegativePriorities) { Style.IncludeCategories = {{".*important_os_header.*", -1}, {".*", 1}}; EXPECT_EQ("#include \"important_os_header.h\"\n" From 9f28442d72ed8db4ce56d163e9ea2355cf7cb4ae Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Jun 2017 23:23:46 +0000 Subject: [PATCH 134/214] Teach ASTReader how to read only the Preprocessor state from an AST file, not the ASTContext state. We use this when running a preprocessor-only action on an AST file in order to avoid paying the runtime cost of loading the extra information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306760 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 11 +- include/clang/Serialization/ASTReader.h | 11 +- lib/Frontend/ASTMerge.cpp | 6 +- lib/Frontend/ASTUnit.cpp | 43 ++++---- lib/Frontend/ChainedIncludesSource.cpp | 2 +- lib/Frontend/CompilerInstance.cpp | 4 +- lib/Frontend/FrontendAction.cpp | 9 +- lib/Frontend/FrontendActions.cpp | 2 +- lib/Serialization/ASTReader.cpp | 127 +++++++++++++++++------- lib/Serialization/ASTReaderDecl.cpp | 37 ++++--- lib/Serialization/ASTReaderStmt.cpp | 1 + tools/c-index-test/core_main.cpp | 2 +- tools/libclang/CIndex.cpp | 3 +- 13 files changed, 169 insertions(+), 89 deletions(-) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 2950c31c2d3d..1ac4f07a3549 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -628,6 +628,15 @@ class ASTUnit { IntrusiveRefCntPtr Diags, bool CaptureDiagnostics, bool UserFilesAreVolatile); + enum WhatToLoad { + /// Load options and the preprocessor state. + LoadPreprocessorOnly, + /// Load the AST, but do not restore Sema state. + LoadASTOnly, + /// Load everything, including Sema. + LoadEverything + }; + /// \brief Create a ASTUnit from an AST file. /// /// \param Filename - The AST file to load. @@ -640,7 +649,7 @@ class ASTUnit { /// \returns - The initialized ASTUnit or null if the AST failed to load. static std::unique_ptr LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, - IntrusiveRefCntPtr Diags, + WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, bool OnlyLocalDecls = false, ArrayRef RemappedFiles = None, bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 9b94aadd767f..eafa05175832 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -400,7 +400,7 @@ class ASTReader Preprocessor &PP; /// \brief The AST context into which we'll read the AST files. - ASTContext &Context; + ASTContext *ContextObj = nullptr; /// \brief The AST consumer. ASTConsumer *Consumer = nullptr; @@ -1387,7 +1387,7 @@ class ASTReader /// precompiled header will be loaded. /// /// \param Context the AST context that this precompiled header will be - /// loaded into. + /// loaded into, if any. /// /// \param PCHContainerRdr the PCHContainerOperations to use for loading and /// creating modules. @@ -1419,7 +1419,7 @@ class ASTReader /// /// \param ReadTimer If non-null, a timer used to track the time spent /// deserializing. - ASTReader(Preprocessor &PP, ASTContext &Context, + ASTReader(Preprocessor &PP, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef> Extensions, StringRef isysroot = "", bool DisableValidation = false, @@ -2208,7 +2208,10 @@ class ASTReader void completeVisibleDeclsMap(const DeclContext *DC) override; /// \brief Retrieve the AST context that this AST reader supplements. - ASTContext &getContext() { return Context; } + ASTContext &getContext() { + assert(ContextObj && "requested AST context when not loading AST"); + return *ContextObj; + } // \brief Contains the IDs for declarations that were requested before we have // access to a Sema object. diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp index 986f98ae598b..354527db7bad 100644 --- a/lib/Frontend/ASTMerge.cpp +++ b/lib/Frontend/ASTMerge.cpp @@ -44,9 +44,9 @@ void ASTMergeAction::ExecuteAction() { new ForwardingDiagnosticConsumer( *CI.getDiagnostics().getClient()), /*ShouldOwnClient=*/true)); - std::unique_ptr Unit = - ASTUnit::LoadFromASTFile(ASTFiles[I], CI.getPCHContainerReader(), - Diags, CI.getFileSystemOpts(), false); + std::unique_ptr Unit = ASTUnit::LoadFromASTFile( + ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, + CI.getFileSystemOpts(), false); if (!Unit) continue; diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index c5a911fdae08..1094e6d089a6 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -458,7 +458,7 @@ namespace { /// a Preprocessor. class ASTInfoCollector : public ASTReaderListener { Preprocessor &PP; - ASTContext &Context; + ASTContext *Context; HeaderSearchOptions &HSOpts; PreprocessorOptions &PPOpts; LangOptions &LangOpt; @@ -468,7 +468,7 @@ class ASTInfoCollector : public ASTReaderListener { bool InitializedLanguage; public: - ASTInfoCollector(Preprocessor &PP, ASTContext &Context, + ASTInfoCollector(Preprocessor &PP, ASTContext *Context, HeaderSearchOptions &HSOpts, PreprocessorOptions &PPOpts, LangOptions &LangOpt, std::shared_ptr &TargetOpts, @@ -536,12 +536,15 @@ class ASTInfoCollector : public ASTReaderListener { // Initialize the preprocessor. PP.Initialize(*Target); + if (!Context) + return; + // Initialize the ASTContext - Context.InitBuiltinTypes(*Target); + Context->InitBuiltinTypes(*Target); // We didn't have access to the comment options when the ASTContext was // constructed, so register them now. - Context.getCommentCommandTraits().registerCommentOptions( + Context->getCommentCommandTraits().registerCommentOptions( LangOpt.CommentOpts); } }; @@ -671,7 +674,7 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr Diags, std::unique_ptr ASTUnit::LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, - IntrusiveRefCntPtr Diags, + WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo, bool OnlyLocalDecls, ArrayRef RemappedFiles, bool CaptureDiagnostics, bool AllowPCHWithCompilerErrors, @@ -722,21 +725,21 @@ std::unique_ptr ASTUnit::LoadFromASTFile( /*OwnsHeaderSearch=*/false); Preprocessor &PP = *AST->PP; - AST->Ctx = new ASTContext(*AST->LangOpts, AST->getSourceManager(), - PP.getIdentifierTable(), PP.getSelectorTable(), - PP.getBuiltinInfo()); - ASTContext &Context = *AST->Ctx; + if (ToLoad >= LoadASTOnly) + AST->Ctx = new ASTContext(*AST->LangOpts, AST->getSourceManager(), + PP.getIdentifierTable(), PP.getSelectorTable(), + PP.getBuiltinInfo()); bool disableValid = false; if (::getenv("LIBCLANG_DISABLE_PCH_VALIDATION")) disableValid = true; - AST->Reader = new ASTReader(PP, Context, PCHContainerRdr, { }, + AST->Reader = new ASTReader(PP, AST->Ctx.get(), PCHContainerRdr, { }, /*isysroot=*/"", /*DisableValidation=*/disableValid, AllowPCHWithCompilerErrors); AST->Reader->setListener(llvm::make_unique( - *AST->PP, Context, *AST->HSOpts, *AST->PPOpts, *AST->LangOpts, + *AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts, AST->TargetOpts, AST->Target, Counter)); // Attach the AST reader to the AST context as an external AST @@ -744,7 +747,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile( // AST file as needed. // We need the external source to be set up before we read the AST, because // eagerly-deserialized declarations may use it. - Context.setExternalSource(AST->Reader); + if (AST->Ctx) + AST->Ctx->setExternalSource(AST->Reader); switch (AST->Reader->ReadAST(Filename, serialization::MK_MainFile, SourceLocation(), ASTReader::ARR_None)) { @@ -766,15 +770,18 @@ std::unique_ptr ASTUnit::LoadFromASTFile( PP.setCounterValue(Counter); // Create an AST consumer, even though it isn't used. - AST->Consumer.reset(new ASTConsumer); - + if (ToLoad >= LoadASTOnly) + AST->Consumer.reset(new ASTConsumer); + // Create a semantic analysis object and tell the AST reader about it. - AST->TheSema.reset(new Sema(PP, Context, *AST->Consumer)); - AST->TheSema->Initialize(); - AST->Reader->InitializeSema(*AST->TheSema); + if (ToLoad >= LoadEverything) { + AST->TheSema.reset(new Sema(PP, *AST->Ctx, *AST->Consumer)); + AST->TheSema->Initialize(); + AST->Reader->InitializeSema(*AST->TheSema); + } // Tell the diagnostic client that we have started a source file. - AST->getDiagnostics().getClient()->BeginSourceFile(Context.getLangOpts(),&PP); + AST->getDiagnostics().getClient()->BeginSourceFile(PP.getLangOpts(), &PP); return AST; } diff --git a/lib/Frontend/ChainedIncludesSource.cpp b/lib/Frontend/ChainedIncludesSource.cpp index b984c2ed0dd5..534c7587f48d 100644 --- a/lib/Frontend/ChainedIncludesSource.cpp +++ b/lib/Frontend/ChainedIncludesSource.cpp @@ -83,7 +83,7 @@ createASTReader(CompilerInstance &CI, StringRef pchFile, ASTDeserializationListener *deserialListener = nullptr) { Preprocessor &PP = CI.getPreprocessor(); std::unique_ptr Reader; - Reader.reset(new ASTReader(PP, CI.getASTContext(), + Reader.reset(new ASTReader(PP, &CI.getASTContext(), CI.getPCHContainerReader(), /*Extensions=*/{ }, /*isysroot=*/"", /*DisableValidation=*/true)); diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 9be5f9cd1bd9..bb6a665cb456 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -517,7 +517,7 @@ IntrusiveRefCntPtr CompilerInstance::createPCHExternalASTSource( HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); IntrusiveRefCntPtr Reader(new ASTReader( - PP, Context, PCHContainerRdr, Extensions, + PP, &Context, PCHContainerRdr, Extensions, Sysroot.empty() ? "" : Sysroot.data(), DisablePCHValidation, AllowPCHWithCompilerErrors, /*AllowConfigurationMismatch*/ false, HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex)); @@ -1473,7 +1473,7 @@ void CompilerInstance::createModuleManager() { "Reading modules", *FrontendTimerGroup); ModuleManager = new ASTReader( - getPreprocessor(), getASTContext(), getPCHContainerReader(), + getPreprocessor(), &getASTContext(), getPCHContainerReader(), getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, /*AllowASTWithCompilerErrors=*/false, diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index eed8631bdb8c..704d51509851 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -536,8 +536,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, ASTDiags->setClient(Diags->getClient(), /*OwnsClient*/false); std::unique_ptr AST = ASTUnit::LoadFromASTFile( - InputFile, CI.getPCHContainerReader(), ASTDiags, CI.getFileSystemOpts(), - CI.getCodeGenOpts().DebugTypeExtRefs); + InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly, + ASTDiags, CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs); if (!AST) goto failure; @@ -576,6 +576,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Module *ASTModule = AST->getPreprocessor().getHeaderSearchInfo().lookupModule( AST->getLangOpts().CurrentModule, /*AllowSearch*/ false); + assert(ASTModule && "module file does not define its own module"); Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind); } else { auto &SM = CI.getSourceManager(); @@ -598,8 +599,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, IntrusiveRefCntPtr Diags(&CI.getDiagnostics()); std::unique_ptr AST = ASTUnit::LoadFromASTFile( - InputFile, CI.getPCHContainerReader(), Diags, CI.getFileSystemOpts(), - CI.getCodeGenOpts().DebugTypeExtRefs); + InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, + CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs); if (!AST) goto failure; diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 9621889b27ad..0fbcc1c7399e 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -230,7 +230,7 @@ void VerifyPCHAction::ExecuteAction() { bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot; std::unique_ptr Reader(new ASTReader( - CI.getPreprocessor(), CI.getASTContext(), CI.getPCHContainerReader(), + CI.getPreprocessor(), &CI.getASTContext(), CI.getPCHContainerReader(), CI.getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index fab7539aaa68..f9421c788d93 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -856,7 +856,7 @@ static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, II.isPoisoned() || (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || II.hasRevertedTokenIDToIdentifier() || - (!(IsModule && Reader.getContext().getLangOpts().CPlusPlus) && + (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && II.getFETokenInfo()); } @@ -1148,7 +1148,7 @@ bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, void ASTReader::Error(StringRef Msg) const { Error(diag::err_fe_pch_malformed, Msg); - if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && + if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { Diag(diag::note_module_cache_path) << PP.getHeaderSearchInfo().getModuleCachePath(); @@ -1391,7 +1391,7 @@ bool ASTReader::ReadSLocEntry(int ID) { const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; unsigned NumFileDecls = Record[7]; - if (NumFileDecls) { + if (NumFileDecls && ContextObj) { assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, NumFileDecls)); @@ -2614,10 +2614,11 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { // contains any declarations lexically within it (which it always does!). // This usually has no cost, since we very rarely need the lookup map for // the translation unit outside C++. - DeclContext *DC = Context.getTranslationUnitDecl(); - if (DC->hasExternalLexicalStorage() && - !getContext().getLangOpts().CPlusPlus) - DC->setMustBuildLookupTable(); + if (ASTContext *Ctx = ContextObj) { + DeclContext *DC = Ctx->getTranslationUnitDecl(); + if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) + DC->setMustBuildLookupTable(); + } return Success; } @@ -2706,7 +2707,33 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { // Read and process a record. Record.clear(); StringRef Blob; - switch ((ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { + auto RecordType = + (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob); + + // If we're not loading an AST context, we don't care about most records. + if (!ContextObj) { + switch (RecordType) { + case IDENTIFIER_TABLE: + case IDENTIFIER_OFFSET: + case INTERESTING_IDENTIFIERS: + case STATISTICS: + case PP_CONDITIONAL_STACK: + case PP_COUNTER_VALUE: + case SOURCE_LOCATION_OFFSETS: + case MODULE_OFFSET_MAP: + case SOURCE_MANAGER_LINE_TABLE: + case SOURCE_LOCATION_PRELOADS: + case PPD_ENTITIES_OFFSETS: + case HEADER_SEARCH_TABLE: + case IMPORTED_MODULES: + case MACRO_OFFSET: + break; + default: + continue; + } + } + + switch (RecordType) { default: // Default behavior: ignore. break; @@ -2765,7 +2792,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { } case TU_UPDATE_LEXICAL: { - DeclContext *TU = Context.getTranslationUnitDecl(); + DeclContext *TU = ContextObj->getTranslationUnitDecl(); LexicalContents Contents( reinterpret_cast( Blob.data()), @@ -3661,7 +3688,7 @@ bool ASTReader::loadGlobalIndex() { return false; if (TriedLoadingGlobalIndex || !UseGlobalIndex || - !Context.getLangOpts().Modules) + !PP.getLangOpts().Modules) return true; // Try to load the global index. @@ -3679,7 +3706,7 @@ bool ASTReader::loadGlobalIndex() { } bool ASTReader::isGlobalIndexUnavailable() const { - return Context.getLangOpts().Modules && UseGlobalIndex && + return PP.getLangOpts().Modules && UseGlobalIndex && !hasGlobalIndex() && TriedLoadingGlobalIndex; } @@ -3737,7 +3764,9 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, Deserializing AnASTFile(this); // Bump the generation number. - unsigned PreviousGeneration = incrementGeneration(Context); + unsigned PreviousGeneration = 0; + if (ContextObj) + PreviousGeneration = incrementGeneration(*ContextObj); unsigned NumModules = ModuleMgr.size(); SmallVector Loaded; @@ -3756,7 +3785,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, LoadedSet.insert(IM.Mod); ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, - Context.getLangOpts().Modules + PP.getLangOpts().Modules ? &PP.getHeaderSearchInfo().getModuleMap() : nullptr); @@ -3852,7 +3881,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); } - if (!Context.getLangOpts().CPlusPlus || + if (!PP.getLangOpts().CPlusPlus || (Type != MK_ImplicitModule && Type != MK_ExplicitModule && Type != MK_PrebuiltModule)) { // Mark all of the identifiers in the identifier table as being out of date, @@ -3909,7 +3938,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, // Might be unnecessary as use declarations are only used to build the // module itself. - InitializeContext(); + if (ContextObj) + InitializeContext(); if (SemaObj) UpdateSema(); @@ -3931,10 +3961,12 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, // For any Objective-C class definitions we have already loaded, make sure // that we load any additional categories. - for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { - loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), - ObjCClassesLoaded[I], - PreviousGeneration); + if (ContextObj) { + for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { + loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), + ObjCClassesLoaded[I], + PreviousGeneration); + } } if (PP.getHeaderSearchInfo() @@ -4314,6 +4346,9 @@ ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { } void ASTReader::InitializeContext() { + assert(ContextObj && "no context to initialize"); + ASTContext &Context = *ContextObj; + // If there's a listener, notify them that we "read" the translation unit. if (DeserializationListener) DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, @@ -5048,8 +5083,8 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { break; } case SUBMODULE_REQUIRES: { - CurrentModule->addRequirement(Blob, Record[0], Context.getLangOpts(), - Context.getTargetInfo()); + CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), + PP.getTargetInfo()); break; } @@ -5075,10 +5110,12 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { } case SUBMODULE_INITIALIZERS: + if (!ContextObj) + break; SmallVector Inits; for (auto &ID : Record) Inits.push_back(getGlobalDeclID(F, ID)); - Context.addLazyModuleInitializers(CurrentModule, Inits); + ContextObj->addLazyModuleInitializers(CurrentModule, Inits); break; } } @@ -5699,6 +5736,8 @@ ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { /// location. It is a helper routine for GetType, which deals with reading type /// IDs. QualType ASTReader::readTypeRecord(unsigned Index) { + assert(ContextObj && "reading type with no AST context"); + ASTContext &Context = *ContextObj; RecordLocation Loc = TypeCursorForIndex(Index); BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; @@ -6555,6 +6594,9 @@ ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, } QualType ASTReader::GetType(TypeID ID) { + assert(ContextObj && "reading type with no AST context"); + ASTContext &Context = *ContextObj; + unsigned FastQuals = ID & Qualifiers::FastMask; unsigned Index = ID >> Qualifiers::FastWidth; @@ -6886,6 +6928,9 @@ ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { } CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { + assert(ContextObj && "reading base specifiers with no AST context"); + ASTContext &Context = *ContextObj; + RecordLocation Loc = getLocalBitOffset(Offset); BitstreamCursor &Cursor = Loc.F->DeclsCursor; SavedStreamPosition SavedPosition(Cursor); @@ -7017,8 +7062,9 @@ static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { } Decl *ASTReader::GetExistingDecl(DeclID ID) { + assert(ContextObj && "reading decl with no AST context"); if (ID < NUM_PREDEF_DECL_IDS) { - Decl *D = getPredefinedDecl(Context, (PredefinedDeclIDs)ID); + Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); if (D) { // Track that we have merged the declaration with ID \p ID into the // pre-existing predefined declaration \p D. @@ -7563,7 +7609,7 @@ IdentifierInfo *ASTReader::get(StringRef Name) { // all interesting declarations, and don't need to use the scope for name // lookups). Perform the lookup in PCH files, though, since we don't build // a complete initial identifier table if we're carrying on from a PCH. - if (Context.getLangOpts().CPlusPlus) { + if (PP.getLangOpts().CPlusPlus) { for (auto F : ModuleMgr.pch_modules()) if (Visitor(*F)) break; @@ -8293,6 +8339,7 @@ ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { DeclarationName ASTReader::ReadDeclarationName(ModuleFile &F, const RecordData &Record, unsigned &Idx) { + ASTContext &Context = getContext(); DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; switch (Kind) { case DeclarationName::Identifier: @@ -8383,7 +8430,8 @@ void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, unsigned NumTPLists = Record[Idx++]; Info.NumTemplParamLists = NumTPLists; if (NumTPLists) { - Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; + Info.TemplParamLists = + new (getContext()) TemplateParameterList *[NumTPLists]; for (unsigned i = 0; i != NumTPLists; ++i) Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); } @@ -8392,6 +8440,7 @@ void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, TemplateName ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, unsigned &Idx) { + ASTContext &Context = getContext(); TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; switch (Kind) { case TemplateName::Template: @@ -8452,6 +8501,7 @@ TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize) { + ASTContext &Context = getContext(); if (Canonicalize) { // The caller wants a canonical template argument. Sometimes the AST only // wants template arguments in canonical form (particularly as the template @@ -8515,9 +8565,8 @@ ASTReader::ReadTemplateParameterList(ModuleFile &F, Params.push_back(ReadDeclAs(F, Record, Idx)); // TODO: Concepts - TemplateParameterList* TemplateParams = - TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, - Params, RAngleLoc, nullptr); + TemplateParameterList *TemplateParams = TemplateParameterList::Create( + getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr); return TemplateParams; } @@ -8536,11 +8585,11 @@ ReadTemplateArgumentList(SmallVectorImpl &TemplArgs, void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, const RecordData &Record, unsigned &Idx) { unsigned NumDecls = Record[Idx++]; - Set.reserve(Context, NumDecls); + Set.reserve(getContext(), NumDecls); while (NumDecls--) { DeclID ID = ReadDeclID(F, Record, Idx); AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; - Set.addLazyDecl(Context, ID, AS); + Set.addLazyDecl(getContext(), ID, AS); } } @@ -8563,6 +8612,7 @@ ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, CXXCtorInitializer ** ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, unsigned &Idx) { + ASTContext &Context = getContext(); unsigned NumInitializers = Record[Idx++]; assert(NumInitializers && "wrote ctor initializers but have no inits"); auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; @@ -8628,6 +8678,7 @@ ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, NestedNameSpecifier * ASTReader::ReadNestedNameSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx) { + ASTContext &Context = getContext(); unsigned N = Record[Idx++]; NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; for (unsigned I = 0; I != N; ++I) { @@ -8683,6 +8734,7 @@ ASTReader::ReadNestedNameSpecifier(ModuleFile &F, NestedNameSpecifierLoc ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx) { + ASTContext &Context = getContext(); unsigned N = Record[Idx++]; NestedNameSpecifierLocBuilder Builder; for (unsigned I = 0; I != N; ++I) { @@ -8804,7 +8856,7 @@ CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx) { CXXDestructorDecl *Decl = ReadDeclAs(F, Record, Idx); - return CXXTemporary::Create(Context, Decl); + return CXXTemporary::Create(getContext(), Decl); } DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { @@ -8840,6 +8892,7 @@ void ASTReader::ClearSwitchCaseIDs() { } void ASTReader::ReadComments() { + ASTContext &Context = getContext(); std::vector Comments; for (SmallVectorImpl >::iterator @@ -9521,8 +9574,8 @@ void ASTReader::diagnoseOdrViolations() { break; } - assert( - Context.hasSameType(FirstField->getType(), SecondField->getType())); + assert(getContext().hasSameType(FirstField->getType(), + SecondField->getType())); QualType FirstType = FirstField->getType(); QualType SecondType = SecondField->getType(); @@ -9973,10 +10026,10 @@ void ASTReader::FinishedDeserializing() { ProcessingUpdatesRAIIObj ProcessingUpdates(*this); auto *FPT = Update.second->getType()->castAs(); auto ESI = FPT->getExtProtoInfo().ExceptionSpec; - if (auto *Listener = Context.getASTMutationListener()) + if (auto *Listener = getContext().getASTMutationListener()) Listener->ResolvedExceptionSpec(cast(Update.second)); for (auto *Redecl : Update.second->redecls()) - Context.adjustExceptionSpec(cast(Redecl), ESI); + getContext().adjustExceptionSpec(cast(Redecl), ESI); } } @@ -10018,7 +10071,7 @@ void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { } } -ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, +ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef> Extensions, StringRef isysroot, bool DisableValidation, @@ -10031,7 +10084,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, : cast(new PCHValidator(PP, *this))), SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), - Context(Context), + ContextObj(Context), ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr), PCMCache(PP.getPCMCache()), DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot), diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index e1b1abba46fb..f07c1b1a39f1 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1587,8 +1587,8 @@ void ASTDeclReader::ReadCXXDefinitionData( Lambda.NumExplicitCaptures = Record.readInt(); Lambda.ManglingNumber = Record.readInt(); Lambda.ContextDecl = ReadDeclID(); - Lambda.Captures - = (Capture*)Reader.Context.Allocate(sizeof(Capture)*Lambda.NumCaptures); + Lambda.Captures = (Capture *)Reader.getContext().Allocate( + sizeof(Capture) * Lambda.NumCaptures); Capture *ToCapture = Lambda.Captures; Lambda.MethodTyInfo = GetTypeSourceInfo(); for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { @@ -2006,7 +2006,7 @@ void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { // We were loaded before our templated declaration was. We've not set up // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct // it now. - Reader.Context.getInjectedClassNameType( + Reader.getContext().getInjectedClassNameType( D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); } } @@ -2493,8 +2493,8 @@ void ASTDeclReader::mergeMergeable(Mergeable *D) { if (FindExistingResult ExistingRes = findExisting(static_cast(D))) if (T *Existing = ExistingRes) - Reader.Context.setPrimaryMergedDecl(static_cast(D), - Existing->getCanonicalDecl()); + Reader.getContext().setPrimaryMergedDecl(static_cast(D), + Existing->getCanonicalDecl()); } void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { @@ -2530,6 +2530,7 @@ void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { Attr *New = nullptr; attr::Kind Kind = (attr::Kind)Record.readInt(); SourceRange Range = Record.readSourceRange(); + ASTContext &Context = getContext(); #include "clang/Serialization/AttrPCHRead.inc" @@ -2928,7 +2929,7 @@ DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, // commit to DC being the canonical definition now, and will fix this when // we load the update record. if (!DD) { - DD = new (Reader.Context) struct CXXRecordDecl::DefinitionData(RD); + DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); RD->IsCompleteDefinition = true; RD->DefinitionData = DD; RD->getCanonicalDecl()->DefinitionData = DD; @@ -3373,6 +3374,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); unsigned Code = DeclsCursor.ReadCode(); + ASTContext &Context = getContext(); Decl *D = nullptr; switch ((DeclCode)Record.readRecord(DeclsCursor, Code)) { case DECL_CONTEXT_LEXICAL: @@ -3673,7 +3675,7 @@ void ASTReader::PassInterestingDeclsToConsumer() { while (!PotentiallyInterestingDecls.empty()) { InterestingDecl D = PotentiallyInterestingDecls.front(); PotentiallyInterestingDecls.pop_front(); - if (isConsumerInterestedIn(Context, D.getDecl(), D.hasPendingBody())) + if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) PassInterestingDeclToConsumer(D.getDecl()); } } @@ -3695,7 +3697,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { // to isConsumerInterestedIn because it is unsafe to call in the // current ASTReader state. bool WasInteresting = - Record.JustLoaded || isConsumerInterestedIn(Context, D, false); + Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); for (auto &FileAndOffset : UpdateOffsets) { ModuleFile *F = FileAndOffset.first; uint64_t Offset = FileAndOffset.second; @@ -3715,7 +3717,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { // We might have made this declaration interesting. If so, remember that // we need to hand it off to the consumer. if (!WasInteresting && - isConsumerInterestedIn(Context, D, Reader.hasPendingBody())) { + isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { PotentiallyInterestingDecls.push_back( InterestingDecl(D, Reader.hasPendingBody())); WasInteresting = true; @@ -4104,7 +4106,7 @@ void ASTDeclReader::UpdateDecl(Decl *D) { // FIXME: If the exception specification is already present, check that it // matches. if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { - FD->setType(Reader.Context.getFunctionType( + FD->setType(Reader.getContext().getFunctionType( FPT->getReturnType(), FPT->getParamTypes(), FPT->getExtProtoInfo().withExceptionSpec(ESI))); @@ -4122,28 +4124,31 @@ void ASTDeclReader::UpdateDecl(Decl *D) { for (auto *Redecl : merged_redecls(D)) { // FIXME: If the return type is already deduced, check that it matches. FunctionDecl *FD = cast(Redecl); - Reader.Context.adjustDeducedFunctionResultType(FD, DeducedResultType); + Reader.getContext().adjustDeducedFunctionResultType(FD, + DeducedResultType); } break; } case UPD_DECL_MARKED_USED: { // Maintain AST consistency: any later redeclarations are used too. - D->markUsed(Reader.Context); + D->markUsed(Reader.getContext()); break; } case UPD_MANGLING_NUMBER: - Reader.Context.setManglingNumber(cast(D), Record.readInt()); + Reader.getContext().setManglingNumber(cast(D), + Record.readInt()); break; case UPD_STATIC_LOCAL_NUMBER: - Reader.Context.setStaticLocalNumber(cast(D), Record.readInt()); + Reader.getContext().setStaticLocalNumber(cast(D), + Record.readInt()); break; case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: - D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( - Reader.Context, ReadSourceRange())); + D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(), + ReadSourceRange())); break; case UPD_DECL_EXPORTED: { diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 3d314a85ff17..afee50ffa3b9 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -2954,6 +2954,7 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; } + ASTContext &Context = getContext(); Stmt *S = nullptr; bool Finished = false; bool IsStmtReference = false; diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index 4f2c3cb34a9b..c255f54ba68c 100644 --- a/tools/c-index-test/core_main.cpp +++ b/tools/c-index-test/core_main.cpp @@ -217,7 +217,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, IntrusiveRefCntPtr Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions()); std::unique_ptr AU = ASTUnit::LoadFromASTFile( - modulePath, *pchRdr, Diags, + modulePath, *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, /*OnlyLocalDecls=*/true, None, /*CaptureDiagnostics=*/false, diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index f92096195081..deaab3608e62 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3247,7 +3247,8 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, IntrusiveRefCntPtr Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions()); std::unique_ptr AU = ASTUnit::LoadFromASTFile( - ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), Diags, + ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), + ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(), None, /*CaptureDiagnostics=*/true, From db18c6fcf7ad7b5e05104070b78e61fcc1db4bd9 Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Thu, 29 Jun 2017 23:33:13 +0000 Subject: [PATCH 135/214] [PM] Add support for sample PGO in the new pass manager (clang-side) Summary: This implements the clang bits of https://reviews.llvm.org/D34720, and add corresponding test to verify if it worked. Reviewers: chandlerc, davidxl, davide, tejohnson Reviewed By: chandlerc, tejohnson Subscribers: tejohnson, sanjoy, mehdi_amini, eraman, cfe-commits Differential Revision: https://reviews.llvm.org/D34721 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306764 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/BackendUtil.cpp | 6 +++++- test/CodeGen/pgo-sample-thinlto-summary.c | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 67ccbcd63a0e..fcd0550b9436 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -857,11 +857,15 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( if (CodeGenOpts.hasProfileIRUse()) PGOOpt.ProfileUseFile = CodeGenOpts.ProfileInstrumentUsePath; + if (!CodeGenOpts.SampleProfileFile.empty()) + PGOOpt.SampleProfileFile = CodeGenOpts.SampleProfileFile; + // Only pass a PGO options struct if -fprofile-generate or // -fprofile-use were passed on the cmdline. PassBuilder PB(TM.get(), (PGOOpt.RunProfileGen || - !PGOOpt.ProfileUseFile.empty()) ? + !PGOOpt.ProfileUseFile.empty() || + !PGOOpt.SampleProfileFile.empty()) ? Optional(PGOOpt) : None); LoopAnalysisManager LAM; diff --git a/test/CodeGen/pgo-sample-thinlto-summary.c b/test/CodeGen/pgo-sample-thinlto-summary.c index d64de536e184..51c8faa6be6d 100644 --- a/test/CodeGen/pgo-sample-thinlto-summary.c +++ b/test/CodeGen/pgo-sample-thinlto-summary.c @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO +// FIXME: Run the following command once LTOPreLinkDefaultPipeline is +// customized. +// %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO // Checks if hot call is inlined by normal compile, but not inlined by // thinlto compile. @@ -36,7 +40,9 @@ void unroll() { // SAMPLEPGO-LABEL: define void @icp // THINLTO-LABEL: define void @icp // SAMPLEPGO: if.true.direct_targ -// ThinLTO-NOT: if.true.direct_targ +// FIXME: the following condition needs to be reversed once +// LTOPreLinkDefaultPipeline is customized. +// THINLTO-NOT: if.true.direct_targ void icp(void (*p)()) { p(); } From 1fd33aee50ee815e88bbb6046372df30ba674966 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 30 Jun 2017 00:03:56 +0000 Subject: [PATCH 136/214] Unified logic for computing target ABI in backend and front end by moving this common code to Support/TargetParser. Modeled Triple::GNU after front end code (aapcs abi) and updated tests that expect apcs abi. Patch by Ana Pazos! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306769 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Clang.cpp | 41 ++++------------------ test/CodeGen/arm-v8.1a-neon-intrinsics.c | 2 +- test/CodeGen/named_reg_global.c | 2 +- test/CodeGen/neon-immediate-ubsan.c | 2 +- test/CodeGen/xray-attributes-supported.cpp | 2 +- 5 files changed, 10 insertions(+), 39 deletions(-) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 9d222a21357a..c9529fc9df1c 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -35,6 +35,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" +#include "llvm/Support/TargetParser.h" #include "llvm/Support/YAMLParser.h" #ifdef LLVM_ON_UNIX @@ -1315,43 +1316,13 @@ void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args, // FIXME: Support -meabi. // FIXME: Parts of this are duplicated in the backend, unify this somehow. const char *ABIName = nullptr; - if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { + if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) ABIName = A->getValue(); - } else if (Triple.isOSBinFormatMachO()) { - if (arm::useAAPCSForMachO(Triple)) { - ABIName = "aapcs"; - } else if (Triple.isWatchABI()) { - ABIName = "aapcs16"; - } else { - ABIName = "apcs-gnu"; - } - } else if (Triple.isOSWindows()) { - // FIXME: this is invalid for WindowsCE - ABIName = "aapcs"; - } else { - // Select the default based on the platform. - switch (Triple.getEnvironment()) { - case llvm::Triple::Android: - case llvm::Triple::GNUEABI: - case llvm::Triple::GNUEABIHF: - case llvm::Triple::MuslEABI: - case llvm::Triple::MuslEABIHF: - ABIName = "aapcs-linux"; - break; - case llvm::Triple::EABIHF: - case llvm::Triple::EABI: - ABIName = "aapcs"; - break; - default: - if (Triple.getOS() == llvm::Triple::NetBSD) - ABIName = "apcs-gnu"; - else if (Triple.getOS() == llvm::Triple::OpenBSD) - ABIName = "aapcs-linux"; - else - ABIName = "aapcs"; - break; - } + else { + StringRef CPU = getCPUName(Args, Triple, /*FromAs*/ false); + ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data(); } + CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); diff --git a/test/CodeGen/arm-v8.1a-neon-intrinsics.c b/test/CodeGen/arm-v8.1a-neon-intrinsics.c index 788883100456..6f5867b6c11f 100644 --- a/test/CodeGen/arm-v8.1a-neon-intrinsics.c +++ b/test/CodeGen/arm-v8.1a-neon-intrinsics.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple armv8.1a-linux-gnu -target-feature +neon \ +// RUN: %clang_cc1 -triple armv8.1a-linux-gnu -target-abi apcs-gnu -target-feature +neon \ // RUN: -S -emit-llvm -o - %s \ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM diff --git a/test/CodeGen/named_reg_global.c b/test/CodeGen/named_reg_global.c index 1da625746891..232b74de1cab 100644 --- a/test/CodeGen/named_reg_global.c +++ b/test/CodeGen/named_reg_global.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X86-64 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM -// RUN: %clang_cc1 -triple armv7-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM +// RUN: %clang_cc1 -triple armv7-linux-gnu -target-abi apcs-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM // CHECK-NOT: @sp = common global diff --git a/test/CodeGen/neon-immediate-ubsan.c b/test/CodeGen/neon-immediate-ubsan.c index c3e1ce23301d..aacf76a6338b 100644 --- a/test/CodeGen/neon-immediate-ubsan.c +++ b/test/CodeGen/neon-immediate-ubsan.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple armv7s-linux-gnu -emit-llvm -o - %s \ +// RUN: %clang_cc1 -triple armv7s-linux-gnu -target-abi apcs-gnu -emit-llvm -o - %s \ // RUN: -target-feature +neon -target-cpu cortex-a8 \ // RUN: -fsanitize=signed-integer-overflow \ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=ARMV7 diff --git a/test/CodeGen/xray-attributes-supported.cpp b/test/CodeGen/xray-attributes-supported.cpp index 860efb276f69..21a5dde53a05 100644 --- a/test/CodeGen/xray-attributes-supported.cpp +++ b/test/CodeGen/xray-attributes-supported.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple x86_64-unknown-linux-gnu | FileCheck %s -// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple arm-unknown-linux-gnu | FileCheck %s +// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple arm-unknown-linux-gnu -target-abi apcs-gnu | FileCheck %s // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mips-unknown-linux-gnu | FileCheck %s // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mipsel-unknown-linux-gnu | FileCheck %s // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mips64-unknown-linux-gnu | FileCheck %s From 6f6b2e231cef5e6714e42eebd485e6f798919a58 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Fri, 30 Jun 2017 00:07:54 +0000 Subject: [PATCH 137/214] [CodeGen] Propagate dllexport to thunks Under Windows Itanium, we need to export virtual and non-virtual thunks if the functions being thunked are exported. These thunks would previously inherit their dllexport attribute from the declaration, but r298330 changed declarations to not have dllexport attributes. We therefore need to add the dllexport attribute to the definition ourselves now. Differential Revision: https://reviews.llvm.org/D34850 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306770 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 4 ++++ test/CodeGenCXX/windows-itanium-dllexport.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 64b6d0d3fe9f..7c9f07d32d87 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -64,6 +64,10 @@ static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, const CXXMethodDecl *MD = cast(GD.getDecl()); setThunkVisibility(CGM, MD, Thunk, ThunkFn); + // Propagate dllexport storage. + if (MD->hasAttr()) + ThunkFn->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); + if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker()) ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName())); } diff --git a/test/CodeGenCXX/windows-itanium-dllexport.cpp b/test/CodeGenCXX/windows-itanium-dllexport.cpp index ff780c777822..ffb8f610f5c3 100644 --- a/test/CodeGenCXX/windows-itanium-dllexport.cpp +++ b/test/CodeGenCXX/windows-itanium-dllexport.cpp @@ -53,3 +53,12 @@ USEMEMFUNC(outer::inner, f) // CHECK: declare dllimport {{.*}} @_ZN5outerIcE1fEv // CHECK: define {{.*}} @_ZN5outerIcE5inner1fEv + +struct base { + virtual ~base(); +}; +struct __declspec(dllexport) derived : public virtual base { + virtual ~derived() {} +}; + +// CHECK: define {{.*}} dllexport {{.*}} @_ZTv0_n12_N7derivedD0Ev From 115b2ce9071f099b2a14bdb8b02985e4b910a116 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 30 Jun 2017 00:44:01 +0000 Subject: [PATCH 138/214] [WebAssembly] Add throw/rethrow builtins for exception handling Summary: Add new builtins for throw/rethrow instructions. This follows exception handling handling proposal in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md Reviewers: sunfish, dschuff Reviewed By: dschuff Subscribers: jfb, dschuff, sbc100, jgravelle-google Differential Revision: https://reviews.llvm.org/D34783 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306775 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/BuiltinsWebAssembly.def | 4 ++++ lib/CodeGen/CGBuiltin.cpp | 10 ++++++++++ test/CodeGen/builtins-wasm.c | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/clang/Basic/BuiltinsWebAssembly.def b/include/clang/Basic/BuiltinsWebAssembly.def index de56908be83c..19318dcebb9e 100644 --- a/include/clang/Basic/BuiltinsWebAssembly.def +++ b/include/clang/Basic/BuiltinsWebAssembly.def @@ -21,4 +21,8 @@ BUILTIN(__builtin_wasm_current_memory, "z", "n") BUILTIN(__builtin_wasm_grow_memory, "zz", "n") +// Exception handling builtins. +BUILTIN(__builtin_wasm_throw, "vUiv*", "r") +BUILTIN(__builtin_wasm_rethrow, "v", "r") + #undef BUILTIN diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index a6451b7fc3c1..2a6e92e7f3ce 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -9372,6 +9372,16 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_grow_memory, X->getType()); return Builder.CreateCall(Callee, X); } + case WebAssembly::BI__builtin_wasm_throw: { + Value *Tag = EmitScalarExpr(E->getArg(0)); + Value *Obj = EmitScalarExpr(E->getArg(1)); + Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_throw); + return Builder.CreateCall(Callee, {Tag, Obj}); + } + case WebAssembly::BI__builtin_wasm_rethrow: { + Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_rethrow); + return Builder.CreateCall(Callee); + } default: return nullptr; diff --git a/test/CodeGen/builtins-wasm.c b/test/CodeGen/builtins-wasm.c index 0c0b87945d42..e0f72d2e5034 100644 --- a/test/CodeGen/builtins-wasm.c +++ b/test/CodeGen/builtins-wasm.c @@ -14,3 +14,15 @@ __SIZE_TYPE__ f2(__SIZE_TYPE__ delta) { // WEBASSEMBLY32: call i32 @llvm.wasm.grow.memory.i32(i32 %{{.*}}) // WEBASSEMBLY64: call i64 @llvm.wasm.grow.memory.i64(i64 %{{.*}}) } + +void f3(unsigned int tag, void *obj) { + return __builtin_wasm_throw(tag, obj); +// WEBASSEMBLY32: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}}) +// WEBASSEMBLY64: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}}) +} + +void f4() { + return __builtin_wasm_rethrow(); +// WEBASSEMBLY32: call void @llvm.wasm.rethrow() +// WEBASSEMBLY64: call void @llvm.wasm.rethrow() +} From 2d0264ba15bc74c1addd5bf03f06e26fdc7860db Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Fri, 30 Jun 2017 02:57:34 +0000 Subject: [PATCH 139/214] Test Commit git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306782 91177308-0d34-0410-b5e6-96231b3b80d8 --- README.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/README.txt b/README.txt index ada9ebc9e231..5477b9c8bac0 100644 --- a/README.txt +++ b/README.txt @@ -24,3 +24,4 @@ on the Clang development mailing list: If you find a bug in Clang, please file it in the LLVM bug tracker: http://llvm.org/bugs/ + From 2b17779e61a95505f5037f90b19646b49ef9a2bd Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Fri, 30 Jun 2017 03:03:28 +0000 Subject: [PATCH 140/214] Remove test commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306783 91177308-0d34-0410-b5e6-96231b3b80d8 --- README.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/README.txt b/README.txt index 5477b9c8bac0..ada9ebc9e231 100644 --- a/README.txt +++ b/README.txt @@ -24,4 +24,3 @@ on the Clang development mailing list: If you find a bug in Clang, please file it in the LLVM bug tracker: http://llvm.org/bugs/ - From a7f9678242b672878fd65efeb91b2f0505c548de Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 30 Jun 2017 05:13:31 +0000 Subject: [PATCH 141/214] Remove Clang support for '-fvectorize-slp-aggressive' which used LLVM's basic block vectorizer. This vectorizer has had no known users for many, many years and is completely surpassed by the normal '-fvectorize-slp'-controlled SLP vectorizer in LLVM. Hal proposed this back in 2014 to no objections: http://lists.llvm.org/pipermail/llvm-dev/2014-November/079091.html While this patch completely removes the flag, Joerg is working on a patch that will add it back in a way that warns users and ignores the flag in a clear and well factored way (so that we can keep doing this going forward). Differential Revision: https://reviews.llvm.org/D34846 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306786 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 2 -- include/clang/Driver/Options.td | 3 --- include/clang/Frontend/CodeGenOptions.def | 1 - lib/CodeGen/BackendUtil.cpp | 1 - lib/Driver/ToolChains/Clang.cpp | 5 ----- lib/Frontend/CompilerInvocation.cpp | 1 - test/Driver/clang_f_opts.c | 7 ------- 7 files changed, 20 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index a0973a2a5a06..5f3ce5e95fee 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -268,8 +268,6 @@ def vectorize_loops : Flag<["-"], "vectorize-loops">, HelpText<"Run the Loop vectorization passes">; def vectorize_slp : Flag<["-"], "vectorize-slp">, HelpText<"Run the SLP vectorization passes">; -def vectorize_slp_aggressive : Flag<["-"], "vectorize-slp-aggressive">, - HelpText<"Run the BB vectorization passes">; def dependent_lib : Joined<["--"], "dependent-lib=">, HelpText<"Add dependent library">; def linker_option : Joined<["--"], "linker-option=">, diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 68b331fed2bd..90791fbfd4e1 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1405,9 +1405,6 @@ def : Flag<["-"], "fno-tree-vectorize">, Alias; def fslp_vectorize : Flag<["-"], "fslp-vectorize">, Group, HelpText<"Enable the superword-level parallelism vectorization passes">; def fno_slp_vectorize : Flag<["-"], "fno-slp-vectorize">, Group; -def fslp_vectorize_aggressive : Flag<["-"], "fslp-vectorize-aggressive">, Group, - HelpText<"Enable the BB vectorization passes">; -def fno_slp_vectorize_aggressive : Flag<["-"], "fno-slp-vectorize-aggressive">, Group; def : Flag<["-"], "ftree-slp-vectorize">, Alias; def : Flag<["-"], "fno-tree-slp-vectorize">, Alias; def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 827a06735595..6eac39c75356 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -179,7 +179,6 @@ CODEGENOPT(RerollLoops , 1, 0) ///< Control whether loops are rerolled. CODEGENOPT(NoUseJumpTables , 1, 0) ///< Set when -fno-jump-tables is enabled. CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns. CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. -CODEGENOPT(VectorizeBB , 1, 0) ///< Run basic block vectorizer. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index fcd0550b9436..b528cb467b9b 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -492,7 +492,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize; - PMBuilder.BBVectorize = CodeGenOpts.VectorizeBB; PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP; PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index c9529fc9df1c..a3e7e9cdf59a 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4127,11 +4127,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_slp_vectorize, EnableSLPVec)) CmdArgs.push_back("-vectorize-slp"); - // -fno-slp-vectorize-aggressive is default. - if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, - options::OPT_fno_slp_vectorize_aggressive, false)) - CmdArgs.push_back("-vectorize-slp-aggressive"); - if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) A->render(Args, CmdArgs); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 6b0a5f9d87a0..b1b10ddf965c 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -672,7 +672,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); - Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive); Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops); Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index bad49942a4c4..e4b72d69ca3f 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -178,13 +178,6 @@ // CHECK-SLP-VECTORIZE: "-vectorize-slp" // CHECK-NO-SLP-VECTORIZE-NOT: "-vectorize-slp" -// RUN: %clang -### -S -fslp-vectorize-aggressive %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE-AGG %s -// RUN: %clang -### -S -fno-slp-vectorize-aggressive -fslp-vectorize-aggressive %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE-AGG %s -// RUN: %clang -### -S -fno-slp-vectorize-aggressive %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE-AGG %s -// RUN: %clang -### -S -fslp-vectorize-aggressive -fno-slp-vectorize-aggressive %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE-AGG %s -// CHECK-SLP-VECTORIZE-AGG: "-vectorize-slp-aggressive" -// CHECK-NO-SLP-VECTORIZE-AGG-NOT: "-vectorize-slp-aggressive" - // RUN: %clang -### -S -fextended-identifiers %s 2>&1 | FileCheck -check-prefix=CHECK-EXTENDED-IDENTIFIERS %s // RUN: not %clang -### -S -fno-extended-identifiers %s 2>&1 | FileCheck -check-prefix=CHECK-NO-EXTENDED-IDENTIFIERS %s // CHECK-EXTENDED-IDENTIFIERS: "-cc1" From 44fc78d5680090b3fcf5775d2e74c9d92d60782a Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Fri, 30 Jun 2017 05:40:31 +0000 Subject: [PATCH 142/214] fix trivial typos, NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306789 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/PTHLexer.h | 2 +- include/clang/Sema/Sema.h | 2 +- lib/Parse/ParseDeclCXX.cpp | 2 +- lib/Sema/SemaDeclAttr.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/clang/Lex/PTHLexer.h b/include/clang/Lex/PTHLexer.h index 904be792b2a9..f96af665b157 100644 --- a/include/clang/Lex/PTHLexer.h +++ b/include/clang/Lex/PTHLexer.h @@ -36,7 +36,7 @@ class PTHLexer : public PreprocessorLexer { const unsigned char* LastHashTokPtr; /// PPCond - Pointer to a side table in the PTH file that provides a - /// a consise summary of the preproccessor conditional block structure. + /// a concise summary of the preprocessor conditional block structure. /// This is used to perform quick skipping of conditional blocks. const unsigned char* PPCond; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index ef33712d4f47..8dee74eb2a12 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3233,7 +3233,7 @@ class Sema { void ProcessPragmaWeak(Scope *S, Decl *D); // Decl attributes - this routine is the top level dispatcher. void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); - // Helper for delayed proccessing of attributes. + // Helper for delayed processing of attributes. void ProcessDeclAttributeDelayed(Decl *D, const AttributeList *AttrList); void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, bool IncludeCXX11Attributes = true); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index a724fa242268..b1a84e7ab943 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1915,7 +1915,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, } if (!TagOrTempResult.isInvalid()) - // Delayed proccessing of attributes. + // Delayed processing of attributes. Actions.ProcessDeclAttributeDelayed(TagOrTempResult.get(), attrs.getList()); const char *PrevSpec = nullptr; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index e8503427536d..1929bc539188 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -6571,7 +6571,7 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, } } -// Helper for delayed proccessing TransparentUnion attribute. +// Helper for delayed processing TransparentUnion attribute. void Sema::ProcessDeclAttributeDelayed(Decl *D, const AttributeList *AttrList) { for (const AttributeList *Attr = AttrList; Attr; Attr = Attr->getNext()) if (Attr->getKind() == AttributeList::AT_TransparentUnion) { From 6b7518998a97d230f76406e8ecf3d7a33cb23167 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 30 Jun 2017 06:03:47 +0000 Subject: [PATCH 143/214] Add -no-canonical-prefixes to the test line so that we can handle different build modes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306790 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Driver/openmp-offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index 8b7929ff3586..d43aa331c9dc 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -593,7 +593,7 @@ /// ########################################################################### /// Check -fopenmp-is-device is passed when compiling for the device. -// RUN: %clang -### -target powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \ +// RUN: %clang -### -no-canonical-prefixes -target powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s // CHK-FOPENMP-IS-DEVICE: clang{{.*}} "-aux-triple" "powerpc64le--linux" {{.*}}.c" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" From 09c135e20c7c80b7c738ddcbb7898bbb8b8ef363 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 30 Jun 2017 07:22:02 +0000 Subject: [PATCH 144/214] Fold exception-warnings.cpp into warn-throw-out-noexcept-func.cpp I had failed to notice the latter existed when I recently introduced the former. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306799 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/SemaCXX/exception-warnings.cpp | 36 ------------------ test/SemaCXX/warn-throw-out-noexcept-func.cpp | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 36 deletions(-) delete mode 100644 test/SemaCXX/exception-warnings.cpp diff --git a/test/SemaCXX/exception-warnings.cpp b/test/SemaCXX/exception-warnings.cpp deleted file mode 100644 index f6c646e5a40e..000000000000 --- a/test/SemaCXX/exception-warnings.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s - -struct B {}; -struct D: B {}; -void goodPlain() throw () { - try { - throw D(); - } catch (B) {} -} -void goodReference() throw () { - try { - throw D(); - } catch (B &) {} -} -void goodPointer() throw () { - D d; - try { - throw &d; - } catch (B *) {} -} -void badPlain() throw () { // expected-note {{non-throwing function declare here}} - try { - throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} - } catch (D) {} -} -void badReference() throw () { // expected-note {{non-throwing function declare here}} - try { - throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} - } catch (D &) {} -} -void badPointer() throw () { // expected-note {{non-throwing function declare here}} - B b; - try { - throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} - } catch (D *) {} -} diff --git a/test/SemaCXX/warn-throw-out-noexcept-func.cpp b/test/SemaCXX/warn-throw-out-noexcept-func.cpp index dfd1ff9065ab..fc2919a1e327 100644 --- a/test/SemaCXX/warn-throw-out-noexcept-func.cpp +++ b/test/SemaCXX/warn-throw-out-noexcept-func.cpp @@ -253,6 +253,43 @@ void with_try_block1() noexcept try { //expected-note {{non-throwing function de } catch (char *) { } +namespace derived { +struct B {}; +struct D: B {}; +void goodPlain() noexcept { + try { + throw D(); + } catch (B) {} +} +void goodReference() noexcept { + try { + throw D(); + } catch (B &) {} +} +void goodPointer() noexcept { + D d; + try { + throw &d; + } catch (B *) {} +} +void badPlain() noexcept { // expected-note {{non-throwing function declare here}} + try { + throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D) {} +} +void badReference() noexcept { // expected-note {{non-throwing function declare here}} + try { + throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D &) {} +} +void badPointer() noexcept { // expected-note {{non-throwing function declare here}} + B b; + try { + throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}} + } catch (D *) {} +} +} + int main() { R1_ShouldDiag o; //expected-note {{in instantiation of member function}} S1_ShouldDiag b; //expected-note {{in instantiation of member function}} From 26f8a8d2c4bf101bb98ff55893198f712a60a336 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 30 Jun 2017 08:02:37 +0000 Subject: [PATCH 145/214] Fix heap use after free introduced by r306769. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306804 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Clang.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index a3e7e9cdf59a..342d628396da 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -1319,7 +1319,7 @@ void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args, if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) ABIName = A->getValue(); else { - StringRef CPU = getCPUName(Args, Triple, /*FromAs*/ false); + std::string CPU = getCPUName(Args, Triple, /*FromAs*/ false); ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data(); } From 6853ca9a40411fc4997749ee9c2d96059f35c1a7 Mon Sep 17 00:00:00 2001 From: Sjoerd Meijer Date: Fri, 30 Jun 2017 08:07:34 +0000 Subject: [PATCH 146/214] ARMV8-A archkind and target defines helper functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This introduces helper functions that set target defines for different ARMV8-A architecture kinds. It fixes an issue that the v8.1 define ARM_FEATURE_QRDMX was not set for v8.2. These helper functions make things more “scalable” if we want to add ARMv8.3 at some point, and a cleanup has been done to hold the architecture kind in one variable (instead of one for each). Differential Revision: https://reviews.llvm.org/D34686 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306805 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 59 ++++++++++++++++----- test/Preprocessor/aarch64-target-features.c | 5 +- test/Preprocessor/arm-target-features.c | 1 + 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 840cb1228b65..e1d1bf3ad176 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -5615,6 +5615,17 @@ class ARMTargetInfo : public TargetInfo { bool setFPMath(StringRef Name) override; + void getTargetDefinesARMV81A(const LangOptions &Opts, + MacroBuilder &Builder) const { + Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); + } + + void getTargetDefinesARMV82A(const LangOptions &Opts, + MacroBuilder &Builder) const { + // Also include the ARMv8.1-A defines + getTargetDefinesARMV81A(Opts, Builder); + } + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { // Target identification. @@ -5813,8 +5824,15 @@ class ARMTargetInfo : public TargetInfo { if (Opts.UnsafeFPMath) Builder.defineMacro("__ARM_FP_FAST", "1"); - if (ArchKind == llvm::ARM::AK_ARMV8_1A) - Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); + switch(ArchKind) { + default: break; + case llvm::ARM::AK_ARMV8_1A: + getTargetDefinesARMV81A(Opts, Builder); + break; + case llvm::ARM::AK_ARMV8_2A: + getTargetDefinesARMV82A(Opts, Builder); + break; + } } ArrayRef getTargetBuiltins() const override { @@ -6207,9 +6225,8 @@ class AArch64TargetInfo : public TargetInfo { unsigned CRC; unsigned Crypto; unsigned Unaligned; - unsigned V8_1A; - unsigned V8_2A; unsigned HasFullFP16; + llvm::AArch64::ArchKind ArchKind; static const Builtin::Info BuiltinInfo[]; @@ -6275,6 +6292,20 @@ class AArch64TargetInfo : public TargetInfo { static_cast(llvm::AArch64::ArchKind::AK_INVALID); } + void getTargetDefinesARMV81A(const LangOptions &Opts, + MacroBuilder &Builder) const { + Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); + } + + void getTargetDefinesARMV82A(const LangOptions &Opts, + MacroBuilder &Builder) const { + // Also include the ARMv8.1 defines + getTargetDefinesARMV81A(Opts, Builder); + + if (FPU == NeonMode && HasFullFP16) + Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1"); + } + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { // Target identification. @@ -6339,10 +6370,15 @@ class AArch64TargetInfo : public TargetInfo { if (Unaligned) Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1"); - if (V8_1A) - Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); - if (V8_2A && FPU == NeonMode && HasFullFP16) - Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1"); + switch(ArchKind) { + default: break; + case llvm::AArch64::ArchKind::AK_ARMV8_1A: + getTargetDefinesARMV81A(Opts, Builder); + break; + case llvm::AArch64::ArchKind::AK_ARMV8_2A: + getTargetDefinesARMV82A(Opts, Builder); + break; + } // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8) builtins work. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"); @@ -6369,9 +6405,8 @@ class AArch64TargetInfo : public TargetInfo { CRC = 0; Crypto = 0; Unaligned = 1; - V8_1A = 0; - V8_2A = 0; HasFullFP16 = 0; + ArchKind = llvm::AArch64::ArchKind::AK_ARMV8A; for (const auto &Feature : Features) { if (Feature == "+neon") @@ -6383,9 +6418,9 @@ class AArch64TargetInfo : public TargetInfo { if (Feature == "+strict-align") Unaligned = 0; if (Feature == "+v8.1a") - V8_1A = 1; + ArchKind = llvm::AArch64::ArchKind::AK_ARMV8_1A; if (Feature == "+v8.2a") - V8_2A = 1; + ArchKind = llvm::AArch64::ArchKind::AK_ARMV8_2A; if (Feature == "+fullfp16") HasFullFP16 = 1; } diff --git a/test/Preprocessor/aarch64-target-features.c b/test/Preprocessor/aarch64-target-features.c index 43a050b14c06..721246aff3a7 100644 --- a/test/Preprocessor/aarch64-target-features.c +++ b/test/Preprocessor/aarch64-target-features.c @@ -71,8 +71,9 @@ // CHECK-NEON: __ARM_NEON 1 // CHECK-NEON: __ARM_NEON_FP 0xE -// RUN: %clang -target aarch64-none-eabi -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-V81A %s -// CHECK-V81A: __ARM_FEATURE_QRDMX 1 +// RUN: %clang -target aarch64-none-eabi -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-QRDMX %s +// RUN: %clang -target aarch64-none-eabi -march=armv8.2-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-QRDMX %s +// CHECK-QRDMX: __ARM_FEATURE_QRDMX 1 // RUN: %clang -target aarch64 -march=arm64 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-ARCH-NOT-ACCEPT %s // RUN: %clang -target aarch64 -march=aarch64 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-ARCH-NOT-ACCEPT %s diff --git a/test/Preprocessor/arm-target-features.c b/test/Preprocessor/arm-target-features.c index 81dab475fc9d..b206e1cf36fd 100644 --- a/test/Preprocessor/arm-target-features.c +++ b/test/Preprocessor/arm-target-features.c @@ -441,4 +441,5 @@ // CHECK-V82A: #define __ARM_ARCH 8 // CHECK-V82A: #define __ARM_ARCH_8_2A__ 1 // CHECK-V82A: #define __ARM_ARCH_PROFILE 'A' +// CHECK-V82A: #define __ARM_FEATURE_QRDMX 1 // CHECK-V82A: #define __ARM_FP 0xE From 0c223be753a86df1bef5ace82e5a3e11020c026c Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 30 Jun 2017 09:25:43 +0000 Subject: [PATCH 147/214] Ambiguity might be also uninitialized. Use llvm::Optional. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306809 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Lookup.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index 145355c5ec3d..fc16ad2e819e 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -18,6 +18,8 @@ #include "clang/AST/DeclCXX.h" #include "clang/Sema/Sema.h" +#include "llvm/ADT/Optional.h" + namespace clang { /// @brief Represents the results of name lookup. @@ -465,9 +467,10 @@ class LookupResult { Paths = nullptr; } } else { - AmbiguityKind SavedAK = Ambiguity; + llvm::Optional SavedAK; bool WasAmbiguous = false; if (ResultKind == Ambiguous) { + SavedAK = Ambiguity; WasAmbiguous = true; } ResultKind = Found; @@ -478,7 +481,7 @@ class LookupResult { if (ResultKind == Ambiguous) { (void)WasAmbiguous; assert(WasAmbiguous); - Ambiguity = SavedAK; + Ambiguity = SavedAK.getValue(); } else if (Paths) { deletePaths(Paths); Paths = nullptr; From f5f1f63df1b65b19c63a06ff10921f08ce043a81 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 30 Jun 2017 13:21:27 +0000 Subject: [PATCH 148/214] [Driver] Actually report errors during parsing instead of stopping when there's an error somewhere. This is a more principled version of r303756. That change was both very brittle about the state of the Diags object going into the driver and also broke tooling in funny ways. In particular it prevented tools from capturing diagnostics properly and made the compilation database logic fail to provide arguments to the tool, falling back to scanning directories for JSON files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306822 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Compilation.h | 8 +++++- include/clang/Driver/Driver.h | 3 ++- lib/Driver/Compilation.cpp | 5 ++-- lib/Driver/Driver.cpp | 42 +++++++++++++++++++++--------- tools/driver/driver.cpp | 2 +- unittests/Driver/ToolChainTest.cpp | 11 ++++++++ 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h index 114e0b33c75a..036b04605ac7 100644 --- a/include/clang/Driver/Compilation.h +++ b/include/clang/Driver/Compilation.h @@ -105,10 +105,13 @@ class Compilation { /// Whether we're compiling for diagnostic purposes. bool ForDiagnostics; + /// Whether an error during the parsing of the input args. + bool ContainsError; + public: Compilation(const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, - llvm::opt::DerivedArgList *TranslatedArgs); + llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError); ~Compilation(); const Driver &getDriver() const { return TheDriver; } @@ -275,6 +278,9 @@ class Compilation { /// Return true if we're compiling for diagnostics. bool isForDiagnostics() const { return ForDiagnostics; } + /// Return whether an error during the parsing of the input args. + bool containsError() const { return ContainsError; } + /// Redirect - Redirect output of this compilation. Can only be done once. /// /// \param Redirects - array of pointers to paths. The array diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 1009754a15d5..5a087eea1b4e 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -341,7 +341,8 @@ class Driver { /// ParseArgStrings - Parse the given list of strings into an /// ArgList. - llvm::opt::InputArgList ParseArgStrings(ArrayRef Args); + llvm::opt::InputArgList ParseArgStrings(ArrayRef Args, + bool &ContainsError); /// BuildInputs - Construct the list of inputs and their types from /// the given arguments. diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 5c13e59a0d73..cf86644fb8cd 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -23,10 +23,11 @@ using namespace clang; using namespace llvm::opt; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, - InputArgList *_Args, DerivedArgList *_TranslatedArgs) + InputArgList *_Args, DerivedArgList *_TranslatedArgs, + bool ContainsError) : TheDriver(D), DefaultToolChain(_DefaultToolChain), ActiveOffloadMask(0u), Args(_Args), TranslatedArgs(_TranslatedArgs), Redirects(nullptr), - ForDiagnostics(false) { + ForDiagnostics(false), ContainsError(ContainsError) { // The offloading host toolchain is the default tool chain. OrderedOffloadingToolchains.insert( std::make_pair(Action::OFK_Host, &DefaultToolChain)); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index f23975829eaf..faced0697ed9 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -153,8 +153,10 @@ void Driver::setDriverModeFromOption(StringRef Opt) { Diag(diag::err_drv_unsupported_option_argument) << OptName << Value; } -InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings) { +InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings, + bool &ContainsError) { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); + ContainsError = false; unsigned IncludedFlagsBitmask; unsigned ExcludedFlagsBitmask; @@ -167,27 +169,41 @@ InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings) { IncludedFlagsBitmask, ExcludedFlagsBitmask); // Check for missing argument error. - if (MissingArgCount) - Diag(clang::diag::err_drv_missing_argument) + if (MissingArgCount) { + Diag(diag::err_drv_missing_argument) << Args.getArgString(MissingArgIndex) << MissingArgCount; + ContainsError |= + Diags.getDiagnosticLevel(diag::err_drv_missing_argument, + SourceLocation()) > DiagnosticsEngine::Warning; + } // Check for unsupported options. for (const Arg *A : Args) { if (A->getOption().hasFlag(options::Unsupported)) { - Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(Args); + Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); + ContainsError |= Diags.getDiagnosticLevel(diag::err_drv_unsupported_opt, + SourceLocation()) > + DiagnosticsEngine::Warning; continue; } // Warn about -mcpu= without an argument. if (A->getOption().matches(options::OPT_mcpu_EQ) && A->containsValue("")) { - Diag(clang::diag::warn_drv_empty_joined_argument) << A->getAsString(Args); + Diag(diag::warn_drv_empty_joined_argument) << A->getAsString(Args); + ContainsError |= Diags.getDiagnosticLevel( + diag::warn_drv_empty_joined_argument, + SourceLocation()) > DiagnosticsEngine::Warning; } } - for (const Arg *A : Args.filtered(options::OPT_UNKNOWN)) - Diags.Report(IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl : - diag::err_drv_unknown_argument) - << A->getAsString(Args); + for (const Arg *A : Args.filtered(options::OPT_UNKNOWN)) { + auto ID = IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl + : diag::err_drv_unknown_argument; + + Diags.Report(ID) << A->getAsString(Args); + ContainsError |= Diags.getDiagnosticLevel(ID, SourceLocation()) > + DiagnosticsEngine::Warning; + } return Args; } @@ -600,9 +616,8 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // FIXME: This stuff needs to go into the Compilation, not the driver. bool CCCPrintPhases; - InputArgList Args = ParseArgStrings(ArgList.slice(1)); - if (Diags.hasErrorOccurred()) - return nullptr; + bool ContainsError; + InputArgList Args = ParseArgStrings(ArgList.slice(1), ContainsError); // Silence driver warnings if requested Diags.setIgnoreAllWarnings(Args.hasArg(options::OPT_w)); @@ -692,7 +707,8 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { *UArgs, computeTargetTriple(*this, DefaultTargetTriple, *UArgs)); // The compilation takes ownership of Args. - Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs); + Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs, + ContainsError); if (!HandleImmediateArgs(*C)) return C; diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index af25d9598021..9f37c428ff93 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -462,7 +462,7 @@ int main(int argc_, const char **argv_) { std::unique_ptr C(TheDriver.BuildCompilation(argv)); int Res = 1; - if (C.get()) { + if (C && !C->containsError()) { SmallVector, 4> FailingCommands; Res = TheDriver.ExecuteCompilation(*C, FailingCommands); diff --git a/unittests/Driver/ToolChainTest.cpp b/unittests/Driver/ToolChainTest.cpp index bce2748aa21b..ec50560b202b 100644 --- a/unittests/Driver/ToolChainTest.cpp +++ b/unittests/Driver/ToolChainTest.cpp @@ -152,5 +152,16 @@ TEST(ToolChainTest, DefaultDriverMode) { EXPECT_TRUE(CXXDriver.CCCIsCXX()); EXPECT_TRUE(CLDriver.IsCLMode()); } +TEST(ToolChainTest, InvalidArgument) { + IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags); + std::unique_ptr C(TheDriver.BuildCompilation( + {"-fsyntax-only", "-fan-unknown-option", "foo.cpp"})); + EXPECT_TRUE(C); + EXPECT_TRUE(C->containsError()); +} } // end anonymous namespace. From 21a927f1c4bc27b97558d3d0554b056a283d631f Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Fri, 30 Jun 2017 13:50:13 +0000 Subject: [PATCH 149/214] [OPENMP] Initial support for taskloop reductions. Add sema/parsupping ort for taskloop [simd] reductions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306825 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/OpenMPKinds.def | 2 ++ test/OpenMP/taskloop_ast_print.cpp | 16 ++++++++-------- test/OpenMP/taskloop_simd_ast_print.cpp | 16 ++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index 74ec26f19ac2..aae1c3a9b8c5 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -552,6 +552,7 @@ OPENMP_TASKLOOP_CLAUSE(priority) OPENMP_TASKLOOP_CLAUSE(grainsize) OPENMP_TASKLOOP_CLAUSE(nogroup) OPENMP_TASKLOOP_CLAUSE(num_tasks) +OPENMP_TASKLOOP_CLAUSE(reduction) // Clauses allowed for OpenMP directive 'taskloop simd'. OPENMP_TASKLOOP_SIMD_CLAUSE(if) @@ -572,6 +573,7 @@ OPENMP_TASKLOOP_SIMD_CLAUSE(simdlen) OPENMP_TASKLOOP_SIMD_CLAUSE(grainsize) OPENMP_TASKLOOP_SIMD_CLAUSE(nogroup) OPENMP_TASKLOOP_SIMD_CLAUSE(num_tasks) +OPENMP_TASKLOOP_SIMD_CLAUSE(reduction) // Clauses allowed for OpenMP directive 'critical'. OPENMP_CRITICAL_CLAUSE(hint) diff --git a/test/OpenMP/taskloop_ast_print.cpp b/test/OpenMP/taskloop_ast_print.cpp index d2fae3fe0f4f..36f90c95dd33 100644 --- a/test/OpenMP/taskloop_ast_print.cpp +++ b/test/OpenMP/taskloop_ast_print.cpp @@ -13,14 +13,14 @@ T tmain(T argc) { T b = argc, c, d, e, f, g; static T a; // CHECK: static T a; -#pragma omp taskloop if(taskloop: argc > N) default(shared) untied priority(N) grainsize(N) - // CHECK-NEXT: #pragma omp taskloop if(taskloop: argc > N) default(shared) untied priority(N) grainsize(N) +#pragma omp taskloop if(taskloop: argc > N) default(shared) untied priority(N) grainsize(N) reduction(+:g) + // CHECK-NEXT: #pragma omp taskloop if(taskloop: argc > N) default(shared) untied priority(N) grainsize(N) reduction(+: g) for (int i = 0; i < 2; ++i) a = 2; // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp taskloop private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) nogroup num_tasks(N) +#pragma omp taskloop private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) nogroup num_tasks(N) reduction(min:a) for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) for (int j = 0; j < 2; ++j) @@ -33,7 +33,7 @@ T tmain(T argc) { for (int j = 0; j < 2; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) nogroup num_tasks(N) + // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) nogroup num_tasks(N) reduction(min: a) // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: for (int j = 0; j < 2; ++j) // CHECK-NEXT: for (int j = 0; j < 2; ++j) @@ -53,19 +53,19 @@ int main(int argc, char **argv) { int b = argc, c, d, e, f, g; static int a; // CHECK: static int a; -#pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc) - // CHECK-NEXT: #pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc) +#pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc) reduction(*: g) + // CHECK-NEXT: #pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc) reduction(*: g) for (int i = 0; i < 2; ++i) a = 2; // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp taskloop private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) shared(g) if(argc) mergeable priority(argc) grainsize(argc) +#pragma omp taskloop private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) shared(g) if(argc) mergeable priority(argc) grainsize(argc) reduction(max: a, e) for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable priority(argc) grainsize(argc) + // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable priority(argc) grainsize(argc) reduction(max: a,e) // CHECK-NEXT: for (int i = 0; i < 10; ++i) // CHECK-NEXT: for (int j = 0; j < 10; ++j) // CHECK-NEXT: foo(); diff --git a/test/OpenMP/taskloop_simd_ast_print.cpp b/test/OpenMP/taskloop_simd_ast_print.cpp index f16b470a3012..9bee8f7f93fd 100644 --- a/test/OpenMP/taskloop_simd_ast_print.cpp +++ b/test/OpenMP/taskloop_simd_ast_print.cpp @@ -14,14 +14,14 @@ T tmain(T argc) { T *ptr; static T a; // CHECK: static T a; -#pragma omp taskloop simd if(taskloop: argc > N) default(shared) untied priority(N) safelen(N) linear(c) aligned(ptr) grainsize(N) - // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: argc > N) default(shared) untied priority(N) safelen(N) linear(c) aligned(ptr) grainsize(N) +#pragma omp taskloop simd if(taskloop: argc > N) default(shared) untied priority(N) safelen(N) linear(c) aligned(ptr) grainsize(N) reduction(+:g) + // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: argc > N) default(shared) untied priority(N) safelen(N) linear(c) aligned(ptr) grainsize(N) reduction(+: g) for (int i = 0; i < 2; ++i) a = 2; // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp taskloop simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N) +#pragma omp taskloop simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N) reduction(min:a) for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) for (int j = 0; j < 2; ++j) @@ -34,7 +34,7 @@ T tmain(T argc) { for (int j = 0; j < 2; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N) + // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N) reduction(min: a) // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: for (int j = 0; j < 2; ++j) // CHECK-NEXT: for (int j = 0; j < 2; ++j) @@ -54,19 +54,19 @@ int main(int argc, char **argv) { int b = argc, c, d, e, f, g; static int a; // CHECK: static int a; -#pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b), aligned(argv) nogroup num_tasks(argc) - // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b) aligned(argv) nogroup num_tasks(argc) +#pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b), aligned(argv) nogroup num_tasks(argc) reduction(*: g) + // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b) aligned(argv) nogroup num_tasks(argc) reduction(*: g) for (int i = 0; i < 2; ++i) a = 2; // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp taskloop simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) shared(g) if(argc) mergeable priority(argc) simdlen(16) grainsize(argc) +#pragma omp taskloop simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) shared(g) if(argc) mergeable priority(argc) simdlen(16) grainsize(argc) reduction(max: a, e) for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable priority(argc) simdlen(16) grainsize(argc) + // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable priority(argc) simdlen(16) grainsize(argc) reduction(max: a,e) // CHECK-NEXT: for (int i = 0; i < 10; ++i) // CHECK-NEXT: for (int j = 0; j < 10; ++j) // CHECK-NEXT: foo(); From a3da1d20798d3a689172a61ab667b61d805fca73 Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Fri, 30 Jun 2017 14:23:01 +0000 Subject: [PATCH 150/214] [OpenCL] Add function name to extension diagnostic Slightly improve the diagnostic by including the function name. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306827 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- include/clang/Sema/Sema.h | 2 +- lib/Sema/Sema.cpp | 5 +++-- test/SemaOpenCL/extension-begin.cl | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 7b1671bb8777..136e48ab5e54 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -8410,7 +8410,7 @@ def warn_opencl_attr_deprecated_ignored : Warning < def err_opencl_variadic_function : Error< "invalid prototype, variadic arguments are not allowed in OpenCL">; def err_opencl_requires_extension : Error< - "use of %select{type |declaration}0%1 requires %2 extension to be enabled">; + "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">; // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions def err_opencl_builtin_pipe_first_arg : Error< diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 8dee74eb2a12..75ff5fdb37a1 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -8432,7 +8432,7 @@ class Sema { /// is disabled due to required OpenCL extensions being disabled. If so, /// emit diagnostics. /// \return true if type is disabled. - bool checkOpenCLDisabledDecl(const Decl &D, const Expr &E); + bool checkOpenCLDisabledDecl(const NamedDecl &D, const Expr &E); //===--------------------------------------------------------------------===// // OpenMP directives and clauses. diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 007a5e483e6c..34f5e26be810 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -1688,7 +1688,8 @@ bool Sema::checkOpenCLDisabledTypeDeclSpec(const DeclSpec &DS, QualType QT) { QT, OpenCLTypeExtMap); } -bool Sema::checkOpenCLDisabledDecl(const Decl &D, const Expr &E) { - return checkOpenCLDisabledTypeOrDecl(&D, E.getLocStart(), "", +bool Sema::checkOpenCLDisabledDecl(const NamedDecl &D, const Expr &E) { + IdentifierInfo *FnName = D.getIdentifier(); + return checkOpenCLDisabledTypeOrDecl(&D, E.getLocStart(), FnName, OpenCLDeclExtMap, 1, D.getSourceRange()); } diff --git a/test/SemaOpenCL/extension-begin.cl b/test/SemaOpenCL/extension-begin.cl index 3393458a893a..92ea88143233 100644 --- a/test/SemaOpenCL/extension-begin.cl +++ b/test/SemaOpenCL/extension-begin.cl @@ -46,7 +46,7 @@ void test_f2(void) { const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext extension to be enabled}} TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 'struct A') requires my_ext extension to be enabled}} PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const struct A *') requires my_ext extension to be enabled}} - f(); // expected-error {{use of declaration requires my_ext extension to be enabled}} + f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}} g(0); // expected-error {{no matching function for call to 'g'}} // expected-note@-26 {{candidate disabled due to OpenCL extension}} // expected-note@-22 {{candidate function not viable: requires 0 arguments, but 1 was provided}} From 0375288466e510a35fda999e37053ab13a79ea89 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 30 Jun 2017 15:15:38 +0000 Subject: [PATCH 151/214] Driver: honor -nostdinc and -isystem-after on CrossWindows This changes CrossWindows to look for -nostdinc instead of -nostdlibinc. In addition, fixes a bug where -isystem-after options would be dropped when called with -nostdinc. Patch by Dave Lee! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306829 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/CrossWindows.cpp | 14 ++++++++++---- test/Driver/windows-cross.c | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Driver/ToolChains/CrossWindows.cpp b/lib/Driver/ToolChains/CrossWindows.cpp index d290c62a056a..7d0c438b1360 100644 --- a/lib/Driver/ToolChains/CrossWindows.cpp +++ b/lib/Driver/ToolChains/CrossWindows.cpp @@ -238,8 +238,15 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, const Driver &D = getDriver(); const std::string &SysRoot = D.SysRoot; - if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + auto AddSystemAfterIncludes = [&]() { + for (const auto &P : DriverArgs.getAllArgValues(options::OPT_isystem_after)) + addSystemInclude(DriverArgs, CC1Args, P); + }; + + if (DriverArgs.hasArg(options::OPT_nostdinc)) { + AddSystemAfterIncludes(); return; + } addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { @@ -247,8 +254,7 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::sys::path::append(ResourceDir, "include"); addSystemInclude(DriverArgs, CC1Args, ResourceDir); } - for (const auto &P : DriverArgs.getAllArgValues(options::OPT_isystem_after)) - addSystemInclude(DriverArgs, CC1Args, P); + AddSystemAfterIncludes(); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); } @@ -258,7 +264,7 @@ AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, const llvm::Triple &Triple = getTriple(); const std::string &SysRoot = getDriver().SysRoot; - if (DriverArgs.hasArg(options::OPT_nostdlibinc) || + if (DriverArgs.hasArg(options::OPT_nostdinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; diff --git a/test/Driver/windows-cross.c b/test/Driver/windows-cross.c index 90fefbadfea1..0e688f0a26e7 100644 --- a/test/Driver/windows-cross.c +++ b/test/Driver/windows-cross.c @@ -80,3 +80,8 @@ // CHECK-ISYSTEM-AFTER: "-internal-isystem" "Windows Kits{{[/\\]}}10{{[/\\]}}Include{{[/\\]}}10.0.10586.0{{[/\\]}}um" // CHECK-ISYSTEM-AFTER: "-internal-isystem" "Windows Kits{{[/\\]}}10{{[/\\]}}Include{{[/\\]}}10.0.10586.0{{[/\\]}}shared" +// RUN: %clang -### -target armv7-windows-itanium -nostdinc -isystem-after "Windows Kits/10/Include/10.0.10586.0/ucrt" -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-NOSTDINC-ISYSTEM-AFTER +// CHECK-NOSTDINC-ISYSTEM-AFTER: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-NOSTDINC-ISYSTEM-AFTER-NOT: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include" +// CHECK-NOSTDINC-ISYSTEM-AFTER: "-internal-isystem" "Windows Kits{{[/\\]}}10{{[/\\]}}Include{{[/\\]}}10.0.10586.0{{[/\\]}}ucrt" From fa96f87e3390e366aa23e8be3e0fe78370fb0db9 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 30 Jun 2017 15:15:39 +0000 Subject: [PATCH 152/214] Driver: fix option declaration The option is a "joined" argument. Fix silly copy-paste error. This allows the parsing to work at runtime. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306830 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 5f3ce5e95fee..205f36b723c8 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -145,7 +145,7 @@ def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">, HelpText<"The string to embed in the Dwarf debug flags record.">; def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">, HelpText<"DWARF debug sections compression">; -def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">, +def compress_debug_sections_EQ : Joined<["-"], "compress-debug-sections=">, HelpText<"DWARF debug sections compression type">; def mno_exec_stack : Flag<["-"], "mnoexecstack">, HelpText<"Mark the file as not needing an executable stack">; From 813f275eefb9ba53f20d56badfde964016f16341 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 30 Jun 2017 16:11:49 +0000 Subject: [PATCH 153/214] Revert "[CodeGen] Propagate dllexport to thunks" This reverts r306770, it causes LNK4102 warnings in MSVC builds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306835 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 4 ---- test/CodeGenCXX/windows-itanium-dllexport.cpp | 9 --------- 2 files changed, 13 deletions(-) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 7c9f07d32d87..64b6d0d3fe9f 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -64,10 +64,6 @@ static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, const CXXMethodDecl *MD = cast(GD.getDecl()); setThunkVisibility(CGM, MD, Thunk, ThunkFn); - // Propagate dllexport storage. - if (MD->hasAttr()) - ThunkFn->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); - if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker()) ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName())); } diff --git a/test/CodeGenCXX/windows-itanium-dllexport.cpp b/test/CodeGenCXX/windows-itanium-dllexport.cpp index ffb8f610f5c3..ff780c777822 100644 --- a/test/CodeGenCXX/windows-itanium-dllexport.cpp +++ b/test/CodeGenCXX/windows-itanium-dllexport.cpp @@ -53,12 +53,3 @@ USEMEMFUNC(outer::inner, f) // CHECK: declare dllimport {{.*}} @_ZN5outerIcE1fEv // CHECK: define {{.*}} @_ZN5outerIcE5inner1fEv - -struct base { - virtual ~base(); -}; -struct __declspec(dllexport) derived : public virtual base { - virtual ~derived() {} -}; - -// CHECK: define {{.*}} dllexport {{.*}} @_ZTv0_n12_N7derivedD0Ev From 75ec5aa40177caeb6531afab8c0757183dddc101 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 30 Jun 2017 16:12:14 +0000 Subject: [PATCH 154/214] [MS] Test that deleting destructor thunks are not exported The MSVC linker emits the LNK4102 warning if they are. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306836 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGenCXX/dllexport-dtor-thunks.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/CodeGenCXX/dllexport-dtor-thunks.cpp diff --git a/test/CodeGenCXX/dllexport-dtor-thunks.cpp b/test/CodeGenCXX/dllexport-dtor-thunks.cpp new file mode 100644 index 000000000000..52f9901620fa --- /dev/null +++ b/test/CodeGenCXX/dllexport-dtor-thunks.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -mconstructor-aliases -fms-extensions %s -emit-llvm -o - -triple x86_64-windows-msvc | FileCheck %s + +struct __declspec(dllexport) A { virtual ~A(); }; +struct __declspec(dllexport) B { virtual ~B(); }; +struct __declspec(dllexport) C : A, B { virtual ~C(); }; +C::~C() {} + +// This thunk should *not* be dllexport. +// CHECK: define linkonce_odr i8* @"\01??_EC@@W7EAAPEAXI@Z" +// CHECK: define dllexport void @"\01??1C@@UEAA@XZ" From fc0baba7f6ae7a67b39c2375bfbbb7948a10b026 Mon Sep 17 00:00:00 2001 From: Kuba Mracek Date: Fri, 30 Jun 2017 16:28:15 +0000 Subject: [PATCH 155/214] [objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls [clang part] This fixes an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. When the result of a struct-returning call is ignored, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes a use-after-scope false positive with AddressSanitizer. Differential Revision: https://reviews.llvm.org/D34834 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306837 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 33 ++++++++++++++++++++---------- test/CodeGenObjC/stret-1.m | 11 +++++++++- test/CodeGenObjC/stret-lifetime.m | 34 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 test/CodeGenObjC/stret-lifetime.m diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 224d2d6606a2..98435fefbd2e 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -1678,7 +1678,10 @@ struct NullReturnState { /// Complete the null-return operation. It is valid to call this /// regardless of whether 'init' has been called. - RValue complete(CodeGenFunction &CGF, RValue result, QualType resultType, + RValue complete(CodeGenFunction &CGF, + ReturnValueSlot returnSlot, + RValue result, + QualType resultType, const CallArgList &CallArgs, const ObjCMethodDecl *Method) { // If we never had to do a null-check, just use the raw result. @@ -1745,7 +1748,8 @@ struct NullReturnState { // memory or (2) agg values in registers. if (result.isAggregate()) { assert(result.isAggregate() && "null init of non-aggregate result?"); - CGF.EmitNullInitialization(result.getAggregateAddress(), resultType); + if (!returnSlot.isUnused()) + CGF.EmitNullInitialization(result.getAggregateAddress(), resultType); if (contBB) CGF.EmitBlock(contBB); return result; } @@ -2117,11 +2121,11 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, } } - NullReturnState nullReturn; + bool RequiresNullCheck = false; llvm::Constant *Fn = nullptr; if (CGM.ReturnSlotInterferesWithArgs(MSI.CallInfo)) { - if (ReceiverCanBeNull) nullReturn.init(CGF, Arg0); + if (ReceiverCanBeNull) RequiresNullCheck = true; Fn = (ObjCABI == 2) ? ObjCTypes.getSendStretFn2(IsSuper) : ObjCTypes.getSendStretFn(IsSuper); } else if (CGM.ReturnTypeUsesFPRet(ResultType)) { @@ -2134,23 +2138,30 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, // arm64 uses objc_msgSend for stret methods and yet null receiver check // must be made for it. if (ReceiverCanBeNull && CGM.ReturnTypeUsesSRet(MSI.CallInfo)) - nullReturn.init(CGF, Arg0); + RequiresNullCheck = true; Fn = (ObjCABI == 2) ? ObjCTypes.getSendFn2(IsSuper) : ObjCTypes.getSendFn(IsSuper); } + // We don't need to emit a null check to zero out an indirect result if the + // result is ignored. + if (Return.isUnused()) + RequiresNullCheck = false; + // Emit a null-check if there's a consumed argument other than the receiver. - bool RequiresNullCheck = false; - if (ReceiverCanBeNull && CGM.getLangOpts().ObjCAutoRefCount && Method) { + if (!RequiresNullCheck && CGM.getLangOpts().ObjCAutoRefCount && Method) { for (const auto *ParamDecl : Method->parameters()) { if (ParamDecl->hasAttr()) { - if (!nullReturn.NullBB) - nullReturn.init(CGF, Arg0); RequiresNullCheck = true; break; } } } + + NullReturnState nullReturn; + if (RequiresNullCheck) { + nullReturn.init(CGF, Arg0); + } llvm::Instruction *CallSite; Fn = llvm::ConstantExpr::getBitCast(Fn, MSI.MessengerType); @@ -2164,7 +2175,7 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, llvm::CallSite(CallSite).setDoesNotReturn(); } - return nullReturn.complete(CGF, rvalue, ResultType, CallArgs, + return nullReturn.complete(CGF, Return, rvalue, ResultType, CallArgs, RequiresNullCheck ? Method : nullptr); } @@ -7073,7 +7084,7 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, CGCallee callee(CGCalleeInfo(), calleePtr); RValue result = CGF.EmitCall(MSI.CallInfo, callee, returnSlot, args); - return nullReturn.complete(CGF, result, resultType, formalArgs, + return nullReturn.complete(CGF, returnSlot, result, resultType, formalArgs, requiresnullCheck ? method : nullptr); } diff --git a/test/CodeGenObjC/stret-1.m b/test/CodeGenObjC/stret-1.m index a7bcdda48b14..2314d5a9ecf5 100644 --- a/test/CodeGenObjC/stret-1.m +++ b/test/CodeGenObjC/stret-1.m @@ -12,11 +12,20 @@ +(struct stret) method { return one; } int main(int argc, const char **argv) { - [(id)(argc&~255) method]; + struct stret s; + s = [(id)(argc&~255) method]; // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T0:%[^,]+]] // CHECK: [[T0P:%.*]] = bitcast %struct.stret* [[T0]] to i8* // CHECK: call void @llvm.memset.p0i8.i64(i8* [[T0P]], i8 0, i64 400, i32 4, i1 false) + s = [Test method]; + // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]] + // CHECK-NOT: call void @llvm.memset.p0i8.i64( + + [(id)(argc&~255) method]; + // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]] + // CHECK-NOT: call void @llvm.memset.p0i8.i64( + [Test method]; // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]] // CHECK-NOT: call void @llvm.memset.p0i8.i64( diff --git a/test/CodeGenObjC/stret-lifetime.m b/test/CodeGenObjC/stret-lifetime.m new file mode 100644 index 000000000000..d81ef34aeed4 --- /dev/null +++ b/test/CodeGenObjC/stret-lifetime.m @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -triple arm64-apple-darwin -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s +// RUN: %clang_cc1 -triple arm64-apple-darwin -fobjc-arc -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,ARC +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,ARC + +struct stret { int x[100]; }; +struct stret one = {{1}}; + +@interface Test ++(struct stret) method; ++(struct stret) methodConsuming:(id __attribute__((ns_consumed)))consumed; +@end + +void foo(id o, id p) { + [o method]; + // CHECK: @llvm.lifetime.start + // CHECK: call void bitcast {{.*}} @objc_msgSend + // CHECK: @llvm.lifetime.end + // CHECK-NOT: call void @llvm.memset + + [o methodConsuming:p]; + // ARC: [[T0:%.*]] = icmp eq i8* + // ARC: br i1 [[T0]] + + // CHECK: @llvm.lifetime.start + // CHECK: call void bitcast {{.*}} @objc_msgSend + // CHECK: @llvm.lifetime.end + // ARC: br label + + // ARC: call void @objc_release + // ARC: br label + + // CHECK-NOT: call void @llvm.memset +} From 4803aff743e866df42dd12fd37093bf2b4af42ac Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 30 Jun 2017 16:36:09 +0000 Subject: [PATCH 156/214] [refactor] Move clang-rename into the clang repository The core engine of clang-rename will be used for local and global renames in the new refactoring engine, as mentioned in http://lists.llvm.org/pipermail/cfe-dev/2017-June/054286.html. The clang-rename tool is still supported but might get deprecated in the future. Differential Revision: https://reviews.llvm.org/D34696 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306840 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Refactoring/Rename/RenamingAction.h | 70 ++ .../Tooling/Refactoring/Rename/USRFinder.h | 84 +++ .../Refactoring/Rename/USRFindingAction.h | 54 ++ .../Tooling/Refactoring/Rename/USRLocFinder.h | 49 ++ include/clang/module.modulemap | 3 +- lib/Tooling/Refactoring/CMakeLists.txt | 8 + .../Refactoring/Rename/RenamingAction.cpp | 134 ++++ lib/Tooling/Refactoring/Rename/USRFinder.cpp | 213 ++++++ .../Refactoring/Rename/USRFindingAction.cpp | 236 ++++++ .../Refactoring/Rename/USRLocFinder.cpp | 509 +++++++++++++ test/CMakeLists.txt | 1 + test/clang-rename/ClassAsTemplateArgument.cpp | 21 + test/clang-rename/ClassFindByName.cpp | 10 + test/clang-rename/ClassReplacements.cpp | 11 + test/clang-rename/ClassSimpleRenaming.cpp | 14 + test/clang-rename/ClassTestMulti.cpp | 11 + test/clang-rename/ClassTestMultiByName.cpp | 8 + test/clang-rename/ComplexFunctionOverride.cpp | 47 ++ test/clang-rename/ComplicatedClassType.cpp | 63 ++ test/clang-rename/Ctor.cpp | 14 + test/clang-rename/CtorInitializer.cpp | 17 + test/clang-rename/DeclRefExpr.cpp | 24 + test/clang-rename/Field.cpp | 15 + test/clang-rename/FunctionMacro.cpp | 20 + test/clang-rename/FunctionOverride.cpp | 13 + .../FunctionWithClassFindByName.cpp | 12 + test/clang-rename/IncludeHeaderWithSymbol.cpp | 10 + test/clang-rename/Inputs/HeaderWithSymbol.h | 1 + test/clang-rename/Inputs/OffsetToNewName.yaml | 6 + .../Inputs/QualifiedNameToNewName.yaml | 6 + test/clang-rename/InvalidNewName.cpp | 2 + test/clang-rename/InvalidOffset.cpp | 9 + test/clang-rename/InvalidQualifiedName.cpp | 4 + test/clang-rename/MemberExprMacro.cpp | 22 + test/clang-rename/Namespace.cpp | 13 + test/clang-rename/NoNewName.cpp | 4 + .../TemplateClassInstantiation.cpp | 42 ++ test/clang-rename/TemplateTypename.cpp | 24 + test/clang-rename/TemplatedClassFunction.cpp | 22 + test/clang-rename/UserDefinedConversion.cpp | 26 + test/clang-rename/Variable.cpp | 33 + test/clang-rename/VariableMacro.cpp | 21 + test/clang-rename/YAMLInput.cpp | 10 + tools/CMakeLists.txt | 2 + tools/clang-rename/CMakeLists.txt | 19 + tools/clang-rename/ClangRename.cpp | 240 ++++++ tools/clang-rename/clang-rename.el | 79 ++ tools/clang-rename/clang-rename.py | 61 ++ unittests/CMakeLists.txt | 1 + unittests/Rename/CMakeLists.txt | 22 + unittests/Rename/ClangRenameTest.h | 112 +++ unittests/Rename/RenameClassTest.cpp | 684 ++++++++++++++++++ 52 files changed, 3135 insertions(+), 1 deletion(-) create mode 100644 include/clang/Tooling/Refactoring/Rename/RenamingAction.h create mode 100644 include/clang/Tooling/Refactoring/Rename/USRFinder.h create mode 100644 include/clang/Tooling/Refactoring/Rename/USRFindingAction.h create mode 100644 include/clang/Tooling/Refactoring/Rename/USRLocFinder.h create mode 100644 lib/Tooling/Refactoring/Rename/RenamingAction.cpp create mode 100644 lib/Tooling/Refactoring/Rename/USRFinder.cpp create mode 100644 lib/Tooling/Refactoring/Rename/USRFindingAction.cpp create mode 100644 lib/Tooling/Refactoring/Rename/USRLocFinder.cpp create mode 100644 test/clang-rename/ClassAsTemplateArgument.cpp create mode 100644 test/clang-rename/ClassFindByName.cpp create mode 100644 test/clang-rename/ClassReplacements.cpp create mode 100644 test/clang-rename/ClassSimpleRenaming.cpp create mode 100644 test/clang-rename/ClassTestMulti.cpp create mode 100644 test/clang-rename/ClassTestMultiByName.cpp create mode 100644 test/clang-rename/ComplexFunctionOverride.cpp create mode 100644 test/clang-rename/ComplicatedClassType.cpp create mode 100644 test/clang-rename/Ctor.cpp create mode 100644 test/clang-rename/CtorInitializer.cpp create mode 100644 test/clang-rename/DeclRefExpr.cpp create mode 100644 test/clang-rename/Field.cpp create mode 100644 test/clang-rename/FunctionMacro.cpp create mode 100644 test/clang-rename/FunctionOverride.cpp create mode 100644 test/clang-rename/FunctionWithClassFindByName.cpp create mode 100644 test/clang-rename/IncludeHeaderWithSymbol.cpp create mode 100644 test/clang-rename/Inputs/HeaderWithSymbol.h create mode 100644 test/clang-rename/Inputs/OffsetToNewName.yaml create mode 100644 test/clang-rename/Inputs/QualifiedNameToNewName.yaml create mode 100644 test/clang-rename/InvalidNewName.cpp create mode 100644 test/clang-rename/InvalidOffset.cpp create mode 100644 test/clang-rename/InvalidQualifiedName.cpp create mode 100644 test/clang-rename/MemberExprMacro.cpp create mode 100644 test/clang-rename/Namespace.cpp create mode 100644 test/clang-rename/NoNewName.cpp create mode 100644 test/clang-rename/TemplateClassInstantiation.cpp create mode 100644 test/clang-rename/TemplateTypename.cpp create mode 100644 test/clang-rename/TemplatedClassFunction.cpp create mode 100644 test/clang-rename/UserDefinedConversion.cpp create mode 100644 test/clang-rename/Variable.cpp create mode 100644 test/clang-rename/VariableMacro.cpp create mode 100644 test/clang-rename/YAMLInput.cpp create mode 100644 tools/clang-rename/CMakeLists.txt create mode 100644 tools/clang-rename/ClangRename.cpp create mode 100644 tools/clang-rename/clang-rename.el create mode 100644 tools/clang-rename/clang-rename.py create mode 100644 unittests/Rename/CMakeLists.txt create mode 100644 unittests/Rename/ClangRenameTest.h create mode 100644 unittests/Rename/RenameClassTest.cpp diff --git a/include/clang/Tooling/Refactoring/Rename/RenamingAction.h b/include/clang/Tooling/Refactoring/Rename/RenamingAction.h new file mode 100644 index 000000000000..099eaca6c42a --- /dev/null +++ b/include/clang/Tooling/Refactoring/Rename/RenamingAction.h @@ -0,0 +1,70 @@ +//===--- RenamingAction.h - Clang refactoring library ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provides an action to rename every symbol at a point. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H +#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H + +#include "clang/Tooling/Refactoring.h" + +namespace clang { +class ASTConsumer; +class CompilerInstance; + +namespace tooling { + +class RenamingAction { +public: + RenamingAction(const std::vector &NewNames, + const std::vector &PrevNames, + const std::vector> &USRList, + std::map &FileToReplaces, + bool PrintLocations = false) + : NewNames(NewNames), PrevNames(PrevNames), USRList(USRList), + FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {} + + std::unique_ptr newASTConsumer(); + +private: + const std::vector &NewNames, &PrevNames; + const std::vector> &USRList; + std::map &FileToReplaces; + bool PrintLocations; +}; + +/// Rename all symbols identified by the given USRs. +class QualifiedRenamingAction { +public: + QualifiedRenamingAction( + const std::vector &NewNames, + const std::vector> &USRList, + std::map &FileToReplaces) + : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {} + + std::unique_ptr newASTConsumer(); + +private: + /// New symbol names. + const std::vector &NewNames; + + /// A list of USRs. Each element represents USRs of a symbol being renamed. + const std::vector> &USRList; + + /// A file path to replacements map. + std::map &FileToReplaces; +}; + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H diff --git a/include/clang/Tooling/Refactoring/Rename/USRFinder.h b/include/clang/Tooling/Refactoring/Rename/USRFinder.h new file mode 100644 index 000000000000..28d541af43c0 --- /dev/null +++ b/include/clang/Tooling/Refactoring/Rename/USRFinder.h @@ -0,0 +1,84 @@ +//===--- USRFinder.h - Clang refactoring library --------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Methods for determining the USR of a symbol at a location in source +/// code. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H +#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H + +#include "clang/AST/AST.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include +#include + +using namespace llvm; +using namespace clang::ast_matchers; + +namespace clang { + +class ASTContext; +class Decl; +class SourceLocation; +class NamedDecl; + +namespace tooling { + +// Given an AST context and a point, returns a NamedDecl identifying the symbol +// at the point. Returns null if nothing is found at the point. +const NamedDecl *getNamedDeclAt(const ASTContext &Context, + const SourceLocation Point); + +// Given an AST context and a fully qualified name, returns a NamedDecl +// identifying the symbol with a matching name. Returns null if nothing is +// found for the name. +const NamedDecl *getNamedDeclFor(const ASTContext &Context, + const std::string &Name); + +// Converts a Decl into a USR. +std::string getUSRForDecl(const Decl *Decl); + +// FIXME: Implement RecursiveASTVisitor::VisitNestedNameSpecifier instead. +class NestedNameSpecifierLocFinder : public MatchFinder::MatchCallback { +public: + explicit NestedNameSpecifierLocFinder(ASTContext &Context) + : Context(Context) {} + + std::vector getNestedNameSpecifierLocations() { + addMatchers(); + Finder.matchAST(Context); + return Locations; + } + +private: + void addMatchers() { + const auto NestedNameSpecifierLocMatcher = + nestedNameSpecifierLoc().bind("nestedNameSpecifierLoc"); + Finder.addMatcher(NestedNameSpecifierLocMatcher, this); + } + + void run(const MatchFinder::MatchResult &Result) override { + const auto *NNS = Result.Nodes.getNodeAs( + "nestedNameSpecifierLoc"); + Locations.push_back(*NNS); + } + + ASTContext &Context; + std::vector Locations; + MatchFinder Finder; +}; + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H diff --git a/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h b/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h new file mode 100644 index 000000000000..8aafee95bc09 --- /dev/null +++ b/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h @@ -0,0 +1,54 @@ +//===--- USRFindingAction.h - Clang refactoring library -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provides an action to find all relevant USRs at a point. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H +#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/ArrayRef.h" + +#include +#include + +namespace clang { +class ASTConsumer; +class CompilerInstance; +class NamedDecl; + +namespace tooling { + +struct USRFindingAction { + USRFindingAction(ArrayRef SymbolOffsets, + ArrayRef QualifiedNames, bool Force) + : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames), + ErrorOccurred(false), Force(Force) {} + std::unique_ptr newASTConsumer(); + + ArrayRef getUSRSpellings() { return SpellingNames; } + ArrayRef> getUSRList() { return USRList; } + bool errorOccurred() { return ErrorOccurred; } + +private: + std::vector SymbolOffsets; + std::vector QualifiedNames; + std::vector SpellingNames; + std::vector> USRList; + bool ErrorOccurred; + bool Force; +}; + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H diff --git a/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h b/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h new file mode 100644 index 000000000000..733ea1a6ac9e --- /dev/null +++ b/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h @@ -0,0 +1,49 @@ +//===--- USRLocFinder.h - Clang refactoring library -----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provides functionality for finding all instances of a USR in a given +/// AST. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H +#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H + +#include "clang/AST/AST.h" +#include "clang/Tooling/Core/Replacement.h" +#include "clang/Tooling/Refactoring/AtomicChange.h" +#include "llvm/ADT/StringRef.h" +#include +#include + +namespace clang { +namespace tooling { + +/// Create atomic changes for renaming all symbol references which are +/// identified by the USRs set to a given new name. +/// +/// \param USRs The set containing USRs of a particular old symbol. +/// \param NewName The new name to replace old symbol name. +/// \param TranslationUnitDecl The translation unit declaration. +/// +/// \return Atomic changes for renaming. +std::vector +createRenameAtomicChanges(llvm::ArrayRef USRs, + llvm::StringRef NewName, Decl *TranslationUnitDecl); + +// FIXME: make this an AST matcher. Wouldn't that be awesome??? I agree! +std::vector +getLocationsOfUSRs(const std::vector &USRs, + llvm::StringRef PrevName, Decl *Decl); + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_LOC_FINDER_H diff --git a/include/clang/module.modulemap b/include/clang/module.modulemap index 282c567c6e51..f7e338d93399 100644 --- a/include/clang/module.modulemap +++ b/include/clang/module.modulemap @@ -133,9 +133,10 @@ module Clang_StaticAnalyzer_Frontend { module Clang_Tooling { requires cplusplus umbrella "Tooling" module * { export * } - // FIXME: Exclude this header to avoid pulling all of the AST matchers + // FIXME: Exclude these headers to avoid pulling all of the AST matchers // library into clang-format. Due to inline key functions in the headers, // importing the AST matchers library gives a link dependency on the AST // matchers (and thus the AST), which clang-format should not have. exclude header "Tooling/RefactoringCallbacks.h" + exclude header "Tooling/Refactoring/Rename/USRFinder.h" } diff --git a/lib/Tooling/Refactoring/CMakeLists.txt b/lib/Tooling/Refactoring/CMakeLists.txt index b2f9b4f4c0cd..288582fc1b6b 100644 --- a/lib/Tooling/Refactoring/CMakeLists.txt +++ b/lib/Tooling/Refactoring/CMakeLists.txt @@ -5,8 +5,16 @@ set(LLVM_LINK_COMPONENTS add_clang_library(clangToolingRefactor AtomicChange.cpp + Rename/RenamingAction.cpp + Rename/USRFinder.cpp + Rename/USRFindingAction.cpp + Rename/USRLocFinder.cpp LINK_LIBS + clangAST + clangASTMatchers clangBasic + clangIndex + clangLex clangToolingCore ) diff --git a/lib/Tooling/Refactoring/Rename/RenamingAction.cpp b/lib/Tooling/Refactoring/Rename/RenamingAction.cpp new file mode 100644 index 000000000000..de6aba944a4a --- /dev/null +++ b/lib/Tooling/Refactoring/Rename/RenamingAction.cpp @@ -0,0 +1,134 @@ +//===--- RenamingAction.cpp - Clang refactoring library -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provides an action to rename every symbol at a point. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/Refactoring/Rename/RenamingAction.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" +#include "clang/Basic/FileManager.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendAction.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Tooling/CommonOptionsParser.h" +#include "clang/Tooling/Refactoring.h" +#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h" +#include "clang/Tooling/Tooling.h" +#include +#include + +using namespace llvm; + +namespace clang { +namespace tooling { + +class RenamingASTConsumer : public ASTConsumer { +public: + RenamingASTConsumer( + const std::vector &NewNames, + const std::vector &PrevNames, + const std::vector> &USRList, + std::map &FileToReplaces, + bool PrintLocations) + : NewNames(NewNames), PrevNames(PrevNames), USRList(USRList), + FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {} + + void HandleTranslationUnit(ASTContext &Context) override { + for (unsigned I = 0; I < NewNames.size(); ++I) + HandleOneRename(Context, NewNames[I], PrevNames[I], USRList[I]); + } + + void HandleOneRename(ASTContext &Context, const std::string &NewName, + const std::string &PrevName, + const std::vector &USRs) { + const SourceManager &SourceMgr = Context.getSourceManager(); + std::vector RenamingCandidates; + std::vector NewCandidates; + + NewCandidates = tooling::getLocationsOfUSRs( + USRs, PrevName, Context.getTranslationUnitDecl()); + RenamingCandidates.insert(RenamingCandidates.end(), NewCandidates.begin(), + NewCandidates.end()); + + unsigned PrevNameLen = PrevName.length(); + for (const auto &Loc : RenamingCandidates) { + if (PrintLocations) { + FullSourceLoc FullLoc(Loc, SourceMgr); + errs() << "clang-rename: renamed at: " << SourceMgr.getFilename(Loc) + << ":" << FullLoc.getSpellingLineNumber() << ":" + << FullLoc.getSpellingColumnNumber() << "\n"; + } + // FIXME: better error handling. + tooling::Replacement Replace(SourceMgr, Loc, PrevNameLen, NewName); + llvm::Error Err = FileToReplaces[Replace.getFilePath()].add(Replace); + if (Err) + llvm::errs() << "Renaming failed in " << Replace.getFilePath() << "! " + << llvm::toString(std::move(Err)) << "\n"; + } + } + +private: + const std::vector &NewNames, &PrevNames; + const std::vector> &USRList; + std::map &FileToReplaces; + bool PrintLocations; +}; + +// A renamer to rename symbols which are identified by a give USRList to +// new name. +// +// FIXME: Merge with the above RenamingASTConsumer. +class USRSymbolRenamer : public ASTConsumer { +public: + USRSymbolRenamer(const std::vector &NewNames, + const std::vector> &USRList, + std::map &FileToReplaces) + : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) { + assert(USRList.size() == NewNames.size()); + } + + void HandleTranslationUnit(ASTContext &Context) override { + for (unsigned I = 0; I < NewNames.size(); ++I) { + // FIXME: Apply AtomicChanges directly once the refactoring APIs are + // ready. + auto AtomicChanges = tooling::createRenameAtomicChanges( + USRList[I], NewNames[I], Context.getTranslationUnitDecl()); + for (const auto AtomicChange : AtomicChanges) { + for (const auto &Replace : AtomicChange.getReplacements()) { + llvm::Error Err = FileToReplaces[Replace.getFilePath()].add(Replace); + if (Err) { + llvm::errs() << "Renaming failed in " << Replace.getFilePath() + << "! " << llvm::toString(std::move(Err)) << "\n"; + } + } + } + } + } + +private: + const std::vector &NewNames; + const std::vector> &USRList; + std::map &FileToReplaces; +}; + +std::unique_ptr RenamingAction::newASTConsumer() { + return llvm::make_unique(NewNames, PrevNames, USRList, + FileToReplaces, PrintLocations); +} + +std::unique_ptr QualifiedRenamingAction::newASTConsumer() { + return llvm::make_unique(NewNames, USRList, FileToReplaces); +} + +} // end namespace tooling +} // end namespace clang diff --git a/lib/Tooling/Refactoring/Rename/USRFinder.cpp b/lib/Tooling/Refactoring/Rename/USRFinder.cpp new file mode 100644 index 000000000000..f36387dafdbf --- /dev/null +++ b/lib/Tooling/Refactoring/Rename/USRFinder.cpp @@ -0,0 +1,213 @@ +//===--- USRFinder.cpp - Clang refactoring library ------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file Implements a recursive AST visitor that finds the USR of a symbol at a +/// point. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/Refactoring/Rename/USRFinder.h" +#include "clang/AST/AST.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Index/USRGeneration.h" +#include "clang/Lex/Lexer.h" +#include "llvm/ADT/SmallVector.h" + +using namespace llvm; + +namespace clang { +namespace tooling { + +// NamedDeclFindingASTVisitor recursively visits each AST node to find the +// symbol underneath the cursor. +// FIXME: move to separate .h/.cc file if this gets too large. +namespace { +class NamedDeclFindingASTVisitor + : public clang::RecursiveASTVisitor { +public: + // \brief Finds the NamedDecl at a point in the source. + // \param Point the location in the source to search for the NamedDecl. + explicit NamedDeclFindingASTVisitor(const SourceLocation Point, + const ASTContext &Context) + : Result(nullptr), Point(Point), Context(Context) {} + + // \brief Finds the NamedDecl for a name in the source. + // \param Name the fully qualified name. + explicit NamedDeclFindingASTVisitor(const std::string &Name, + const ASTContext &Context) + : Result(nullptr), Name(Name), Context(Context) {} + + // Declaration visitors: + + // \brief Checks if the point falls within the NameDecl. This covers every + // declaration of a named entity that we may come across. Usually, just + // checking if the point lies within the length of the name of the declaration + // and the start location is sufficient. + bool VisitNamedDecl(const NamedDecl *Decl) { + return dyn_cast(Decl) + ? true + : setResult(Decl, Decl->getLocation(), + Decl->getNameAsString().length()); + } + + // Expression visitors: + + bool VisitDeclRefExpr(const DeclRefExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl(); + return setResult(Decl, Expr->getLocation(), + Decl->getNameAsString().length()); + } + + bool VisitMemberExpr(const MemberExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl().getDecl(); + return setResult(Decl, Expr->getMemberLoc(), + Decl->getNameAsString().length()); + } + + // Other visitors: + + bool VisitTypeLoc(const TypeLoc Loc) { + const SourceLocation TypeBeginLoc = Loc.getBeginLoc(); + const SourceLocation TypeEndLoc = Lexer::getLocForEndOfToken( + TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts()); + if (const auto *TemplateTypeParm = + dyn_cast(Loc.getType())) + return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc); + if (const auto *TemplateSpecType = + dyn_cast(Loc.getType())) { + return setResult(TemplateSpecType->getTemplateName().getAsTemplateDecl(), + TypeBeginLoc, TypeEndLoc); + } + return setResult(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc, + TypeEndLoc); + } + + bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) { + for (const auto *Initializer : ConstructorDecl->inits()) { + // Ignore implicit initializers. + if (!Initializer->isWritten()) + continue; + if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) { + const SourceLocation InitBeginLoc = Initializer->getSourceLocation(), + InitEndLoc = Lexer::getLocForEndOfToken( + InitBeginLoc, 0, Context.getSourceManager(), + Context.getLangOpts()); + if (!setResult(FieldDecl, InitBeginLoc, InitEndLoc)) + return false; + } + } + return true; + } + + // Other: + + const NamedDecl *getNamedDecl() { return Result; } + + // \brief Determines if a namespace qualifier contains the point. + // \returns false on success and sets Result. + void handleNestedNameSpecifierLoc(NestedNameSpecifierLoc NameLoc) { + while (NameLoc) { + const NamespaceDecl *Decl = + NameLoc.getNestedNameSpecifier()->getAsNamespace(); + setResult(Decl, NameLoc.getLocalBeginLoc(), NameLoc.getLocalEndLoc()); + NameLoc = NameLoc.getPrefix(); + } + } + +private: + // \brief Sets Result to Decl if the Point is within Start and End. + // \returns false on success. + bool setResult(const NamedDecl *Decl, SourceLocation Start, + SourceLocation End) { + if (!Decl) + return true; + if (Name.empty()) { + // Offset is used to find the declaration. + if (!Start.isValid() || !Start.isFileID() || !End.isValid() || + !End.isFileID() || !isPointWithin(Start, End)) + return true; + } else { + // Fully qualified name is used to find the declaration. + if (Name != Decl->getQualifiedNameAsString() && + Name != "::" + Decl->getQualifiedNameAsString()) + return true; + } + Result = Decl; + return false; + } + + // \brief Sets Result to Decl if Point is within Loc and Loc + Offset. + // \returns false on success. + bool setResult(const NamedDecl *Decl, SourceLocation Loc, unsigned Offset) { + // FIXME: Add test for Offset == 0. Add test for Offset - 1 (vs -2 etc). + return Offset == 0 || + setResult(Decl, Loc, Loc.getLocWithOffset(Offset - 1)); + } + + // \brief Determines if the Point is within Start and End. + bool isPointWithin(const SourceLocation Start, const SourceLocation End) { + // FIXME: Add tests for Point == End. + return Point == Start || Point == End || + (Context.getSourceManager().isBeforeInTranslationUnit(Start, + Point) && + Context.getSourceManager().isBeforeInTranslationUnit(Point, End)); + } + + const NamedDecl *Result; + const SourceLocation Point; // The location to find the NamedDecl. + const std::string Name; + const ASTContext &Context; +}; +} // namespace + +const NamedDecl *getNamedDeclAt(const ASTContext &Context, + const SourceLocation Point) { + const SourceManager &SM = Context.getSourceManager(); + NamedDeclFindingASTVisitor Visitor(Point, Context); + + // Try to be clever about pruning down the number of top-level declarations we + // see. If both start and end is either before or after the point we're + // looking for the point cannot be inside of this decl. Don't even look at it. + for (auto *CurrDecl : Context.getTranslationUnitDecl()->decls()) { + SourceLocation StartLoc = CurrDecl->getLocStart(); + SourceLocation EndLoc = CurrDecl->getLocEnd(); + if (StartLoc.isValid() && EndLoc.isValid() && + SM.isBeforeInTranslationUnit(StartLoc, Point) != + SM.isBeforeInTranslationUnit(EndLoc, Point)) + Visitor.TraverseDecl(CurrDecl); + } + + NestedNameSpecifierLocFinder Finder(const_cast(Context)); + for (const auto &Location : Finder.getNestedNameSpecifierLocations()) + Visitor.handleNestedNameSpecifierLoc(Location); + + return Visitor.getNamedDecl(); +} + +const NamedDecl *getNamedDeclFor(const ASTContext &Context, + const std::string &Name) { + NamedDeclFindingASTVisitor Visitor(Name, Context); + Visitor.TraverseDecl(Context.getTranslationUnitDecl()); + + return Visitor.getNamedDecl(); +} + +std::string getUSRForDecl(const Decl *Decl) { + llvm::SmallVector Buff; + + // FIXME: Add test for the nullptr case. + if (Decl == nullptr || index::generateUSRForDecl(Decl, Buff)) + return ""; + + return std::string(Buff.data(), Buff.size()); +} + +} // end namespace tooling +} // end namespace clang diff --git a/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp new file mode 100644 index 000000000000..2769802ad2bc --- /dev/null +++ b/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -0,0 +1,236 @@ +//===--- USRFindingAction.cpp - Clang refactoring library -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provides an action to find USR for the symbol at , as well as +/// all additional USRs. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h" +#include "clang/AST/AST.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/FileManager.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendAction.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Tooling/CommonOptionsParser.h" +#include "clang/Tooling/Refactoring.h" +#include "clang/Tooling/Refactoring/Rename/USRFinder.h" +#include "clang/Tooling/Tooling.h" + +#include +#include +#include +#include + +using namespace llvm; + +namespace clang { +namespace tooling { + +namespace { +// \brief NamedDeclFindingConsumer should delegate finding USRs of given Decl to +// AdditionalUSRFinder. AdditionalUSRFinder adds USRs of ctor and dtor if given +// Decl refers to class and adds USRs of all overridden methods if Decl refers +// to virtual method. +class AdditionalUSRFinder : public RecursiveASTVisitor { +public: + AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context) + : FoundDecl(FoundDecl), Context(Context) {} + + std::vector Find() { + // Fill OverriddenMethods and PartialSpecs storages. + TraverseDecl(Context.getTranslationUnitDecl()); + if (const auto *MethodDecl = dyn_cast(FoundDecl)) { + addUSRsOfOverridenFunctions(MethodDecl); + for (const auto &OverriddenMethod : OverriddenMethods) { + if (checkIfOverriddenFunctionAscends(OverriddenMethod)) + USRSet.insert(getUSRForDecl(OverriddenMethod)); + } + } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) { + handleCXXRecordDecl(RecordDecl); + } else if (const auto *TemplateDecl = + dyn_cast(FoundDecl)) { + handleClassTemplateDecl(TemplateDecl); + } else { + USRSet.insert(getUSRForDecl(FoundDecl)); + } + return std::vector(USRSet.begin(), USRSet.end()); + } + + bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) { + if (MethodDecl->isVirtual()) + OverriddenMethods.push_back(MethodDecl); + return true; + } + + bool VisitClassTemplatePartialSpecializationDecl( + const ClassTemplatePartialSpecializationDecl *PartialSpec) { + PartialSpecs.push_back(PartialSpec); + return true; + } + +private: + void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) { + RecordDecl = RecordDecl->getDefinition(); + if (const auto *ClassTemplateSpecDecl = + dyn_cast(RecordDecl)) + handleClassTemplateDecl(ClassTemplateSpecDecl->getSpecializedTemplate()); + addUSRsOfCtorDtors(RecordDecl); + } + + void handleClassTemplateDecl(const ClassTemplateDecl *TemplateDecl) { + for (const auto *Specialization : TemplateDecl->specializations()) + addUSRsOfCtorDtors(Specialization); + + for (const auto *PartialSpec : PartialSpecs) { + if (PartialSpec->getSpecializedTemplate() == TemplateDecl) + addUSRsOfCtorDtors(PartialSpec); + } + addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl()); + } + + void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) { + RecordDecl = RecordDecl->getDefinition(); + + // Skip if the CXXRecordDecl doesn't have definition. + if (!RecordDecl) + return; + + for (const auto *CtorDecl : RecordDecl->ctors()) + USRSet.insert(getUSRForDecl(CtorDecl)); + + USRSet.insert(getUSRForDecl(RecordDecl->getDestructor())); + USRSet.insert(getUSRForDecl(RecordDecl)); + } + + void addUSRsOfOverridenFunctions(const CXXMethodDecl *MethodDecl) { + USRSet.insert(getUSRForDecl(MethodDecl)); + // Recursively visit each OverridenMethod. + for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) + addUSRsOfOverridenFunctions(OverriddenMethod); + } + + bool checkIfOverriddenFunctionAscends(const CXXMethodDecl *MethodDecl) { + for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) { + if (USRSet.find(getUSRForDecl(OverriddenMethod)) != USRSet.end()) + return true; + return checkIfOverriddenFunctionAscends(OverriddenMethod); + } + return false; + } + + const Decl *FoundDecl; + ASTContext &Context; + std::set USRSet; + std::vector OverriddenMethods; + std::vector PartialSpecs; +}; +} // namespace + +class NamedDeclFindingConsumer : public ASTConsumer { +public: + NamedDeclFindingConsumer(ArrayRef SymbolOffsets, + ArrayRef QualifiedNames, + std::vector &SpellingNames, + std::vector> &USRList, + bool Force, bool &ErrorOccurred) + : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames), + SpellingNames(SpellingNames), USRList(USRList), Force(Force), + ErrorOccurred(ErrorOccurred) {} + +private: + bool FindSymbol(ASTContext &Context, const SourceManager &SourceMgr, + unsigned SymbolOffset, const std::string &QualifiedName) { + DiagnosticsEngine &Engine = Context.getDiagnostics(); + const FileID MainFileID = SourceMgr.getMainFileID(); + + if (SymbolOffset >= SourceMgr.getFileIDSize(MainFileID)) { + ErrorOccurred = true; + unsigned InvalidOffset = Engine.getCustomDiagID( + DiagnosticsEngine::Error, + "SourceLocation in file %0 at offset %1 is invalid"); + Engine.Report(SourceLocation(), InvalidOffset) + << SourceMgr.getFileEntryForID(MainFileID)->getName() << SymbolOffset; + return false; + } + + const SourceLocation Point = SourceMgr.getLocForStartOfFile(MainFileID) + .getLocWithOffset(SymbolOffset); + const NamedDecl *FoundDecl = QualifiedName.empty() + ? getNamedDeclAt(Context, Point) + : getNamedDeclFor(Context, QualifiedName); + + if (FoundDecl == nullptr) { + if (QualifiedName.empty()) { + FullSourceLoc FullLoc(Point, SourceMgr); + unsigned CouldNotFindSymbolAt = Engine.getCustomDiagID( + DiagnosticsEngine::Error, + "clang-rename could not find symbol (offset %0)"); + Engine.Report(Point, CouldNotFindSymbolAt) << SymbolOffset; + ErrorOccurred = true; + return false; + } + + if (Force) + return true; + + unsigned CouldNotFindSymbolNamed = Engine.getCustomDiagID( + DiagnosticsEngine::Error, "clang-rename could not find symbol %0"); + Engine.Report(CouldNotFindSymbolNamed) << QualifiedName; + ErrorOccurred = true; + return false; + } + + // If FoundDecl is a constructor or destructor, we want to instead take + // the Decl of the corresponding class. + if (const auto *CtorDecl = dyn_cast(FoundDecl)) + FoundDecl = CtorDecl->getParent(); + else if (const auto *DtorDecl = dyn_cast(FoundDecl)) + FoundDecl = DtorDecl->getParent(); + + SpellingNames.push_back(FoundDecl->getNameAsString()); + AdditionalUSRFinder Finder(FoundDecl, Context); + USRList.push_back(Finder.Find()); + return true; + } + + void HandleTranslationUnit(ASTContext &Context) override { + const SourceManager &SourceMgr = Context.getSourceManager(); + for (unsigned Offset : SymbolOffsets) { + if (!FindSymbol(Context, SourceMgr, Offset, "")) + return; + } + for (const std::string &QualifiedName : QualifiedNames) { + if (!FindSymbol(Context, SourceMgr, 0, QualifiedName)) + return; + } + } + + ArrayRef SymbolOffsets; + ArrayRef QualifiedNames; + std::vector &SpellingNames; + std::vector> &USRList; + bool Force; + bool &ErrorOccurred; +}; + +std::unique_ptr USRFindingAction::newASTConsumer() { + return llvm::make_unique( + SymbolOffsets, QualifiedNames, SpellingNames, USRList, Force, + ErrorOccurred); +} + +} // end namespace tooling +} // end namespace clang diff --git a/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp new file mode 100644 index 000000000000..934507fe6eae --- /dev/null +++ b/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp @@ -0,0 +1,509 @@ +//===--- USRLocFinder.cpp - Clang refactoring library ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Methods for finding all instances of a USR. Our strategy is very +/// simple; we just compare the USR at every relevant AST node with the one +/// provided. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Lex/Lexer.h" +#include "clang/Tooling/Core/Lookup.h" +#include "clang/Tooling/Refactoring/Rename/USRFinder.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" +#include +#include +#include +#include + +using namespace llvm; + +namespace clang { +namespace tooling { + +namespace { + +// \brief This visitor recursively searches for all instances of a USR in a +// translation unit and stores them for later usage. +class USRLocFindingASTVisitor + : public clang::RecursiveASTVisitor { +public: + explicit USRLocFindingASTVisitor(const std::vector &USRs, + StringRef PrevName, + const ASTContext &Context) + : USRSet(USRs.begin(), USRs.end()), PrevName(PrevName), Context(Context) { + } + + // Declaration visitors: + + bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) { + for (const auto *Initializer : ConstructorDecl->inits()) { + // Ignore implicit initializers. + if (!Initializer->isWritten()) + continue; + if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) { + if (USRSet.find(getUSRForDecl(FieldDecl)) != USRSet.end()) + LocationsFound.push_back(Initializer->getSourceLocation()); + } + } + return true; + } + + bool VisitNamedDecl(const NamedDecl *Decl) { + if (USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) + checkAndAddLocation(Decl->getLocation()); + return true; + } + + // Expression visitors: + + bool VisitDeclRefExpr(const DeclRefExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl(); + + if (USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) { + const SourceManager &Manager = Decl->getASTContext().getSourceManager(); + SourceLocation Location = Manager.getSpellingLoc(Expr->getLocation()); + checkAndAddLocation(Location); + } + + return true; + } + + bool VisitMemberExpr(const MemberExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl().getDecl(); + if (USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) { + const SourceManager &Manager = Decl->getASTContext().getSourceManager(); + SourceLocation Location = Manager.getSpellingLoc(Expr->getMemberLoc()); + checkAndAddLocation(Location); + } + return true; + } + + // Other visitors: + + bool VisitTypeLoc(const TypeLoc Loc) { + if (USRSet.find(getUSRForDecl(Loc.getType()->getAsCXXRecordDecl())) != + USRSet.end()) + checkAndAddLocation(Loc.getBeginLoc()); + if (const auto *TemplateTypeParm = + dyn_cast(Loc.getType())) { + if (USRSet.find(getUSRForDecl(TemplateTypeParm->getDecl())) != + USRSet.end()) + checkAndAddLocation(Loc.getBeginLoc()); + } + return true; + } + + // Non-visitors: + + // \brief Returns a list of unique locations. Duplicate or overlapping + // locations are erroneous and should be reported! + const std::vector &getLocationsFound() const { + return LocationsFound; + } + + // Namespace traversal: + void handleNestedNameSpecifierLoc(NestedNameSpecifierLoc NameLoc) { + while (NameLoc) { + const NamespaceDecl *Decl = + NameLoc.getNestedNameSpecifier()->getAsNamespace(); + if (Decl && USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) + checkAndAddLocation(NameLoc.getLocalBeginLoc()); + NameLoc = NameLoc.getPrefix(); + } + } + +private: + void checkAndAddLocation(SourceLocation Loc) { + const SourceLocation BeginLoc = Loc; + const SourceLocation EndLoc = Lexer::getLocForEndOfToken( + BeginLoc, 0, Context.getSourceManager(), Context.getLangOpts()); + StringRef TokenName = + Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc), + Context.getSourceManager(), Context.getLangOpts()); + size_t Offset = TokenName.find(PrevName); + + // The token of the source location we find actually has the old + // name. + if (Offset != StringRef::npos) + LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset)); + } + + const std::set USRSet; + const std::string PrevName; + std::vector LocationsFound; + const ASTContext &Context; +}; + +SourceLocation StartLocationForType(TypeLoc TL) { + // For elaborated types (e.g. `struct a::A`) we want the portion after the + // `struct` but including the namespace qualifier, `a::`. + if (auto ElaboratedTypeLoc = TL.getAs()) { + NestedNameSpecifierLoc NestedNameSpecifier = + ElaboratedTypeLoc.getQualifierLoc(); + if (NestedNameSpecifier.getNestedNameSpecifier()) + return NestedNameSpecifier.getBeginLoc(); + TL = TL.getNextTypeLoc(); + } + return TL.getLocStart(); +} + +SourceLocation EndLocationForType(TypeLoc TL) { + // Dig past any namespace or keyword qualifications. + while (TL.getTypeLocClass() == TypeLoc::Elaborated || + TL.getTypeLocClass() == TypeLoc::Qualified) + TL = TL.getNextTypeLoc(); + + // The location for template specializations (e.g. Foo) includes the + // templated types in its location range. We want to restrict this to just + // before the `<` character. + if (TL.getTypeLocClass() == TypeLoc::TemplateSpecialization) { + return TL.castAs() + .getLAngleLoc() + .getLocWithOffset(-1); + } + return TL.getEndLoc(); +} + +NestedNameSpecifier *GetNestedNameForType(TypeLoc TL) { + // Dig past any keyword qualifications. + while (TL.getTypeLocClass() == TypeLoc::Qualified) + TL = TL.getNextTypeLoc(); + + // For elaborated types (e.g. `struct a::A`) we want the portion after the + // `struct` but including the namespace qualifier, `a::`. + if (auto ElaboratedTypeLoc = TL.getAs()) + return ElaboratedTypeLoc.getQualifierLoc().getNestedNameSpecifier(); + return nullptr; +} + +// Find all locations identified by the given USRs for rename. +// +// This class will traverse the AST and find every AST node whose USR is in the +// given USRs' set. +class RenameLocFinder : public RecursiveASTVisitor { +public: + RenameLocFinder(llvm::ArrayRef USRs, ASTContext &Context) + : USRSet(USRs.begin(), USRs.end()), Context(Context) {} + + // A structure records all information of a symbol reference being renamed. + // We try to add as few prefix qualifiers as possible. + struct RenameInfo { + // The begin location of a symbol being renamed. + SourceLocation Begin; + // The end location of a symbol being renamed. + SourceLocation End; + // The declaration of a symbol being renamed (can be nullptr). + const NamedDecl *FromDecl; + // The declaration in which the nested name is contained (can be nullptr). + const Decl *Context; + // The nested name being replaced (can be nullptr). + const NestedNameSpecifier *Specifier; + }; + + // FIXME: Currently, prefix qualifiers will be added to the renamed symbol + // definition (e.g. "class Foo {};" => "class b::Bar {};" when renaming + // "a::Foo" to "b::Bar"). + // For renaming declarations/definitions, prefix qualifiers should be filtered + // out. + bool VisitNamedDecl(const NamedDecl *Decl) { + // UsingDecl has been handled in other place. + if (llvm::isa(Decl)) + return true; + + // DestructorDecl has been handled in Typeloc. + if (llvm::isa(Decl)) + return true; + + if (Decl->isImplicit()) + return true; + + if (isInUSRSet(Decl)) { + RenameInfo Info = {Decl->getLocation(), Decl->getLocation(), nullptr, + nullptr, nullptr}; + RenameInfos.push_back(Info); + } + return true; + } + + bool VisitDeclRefExpr(const DeclRefExpr *Expr) { + const NamedDecl *Decl = Expr->getFoundDecl(); + if (isInUSRSet(Decl)) { + RenameInfo Info = {Expr->getSourceRange().getBegin(), + Expr->getSourceRange().getEnd(), Decl, + getClosestAncestorDecl(*Expr), Expr->getQualifier()}; + RenameInfos.push_back(Info); + } + + return true; + } + + bool VisitUsingDecl(const UsingDecl *Using) { + for (const auto *UsingShadow : Using->shadows()) { + if (isInUSRSet(UsingShadow->getTargetDecl())) { + UsingDecls.push_back(Using); + break; + } + } + return true; + } + + bool VisitNestedNameSpecifierLocations(NestedNameSpecifierLoc NestedLoc) { + if (!NestedLoc.getNestedNameSpecifier()->getAsType()) + return true; + if (IsTypeAliasWhichWillBeRenamedElsewhere(NestedLoc.getTypeLoc())) + return true; + + if (const auto *TargetDecl = + getSupportedDeclFromTypeLoc(NestedLoc.getTypeLoc())) { + if (isInUSRSet(TargetDecl)) { + RenameInfo Info = {NestedLoc.getBeginLoc(), + EndLocationForType(NestedLoc.getTypeLoc()), + TargetDecl, getClosestAncestorDecl(NestedLoc), + NestedLoc.getNestedNameSpecifier()->getPrefix()}; + RenameInfos.push_back(Info); + } + } + return true; + } + + bool VisitTypeLoc(TypeLoc Loc) { + if (IsTypeAliasWhichWillBeRenamedElsewhere(Loc)) + return true; + + auto Parents = Context.getParents(Loc); + TypeLoc ParentTypeLoc; + if (!Parents.empty()) { + // Handle cases of nested name specificier locations. + // + // The VisitNestedNameSpecifierLoc interface is not impelmented in + // RecursiveASTVisitor, we have to handle it explicitly. + if (const auto *NSL = Parents[0].get()) { + VisitNestedNameSpecifierLocations(*NSL); + return true; + } + + if (const auto *TL = Parents[0].get()) + ParentTypeLoc = *TL; + } + + // Handle the outermost TypeLoc which is directly linked to the interesting + // declaration and don't handle nested name specifier locations. + if (const auto *TargetDecl = getSupportedDeclFromTypeLoc(Loc)) { + if (isInUSRSet(TargetDecl)) { + // Only handle the outermost typeLoc. + // + // For a type like "a::Foo", there will be two typeLocs for it. + // One ElaboratedType, the other is RecordType: + // + // ElaboratedType 0x33b9390 'a::Foo' sugar + // `-RecordType 0x338fef0 'class a::Foo' + // `-CXXRecord 0x338fe58 'Foo' + // + // Skip if this is an inner typeLoc. + if (!ParentTypeLoc.isNull() && + isInUSRSet(getSupportedDeclFromTypeLoc(ParentTypeLoc))) + return true; + RenameInfo Info = {StartLocationForType(Loc), EndLocationForType(Loc), + TargetDecl, getClosestAncestorDecl(Loc), + GetNestedNameForType(Loc)}; + RenameInfos.push_back(Info); + return true; + } + } + + // Handle specific template class specialiation cases. + if (const auto *TemplateSpecType = + dyn_cast(Loc.getType())) { + TypeLoc TargetLoc = Loc; + if (!ParentTypeLoc.isNull()) { + if (llvm::isa(ParentTypeLoc.getType())) + TargetLoc = ParentTypeLoc; + } + + if (isInUSRSet(TemplateSpecType->getTemplateName().getAsTemplateDecl())) { + TypeLoc TargetLoc = Loc; + // FIXME: Find a better way to handle this case. + // For the qualified template class specification type like + // "ns::Foo" in "ns::Foo& f();", we want the parent typeLoc + // (ElaboratedType) of the TemplateSpecializationType in order to + // catch the prefix qualifiers "ns::". + if (!ParentTypeLoc.isNull() && + llvm::isa(ParentTypeLoc.getType())) + TargetLoc = ParentTypeLoc; + RenameInfo Info = { + StartLocationForType(TargetLoc), EndLocationForType(TargetLoc), + TemplateSpecType->getTemplateName().getAsTemplateDecl(), + getClosestAncestorDecl( + ast_type_traits::DynTypedNode::create(TargetLoc)), + GetNestedNameForType(TargetLoc)}; + RenameInfos.push_back(Info); + } + } + return true; + } + + // Returns a list of RenameInfo. + const std::vector &getRenameInfos() const { return RenameInfos; } + + // Returns a list of using declarations which are needed to update. + const std::vector &getUsingDecls() const { + return UsingDecls; + } + +private: + // FIXME: This method may not be suitable for renaming other types like alias + // types. Need to figure out a way to handle it. + bool IsTypeAliasWhichWillBeRenamedElsewhere(TypeLoc TL) const { + while (!TL.isNull()) { + // SubstTemplateTypeParm is the TypeLocation class for a substituted type + // inside a template expansion so we ignore these. For example: + // + // template struct S { + // T t; // <-- this T becomes a TypeLoc(int) with class + // // SubstTemplateTypeParm when S is instantiated + // } + if (TL.getTypeLocClass() == TypeLoc::SubstTemplateTypeParm) + return true; + + // Typedef is the TypeLocation class for a type which is a typedef to the + // type we want to replace. We ignore the use of the typedef as we will + // replace the definition of it. For example: + // + // typedef int T; + // T a; // <--- This T is a TypeLoc(int) with class Typedef. + if (TL.getTypeLocClass() == TypeLoc::Typedef) + return true; + TL = TL.getNextTypeLoc(); + } + return false; + } + + // Get the supported declaration from a given typeLoc. If the declaration type + // is not supported, returns nullptr. + // + // FIXME: support more types, e.g. enum, type alias. + const NamedDecl *getSupportedDeclFromTypeLoc(TypeLoc Loc) { + if (const auto *RD = Loc.getType()->getAsCXXRecordDecl()) + return RD; + return nullptr; + } + + // Get the closest ancester which is a declaration of a given AST node. + template + const Decl *getClosestAncestorDecl(const ASTNodeType &Node) { + auto Parents = Context.getParents(Node); + // FIXME: figure out how to handle it when there are multiple parents. + if (Parents.size() != 1) + return nullptr; + if (ast_type_traits::ASTNodeKind::getFromNodeKind().isBaseOf( + Parents[0].getNodeKind())) + return Parents[0].template get(); + return getClosestAncestorDecl(Parents[0]); + } + + // Get the parent typeLoc of a given typeLoc. If there is no such parent, + // return nullptr. + const TypeLoc *getParentTypeLoc(TypeLoc Loc) const { + auto Parents = Context.getParents(Loc); + // FIXME: figure out how to handle it when there are multiple parents. + if (Parents.size() != 1) + return nullptr; + return Parents[0].get(); + } + + // Check whether the USR of a given Decl is in the USRSet. + bool isInUSRSet(const Decl *Decl) const { + auto USR = getUSRForDecl(Decl); + if (USR.empty()) + return false; + return llvm::is_contained(USRSet, USR); + } + + const std::set USRSet; + ASTContext &Context; + std::vector RenameInfos; + // Record all interested using declarations which contains the using-shadow + // declarations of the symbol declarations being renamed. + std::vector UsingDecls; +}; + +} // namespace + +std::vector +getLocationsOfUSRs(const std::vector &USRs, StringRef PrevName, + Decl *Decl) { + USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext()); + Visitor.TraverseDecl(Decl); + NestedNameSpecifierLocFinder Finder(Decl->getASTContext()); + + for (const auto &Location : Finder.getNestedNameSpecifierLocations()) + Visitor.handleNestedNameSpecifierLoc(Location); + + return Visitor.getLocationsFound(); +} + +std::vector +createRenameAtomicChanges(llvm::ArrayRef USRs, + llvm::StringRef NewName, Decl *TranslationUnitDecl) { + RenameLocFinder Finder(USRs, TranslationUnitDecl->getASTContext()); + Finder.TraverseDecl(TranslationUnitDecl); + + const SourceManager &SM = + TranslationUnitDecl->getASTContext().getSourceManager(); + + std::vector AtomicChanges; + auto Replace = [&](SourceLocation Start, SourceLocation End, + llvm::StringRef Text) { + tooling::AtomicChange ReplaceChange = tooling::AtomicChange(SM, Start); + llvm::Error Err = ReplaceChange.replace( + SM, CharSourceRange::getTokenRange(Start, End), Text); + if (Err) { + llvm::errs() << "Faile to add replacement to AtomicChange: " + << llvm::toString(std::move(Err)) << "\n"; + return; + } + AtomicChanges.push_back(std::move(ReplaceChange)); + }; + + for (const auto &RenameInfo : Finder.getRenameInfos()) { + std::string ReplacedName = NewName.str(); + if (RenameInfo.FromDecl && RenameInfo.Context) { + if (!llvm::isa( + RenameInfo.Context->getDeclContext())) { + ReplacedName = tooling::replaceNestedName( + RenameInfo.Specifier, RenameInfo.Context->getDeclContext(), + RenameInfo.FromDecl, + NewName.startswith("::") ? NewName.str() : ("::" + NewName).str()); + } + } + // If the NewName contains leading "::", add it back. + if (NewName.startswith("::") && NewName.substr(2) == ReplacedName) + ReplacedName = NewName.str(); + Replace(RenameInfo.Begin, RenameInfo.End, ReplacedName); + } + + // Hanlde using declarations explicitly as "using a::Foo" don't trigger + // typeLoc for "a::Foo". + for (const auto *Using : Finder.getUsingDecls()) + Replace(Using->getLocStart(), Using->getLocEnd(), "using " + NewName.str()); + + return AtomicChanges; +} + +} // end namespace tooling +} // end namespace clang diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 23d23bcddcc1..fa926c584f8e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,6 +47,7 @@ list(APPEND CLANG_TEST_DEPS clang-tblgen clang-offload-bundler clang-import-test + clang-rename ) if(CLANG_ENABLE_STATIC_ANALYZER) diff --git a/test/clang-rename/ClassAsTemplateArgument.cpp b/test/clang-rename/ClassAsTemplateArgument.cpp new file mode 100644 index 000000000000..2e09a5b529e7 --- /dev/null +++ b/test/clang-rename/ClassAsTemplateArgument.cpp @@ -0,0 +1,21 @@ +class Foo /* Test 1 */ {}; // CHECK: class Bar /* Test 1 */ {}; + +template +void func() {} + +template +class Baz {}; + +int main() { + func(); // CHECK: func(); + Baz /* Test 2 */ obj; // CHECK: Baz /* Test 2 */ obj; + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=215 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/ClassFindByName.cpp b/test/clang-rename/ClassFindByName.cpp new file mode 100644 index 000000000000..4430891ec4b1 --- /dev/null +++ b/test/clang-rename/ClassFindByName.cpp @@ -0,0 +1,10 @@ +class Foo { // CHECK: class Bar { +}; + +int main() { + Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; + return 0; +} + +// Test 1. +// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/test/clang-rename/ClassReplacements.cpp b/test/clang-rename/ClassReplacements.cpp new file mode 100644 index 000000000000..2b478bbf900d --- /dev/null +++ b/test/clang-rename/ClassReplacements.cpp @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t/fixes +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=254 -new-name=Bar -export-fixes=%t/fixes/clang-rename.yaml %t.cpp -- +// RUN: clang-apply-replacements %t +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +class Foo {}; // CHECK: class Bar {}; + +// Use grep -FUbo 'Foo' to get the correct offset of Cla when changing +// this file. diff --git a/test/clang-rename/ClassSimpleRenaming.cpp b/test/clang-rename/ClassSimpleRenaming.cpp new file mode 100644 index 000000000000..086f55736cb7 --- /dev/null +++ b/test/clang-rename/ClassSimpleRenaming.cpp @@ -0,0 +1,14 @@ +class Foo /* Test 1 */ { // CHECK: class Bar /* Test 1 */ { +public: + void foo(int x); +}; + +void Foo::foo(int x) /* Test 2 */ {} // CHECK: void Bar::foo(int x) /* Test 2 */ {} + +// Test 1. +// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=109 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/ClassTestMulti.cpp b/test/clang-rename/ClassTestMulti.cpp new file mode 100644 index 000000000000..81e65c760652 --- /dev/null +++ b/test/clang-rename/ClassTestMulti.cpp @@ -0,0 +1,11 @@ +class Foo1 /* Offset 1 */ { // CHECK: class Bar1 /* Offset 1 */ { +}; + +class Foo2 /* Offset 2 */ { // CHECK: class Bar2 /* Offset 2 */ { +}; + +// Test 1. +// RUN: clang-rename -offset=6 -new-name=Bar1 -offset=76 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/ClassTestMultiByName.cpp b/test/clang-rename/ClassTestMultiByName.cpp new file mode 100644 index 000000000000..61b69a1bdf4c --- /dev/null +++ b/test/clang-rename/ClassTestMultiByName.cpp @@ -0,0 +1,8 @@ +class Foo1 { // CHECK: class Bar1 +}; + +class Foo2 { // CHECK: class Bar2 +}; + +// Test 1. +// RUN: clang-rename -qualified-name=Foo1 -new-name=Bar1 -qualified-name=Foo2 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/test/clang-rename/ComplexFunctionOverride.cpp b/test/clang-rename/ComplexFunctionOverride.cpp new file mode 100644 index 000000000000..ccf3a20e5400 --- /dev/null +++ b/test/clang-rename/ComplexFunctionOverride.cpp @@ -0,0 +1,47 @@ +struct A { + virtual void foo() {} /* Test 1 */ // CHECK: virtual void bar() {} +}; + +struct B : A { + void foo() override {} /* Test 2 */ // CHECK: void bar() override {} +}; + +struct C : B { + void foo() override {} /* Test 3 */ // CHECK: void bar() override {} +}; + +struct D : B { + void foo() override {} /* Test 4 */ // CHECK: void bar() override {} +}; + +struct E : D { + void foo() override {} /* Test 5 */ // CHECK: void bar() override {} +}; + +int main() { + A a; + a.foo(); // CHECK: a.bar(); + B b; + b.foo(); // CHECK: b.bar(); + C c; + c.foo(); // CHECK: c.bar(); + D d; + d.foo(); // CHECK: d.bar(); + E e; + e.foo(); // CHECK: e.bar(); + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=26 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=109 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=201 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 4. +// RUN: clang-rename -offset=293 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 5. +// RUN: clang-rename -offset=385 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'foo.*' diff --git a/test/clang-rename/ComplicatedClassType.cpp b/test/clang-rename/ComplicatedClassType.cpp new file mode 100644 index 000000000000..880195303127 --- /dev/null +++ b/test/clang-rename/ComplicatedClassType.cpp @@ -0,0 +1,63 @@ +// Forward declaration. +class Foo; /* Test 1 */ // CHECK: class Bar; /* Test 1 */ + +class Baz { + virtual int getValue() const = 0; +}; + +class Foo : public Baz { /* Test 2 */// CHECK: class Bar : public Baz { +public: + Foo(int value = 0) : x(value) {} // CHECK: Bar(int value = 0) : x(value) {} + + Foo &operator++(int) { // CHECK: Bar &operator++(int) { + x++; + return *this; + } + + bool operator<(Foo const &rhs) { // CHECK: bool operator<(Bar const &rhs) { + return this->x < rhs.x; + } + + int getValue() const { + return 0; + } + +private: + int x; +}; + +int main() { + Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; + Foo Variable = Foo(10); // CHECK: Bar Variable = Bar(10); + for (Foo it; it < Variable; it++) { // CHECK: for (Bar it; it < Variable; it++) { + } + const Foo *C = new Foo(); // CHECK: const Bar *C = new Bar(); + const_cast(C)->getValue(); // CHECK: const_cast(C)->getValue(); + Foo foo; // CHECK: Bar foo; + const Baz &BazReference = foo; + const Baz *BazPointer = &foo; + dynamic_cast(BazReference).getValue(); /* Test 3 */ // CHECK: dynamic_cast(BazReference).getValue(); + dynamic_cast(BazPointer)->getValue(); /* Test 4 */ // CHECK: dynamic_cast(BazPointer)->getValue(); + reinterpret_cast(BazPointer)->getValue(); /* Test 5 */ // CHECK: reinterpret_cast(BazPointer)->getValue(); + static_cast(BazReference).getValue(); /* Test 6 */ // CHECK: static_cast(BazReference).getValue(); + static_cast(BazPointer)->getValue(); /* Test 7 */ // CHECK: static_cast(BazPointer)->getValue(); + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=30 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=155 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=1133 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 4. +// RUN: clang-rename -offset=1266 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 5. +// RUN: clang-rename -offset=1402 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 6. +// RUN: clang-rename -offset=1533 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s +// Test 7. +// RUN: clang-rename -offset=1665 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/Ctor.cpp b/test/clang-rename/Ctor.cpp new file mode 100644 index 000000000000..9908a4123ddf --- /dev/null +++ b/test/clang-rename/Ctor.cpp @@ -0,0 +1,14 @@ +class Foo { // CHECK: class Bar { +public: + Foo(); /* Test 1 */ // CHECK: Bar(); +}; + +Foo::Foo() /* Test 2 */ {} // CHECK: Bar::Bar() /* Test 2 */ {} + +// Test 1. +// RUN: clang-rename -offset=62 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=116 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/CtorInitializer.cpp b/test/clang-rename/CtorInitializer.cpp new file mode 100644 index 000000000000..fed4f5b06c27 --- /dev/null +++ b/test/clang-rename/CtorInitializer.cpp @@ -0,0 +1,17 @@ +class Baz {}; + +class Qux { + Baz Foo; /* Test 1 */ // CHECK: Baz Bar; +public: + Qux(); +}; + +Qux::Qux() : Foo() /* Test 2 */ {} // CHECK: Qux::Qux() : Bar() /* Test 2 */ {} + +// Test 1. +// RUN: clang-rename -offset=33 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=118 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/DeclRefExpr.cpp b/test/clang-rename/DeclRefExpr.cpp new file mode 100644 index 000000000000..6462862d82ad --- /dev/null +++ b/test/clang-rename/DeclRefExpr.cpp @@ -0,0 +1,24 @@ +class C { +public: + static int Foo; /* Test 1 */ // CHECK: static int Bar; +}; + +int foo(int x) { return 0; } +#define MACRO(a) foo(a) + +int main() { + C::Foo = 1; /* Test 2 */ // CHECK: C::Bar = 1; + MACRO(C::Foo); // CHECK: MACRO(C::Bar); + int y = C::Foo; /* Test 3 */ // CHECK: int y = C::Bar; + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=31 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=152 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=271 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/Field.cpp b/test/clang-rename/Field.cpp new file mode 100644 index 000000000000..c0e9a019e47e --- /dev/null +++ b/test/clang-rename/Field.cpp @@ -0,0 +1,15 @@ +class Baz { + int Foo; /* Test 1 */ // CHECK: int Bar; +public: + Baz(); +}; + +Baz::Baz() : Foo(0) /* Test 2 */ {} // CHECK: Baz::Baz() : Bar(0) + +// Test 1. +// RUN: clang-rename -offset=18 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=89 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/FunctionMacro.cpp b/test/clang-rename/FunctionMacro.cpp new file mode 100644 index 000000000000..6e87026ec706 --- /dev/null +++ b/test/clang-rename/FunctionMacro.cpp @@ -0,0 +1,20 @@ +#define moo foo // CHECK: #define moo macro_function + +int foo() /* Test 1 */ { // CHECK: int macro_function() /* Test 1 */ { + return 42; +} + +void boo(int value) {} + +void qoo() { + foo(); // CHECK: macro_function(); + boo(foo()); // CHECK: boo(macro_function()); + moo(); + boo(moo()); +} + +// Test 1. +// RUN: clang-rename -offset=68 -new-name=macro_function %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'foo.*' diff --git a/test/clang-rename/FunctionOverride.cpp b/test/clang-rename/FunctionOverride.cpp new file mode 100644 index 000000000000..adfeb739e66d --- /dev/null +++ b/test/clang-rename/FunctionOverride.cpp @@ -0,0 +1,13 @@ +class A { virtual void foo(); /* Test 1 */ }; // CHECK: class A { virtual void bar(); +class B : public A { void foo(); /* Test 2 */ }; // CHECK: class B : public A { void bar(); +class C : public B { void foo(); /* Test 3 */ }; // CHECK: class C : public B { void bar(); + +// Test 1. +// RUN: clang-rename -offset=23 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=116 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=209 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'foo.*' diff --git a/test/clang-rename/FunctionWithClassFindByName.cpp b/test/clang-rename/FunctionWithClassFindByName.cpp new file mode 100644 index 000000000000..2cae09a1c244 --- /dev/null +++ b/test/clang-rename/FunctionWithClassFindByName.cpp @@ -0,0 +1,12 @@ +void foo() { +} + +class Foo { // CHECK: class Bar +}; + +int main() { + Foo *Pointer = 0; // CHECK: Bar *Pointer = 0; + return 0; +} + +// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/test/clang-rename/IncludeHeaderWithSymbol.cpp b/test/clang-rename/IncludeHeaderWithSymbol.cpp new file mode 100644 index 000000000000..cb2baee57b89 --- /dev/null +++ b/test/clang-rename/IncludeHeaderWithSymbol.cpp @@ -0,0 +1,10 @@ +#include "Inputs/HeaderWithSymbol.h" + +int main() { + return 0; // CHECK: {{^ return 0;}} +} + +// Test 1. +// The file IncludeHeaderWithSymbol.cpp doesn't contain the symbol Foo +// and is expected to be written to stdout without modifications +// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | FileCheck %s diff --git a/test/clang-rename/Inputs/HeaderWithSymbol.h b/test/clang-rename/Inputs/HeaderWithSymbol.h new file mode 100644 index 000000000000..1fe02e89786c --- /dev/null +++ b/test/clang-rename/Inputs/HeaderWithSymbol.h @@ -0,0 +1 @@ +struct Foo {}; diff --git a/test/clang-rename/Inputs/OffsetToNewName.yaml b/test/clang-rename/Inputs/OffsetToNewName.yaml new file mode 100644 index 000000000000..d8e972880f36 --- /dev/null +++ b/test/clang-rename/Inputs/OffsetToNewName.yaml @@ -0,0 +1,6 @@ +--- +- Offset: 6 + NewName: Bar1 +- Offset: 44 + NewName: Bar2 +... diff --git a/test/clang-rename/Inputs/QualifiedNameToNewName.yaml b/test/clang-rename/Inputs/QualifiedNameToNewName.yaml new file mode 100644 index 000000000000..6e3783671dfa --- /dev/null +++ b/test/clang-rename/Inputs/QualifiedNameToNewName.yaml @@ -0,0 +1,6 @@ +--- +- QualifiedName: Foo1 + NewName: Bar1 +- QualifiedName: Foo2 + NewName: Bar2 +... diff --git a/test/clang-rename/InvalidNewName.cpp b/test/clang-rename/InvalidNewName.cpp new file mode 100644 index 000000000000..e6b38e59420a --- /dev/null +++ b/test/clang-rename/InvalidNewName.cpp @@ -0,0 +1,2 @@ +// RUN: not clang-rename -new-name=class -offset=133 %s 2>&1 | FileCheck %s +// CHECK: ERROR: new name is not a valid identifier in C++17. diff --git a/test/clang-rename/InvalidOffset.cpp b/test/clang-rename/InvalidOffset.cpp new file mode 100644 index 000000000000..2ae04d01e4a7 --- /dev/null +++ b/test/clang-rename/InvalidOffset.cpp @@ -0,0 +1,9 @@ +#include "Inputs/HeaderWithSymbol.h" +#define FOO int bar; +FOO + +int foo; + +// RUN: not clang-rename -new-name=qux -offset=259 %s -- 2>&1 | FileCheck %s +// CHECK-NOT: CHECK +// CHECK: error: SourceLocation in file {{.*}}InvalidOffset.cpp at offset 259 is invalid diff --git a/test/clang-rename/InvalidQualifiedName.cpp b/test/clang-rename/InvalidQualifiedName.cpp new file mode 100644 index 000000000000..5280e3939ccd --- /dev/null +++ b/test/clang-rename/InvalidQualifiedName.cpp @@ -0,0 +1,4 @@ +struct S { +}; + +// RUN: clang-rename -force -qualified-name S2 -new-name=T %s -- diff --git a/test/clang-rename/MemberExprMacro.cpp b/test/clang-rename/MemberExprMacro.cpp new file mode 100644 index 000000000000..56cd8d95f6e8 --- /dev/null +++ b/test/clang-rename/MemberExprMacro.cpp @@ -0,0 +1,22 @@ +class Baz { +public: + int Foo; /* Test 1 */ // CHECK: int Bar; +}; + +int qux(int x) { return 0; } +#define MACRO(a) qux(a) + +int main() { + Baz baz; + baz.Foo = 1; /* Test 2 */ // CHECK: baz.Bar = 1; + MACRO(baz.Foo); // CHECK: MACRO(baz.Bar); + int y = baz.Foo; // CHECK: int y = baz.Bar; +} + +// Test 1. +// RUN: clang-rename -offset=26 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=155 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/Namespace.cpp b/test/clang-rename/Namespace.cpp new file mode 100644 index 000000000000..ec9630fdedb6 --- /dev/null +++ b/test/clang-rename/Namespace.cpp @@ -0,0 +1,13 @@ +namespace gcc /* Test 1 */ { // CHECK: namespace clang /* Test 1 */ { + int x; +} + +void boo() { + gcc::x = 42; // CHECK: clang::x = 42; +} + +// Test 1. +// RUN: clang-rename -offset=10 -new-name=clang %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/NoNewName.cpp b/test/clang-rename/NoNewName.cpp new file mode 100644 index 000000000000..4f882d83b0c1 --- /dev/null +++ b/test/clang-rename/NoNewName.cpp @@ -0,0 +1,4 @@ +// Check for an error while -new-name argument has not been passed to +// clang-rename. +// RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s +// CHECK: clang-rename: -new-name must be specified. diff --git a/test/clang-rename/TemplateClassInstantiation.cpp b/test/clang-rename/TemplateClassInstantiation.cpp new file mode 100644 index 000000000000..493d0951df57 --- /dev/null +++ b/test/clang-rename/TemplateClassInstantiation.cpp @@ -0,0 +1,42 @@ +template +class Foo { /* Test 1 */ // CHECK: class Bar { /* Test 1 */ +public: + T foo(T arg, T& ref, T* ptr) { + T value; + int number = 42; + value = (T)number; + value = static_cast(number); + return value; + } + static void foo(T value) {} + T member; +}; + +template +void func() { + Foo obj; /* Test 2 */ // CHECK: Bar obj; + obj.member = T(); + Foo::foo(); // CHECK: Bar::foo(); +} + +int main() { + Foo i; /* Test 3 */ // CHECK: Bar i; + i.member = 0; + Foo::foo(0); // CHECK: Bar::foo(0); + + Foo b; // CHECK: Bar b; + b.member = false; + Foo::foo(false); // CHECK: Bar::foo(false); + + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=29 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=324 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=463 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/TemplateTypename.cpp b/test/clang-rename/TemplateTypename.cpp new file mode 100644 index 000000000000..559ec1f9ade7 --- /dev/null +++ b/test/clang-rename/TemplateTypename.cpp @@ -0,0 +1,24 @@ +template // CHECK: template +class Foo { +T foo(T arg, T& ref, T* /* Test 2 */ ptr) { // CHECK: U foo(U arg, U& ref, U* /* Test 2 */ ptr) { + T value; // CHECK: U value; + int number = 42; + value = (T)number; // CHECK: value = (U)number; + value = static_cast(number); // CHECK: value = static_cast(number); + return value; +} + +static void foo(T value) {} // CHECK: static void foo(U value) {} + +T member; // CHECK: U member; +}; + +// Test 1. +// RUN: clang-rename -offset=19 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=126 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=392 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'T.*' diff --git a/test/clang-rename/TemplatedClassFunction.cpp b/test/clang-rename/TemplatedClassFunction.cpp new file mode 100644 index 000000000000..1f5b0b52ba7a --- /dev/null +++ b/test/clang-rename/TemplatedClassFunction.cpp @@ -0,0 +1,22 @@ +template +class A { +public: + void foo() /* Test 1 */ {} // CHECK: void bar() /* Test 1 */ {} +}; + +int main(int argc, char **argv) { + A a; + a.foo(); /* Test 2 */ // CHECK: a.bar() /* Test 2 */ + return 0; +} + +// Test 1. +// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s +// +// Currently unsupported test. +// XFAIL: * + +// To find offsets after modifying the file, use: +// grep -Ubo 'foo.*' diff --git a/test/clang-rename/UserDefinedConversion.cpp b/test/clang-rename/UserDefinedConversion.cpp new file mode 100644 index 000000000000..60f251ab4483 --- /dev/null +++ b/test/clang-rename/UserDefinedConversion.cpp @@ -0,0 +1,26 @@ +class Foo { /* Test 1 */ // CHECK: class Bar { +public: + Foo() {} // CHECK: Bar() {} +}; + +class Baz { +public: + operator Foo() /* Test 2 */ const { // CHECK: operator Bar() /* Test 2 */ const { + Foo foo; // CHECK: Bar foo; + return foo; + } +}; + +int main() { + Baz boo; + Foo foo = static_cast(boo); // CHECK: Bar foo = static_cast(boo); + return 0; +} + +// Test 1. +// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=164 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/Variable.cpp b/test/clang-rename/Variable.cpp new file mode 100644 index 000000000000..d7e670fb43ee --- /dev/null +++ b/test/clang-rename/Variable.cpp @@ -0,0 +1,33 @@ +#define NAMESPACE namespace A +NAMESPACE { +int Foo; /* Test 1 */ // CHECK: int Bar; +} +int Foo; // CHECK: int Foo; +int Qux = Foo; // CHECK: int Qux = Foo; +int Baz = A::Foo; /* Test 2 */ // CHECK: Baz = A::Bar; +void fun() { + struct { + int Foo; // CHECK: int Foo; + } b = {100}; + int Foo = 100; // CHECK: int Foo = 100; + Baz = Foo; // CHECK: Baz = Foo; + { + extern int Foo; // CHECK: extern int Foo; + Baz = Foo; // CHECK: Baz = Foo; + Foo = A::Foo /* Test 3 */ + Baz; // CHECK: Foo = A::Bar /* Test 3 */ + Baz; + A::Foo /* Test 4 */ = b.Foo; // CHECK: A::Bar /* Test 4 */ = b.Foo; + } + Foo = b.Foo; // Foo = b.Foo; +} + +// Test 1. +// RUN: clang-rename -offset=46 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=234 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=641 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 4. +// RUN: clang-rename -offset=716 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/VariableMacro.cpp b/test/clang-rename/VariableMacro.cpp new file mode 100644 index 000000000000..622e825d3e41 --- /dev/null +++ b/test/clang-rename/VariableMacro.cpp @@ -0,0 +1,21 @@ +#define Baz Foo // CHECK: #define Baz Bar + +void foo(int value) {} + +void macro() { + int Foo; /* Test 1 */ // CHECK: int Bar; + Foo = 42; /* Test 2 */ // CHECK: Bar = 42; + Baz -= 0; + foo(Foo); /* Test 3 */ // CHECK: foo(Bar); + foo(Baz); +} + +// Test 1. +// RUN: clang-rename -offset=88 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -offset=129 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s +// Test 3. +// RUN: clang-rename -offset=191 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s + +// To find offsets after modifying the file, use: +// grep -Ubo 'Foo.*' diff --git a/test/clang-rename/YAMLInput.cpp b/test/clang-rename/YAMLInput.cpp new file mode 100644 index 000000000000..55dbc6d66a5a --- /dev/null +++ b/test/clang-rename/YAMLInput.cpp @@ -0,0 +1,10 @@ +class Foo1 { // CHECK: class Bar1 +}; + +class Foo2 { // CHECK: class Bar2 +}; + +// Test 1. +// RUN: clang-rename -input %S/Inputs/OffsetToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s +// Test 2. +// RUN: clang-rename -input %S/Inputs/QualifiedNameToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b0c97f0f1e4c..4976332b7dbc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -10,6 +10,8 @@ add_clang_subdirectory(clang-offload-bundler) add_clang_subdirectory(c-index-test) +add_clang_subdirectory(clang-rename) + if(CLANG_ENABLE_ARCMT) add_clang_subdirectory(arcmt-test) add_clang_subdirectory(c-arcmt-test) diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt new file mode 100644 index 000000000000..f6a4f49f7aaf --- /dev/null +++ b/tools/clang-rename/CMakeLists.txt @@ -0,0 +1,19 @@ +add_clang_executable(clang-rename ClangRename.cpp) + +target_link_libraries(clang-rename + clangBasic + clangFrontend + clangRewrite + clangTooling + clangToolingCore + clangToolingRefactor + ) + +install(TARGETS clang-rename RUNTIME DESTINATION bin) + +install(PROGRAMS clang-rename.py + DESTINATION share/clang + COMPONENT clang-rename) +install(PROGRAMS clang-rename.el + DESTINATION share/clang + COMPONENT clang-rename) diff --git a/tools/clang-rename/ClangRename.cpp b/tools/clang-rename/ClangRename.cpp new file mode 100644 index 000000000000..0fdf9a39809f --- /dev/null +++ b/tools/clang-rename/ClangRename.cpp @@ -0,0 +1,240 @@ +//===--- tools/extra/clang-rename/ClangRename.cpp - Clang rename tool -----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief This file implements a clang-rename tool that automatically finds and +/// renames symbols in C++ code. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Tooling/CommonOptionsParser.h" +#include "clang/Tooling/Refactoring.h" +#include "clang/Tooling/Refactoring/Rename/RenamingAction.h" +#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "clang/Tooling/Tooling.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include + +using namespace llvm; +using namespace clang; + +/// \brief An oldname -> newname rename. +struct RenameAllInfo { + unsigned Offset = 0; + std::string QualifiedName; + std::string NewName; +}; + +LLVM_YAML_IS_SEQUENCE_VECTOR(RenameAllInfo) + +namespace llvm { +namespace yaml { + +/// \brief Specialized MappingTraits to describe how a RenameAllInfo is +/// (de)serialized. +template <> struct MappingTraits { + static void mapping(IO &IO, RenameAllInfo &Info) { + IO.mapOptional("Offset", Info.Offset); + IO.mapOptional("QualifiedName", Info.QualifiedName); + IO.mapRequired("NewName", Info.NewName); + } +}; + +} // end namespace yaml +} // end namespace llvm + +static cl::OptionCategory ClangRenameOptions("clang-rename common options"); + +static cl::list SymbolOffsets( + "offset", + cl::desc("Locates the symbol by offset as opposed to :."), + cl::ZeroOrMore, cl::cat(ClangRenameOptions)); +static cl::opt Inplace("i", cl::desc("Overwrite edited s."), + cl::cat(ClangRenameOptions)); +static cl::list + QualifiedNames("qualified-name", + cl::desc("The fully qualified name of the symbol."), + cl::ZeroOrMore, cl::cat(ClangRenameOptions)); + +static cl::list + NewNames("new-name", cl::desc("The new name to change the symbol to."), + cl::ZeroOrMore, cl::cat(ClangRenameOptions)); +static cl::opt PrintName( + "pn", + cl::desc("Print the found symbol's name prior to renaming to stderr."), + cl::cat(ClangRenameOptions)); +static cl::opt PrintLocations( + "pl", cl::desc("Print the locations affected by renaming to stderr."), + cl::cat(ClangRenameOptions)); +static cl::opt + ExportFixes("export-fixes", + cl::desc("YAML file to store suggested fixes in."), + cl::value_desc("filename"), cl::cat(ClangRenameOptions)); +static cl::opt + Input("input", cl::desc("YAML file to load oldname-newname pairs from."), + cl::Optional, cl::cat(ClangRenameOptions)); +static cl::opt Force("force", + cl::desc("Ignore nonexistent qualified names."), + cl::cat(ClangRenameOptions)); + +int main(int argc, const char **argv) { + tooling::CommonOptionsParser OP(argc, argv, ClangRenameOptions); + + if (!Input.empty()) { + // Populate QualifiedNames and NewNames from a YAML file. + ErrorOr> Buffer = + llvm::MemoryBuffer::getFile(Input); + if (!Buffer) { + errs() << "clang-rename: failed to read " << Input << ": " + << Buffer.getError().message() << "\n"; + return 1; + } + + std::vector Infos; + llvm::yaml::Input YAML(Buffer.get()->getBuffer()); + YAML >> Infos; + for (const auto &Info : Infos) { + if (!Info.QualifiedName.empty()) + QualifiedNames.push_back(Info.QualifiedName); + else + SymbolOffsets.push_back(Info.Offset); + NewNames.push_back(Info.NewName); + } + } + + // Check the arguments for correctness. + if (NewNames.empty()) { + errs() << "clang-rename: -new-name must be specified.\n\n"; + exit(1); + } + + if (SymbolOffsets.empty() == QualifiedNames.empty()) { + errs() << "clang-rename: -offset and -qualified-name can't be present at " + "the same time.\n"; + exit(1); + } + + // Check if NewNames is a valid identifier in C++17. + LangOptions Options; + Options.CPlusPlus = true; + Options.CPlusPlus1z = true; + IdentifierTable Table(Options); + for (const auto &NewName : NewNames) { + auto NewNameTokKind = Table.get(NewName).getTokenID(); + if (!tok::isAnyIdentifier(NewNameTokKind)) { + errs() << "ERROR: new name is not a valid identifier in C++17.\n\n"; + exit(1); + } + } + + if (SymbolOffsets.size() + QualifiedNames.size() != NewNames.size()) { + errs() << "clang-rename: number of symbol offsets(" << SymbolOffsets.size() + << ") + number of qualified names (" << QualifiedNames.size() + << ") must be equal to number of new names(" << NewNames.size() + << ").\n\n"; + cl::PrintHelpMessage(); + exit(1); + } + + auto Files = OP.getSourcePathList(); + tooling::RefactoringTool Tool(OP.getCompilations(), Files); + tooling::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force); + Tool.run(tooling::newFrontendActionFactory(&FindingAction).get()); + const std::vector> &USRList = + FindingAction.getUSRList(); + const std::vector &PrevNames = FindingAction.getUSRSpellings(); + if (PrintName) { + for (const auto &PrevName : PrevNames) { + outs() << "clang-rename found name: " << PrevName << '\n'; + } + } + + if (FindingAction.errorOccurred()) { + // Diagnostics are already issued at this point. + exit(1); + } + + if (Force && PrevNames.size() < NewNames.size()) { + // No matching PrevName for all NewNames. Without Force this is an error + // above already. + exit(0); + } + + // Perform the renaming. + tooling::RenamingAction RenameAction(NewNames, PrevNames, USRList, + Tool.getReplacements(), PrintLocations); + std::unique_ptr Factory = + tooling::newFrontendActionFactory(&RenameAction); + int ExitCode; + + if (Inplace) { + ExitCode = Tool.runAndSave(Factory.get()); + } else { + ExitCode = Tool.run(Factory.get()); + + if (!ExportFixes.empty()) { + std::error_code EC; + llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None); + if (EC) { + llvm::errs() << "Error opening output file: " << EC.message() << '\n'; + exit(1); + } + + // Export replacements. + tooling::TranslationUnitReplacements TUR; + const auto &FileToReplacements = Tool.getReplacements(); + for (const auto &Entry : FileToReplacements) + TUR.Replacements.insert(TUR.Replacements.end(), Entry.second.begin(), + Entry.second.end()); + + yaml::Output YAML(OS); + YAML << TUR; + OS.close(); + exit(0); + } + + // Write every file to stdout. Right now we just barf the files without any + // indication of which files start where, other than that we print the files + // in the same order we see them. + LangOptions DefaultLangOptions; + IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts); + DiagnosticsEngine Diagnostics( + IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, + &DiagnosticPrinter, false); + auto &FileMgr = Tool.getFiles(); + SourceManager Sources(Diagnostics, FileMgr); + Rewriter Rewrite(Sources, DefaultLangOptions); + + Tool.applyAllReplacements(Rewrite); + for (const auto &File : Files) { + const auto *Entry = FileMgr.getFile(File); + const auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User); + Rewrite.getEditBuffer(ID).write(outs()); + } + } + + exit(ExitCode); +} diff --git a/tools/clang-rename/clang-rename.el b/tools/clang-rename/clang-rename.el new file mode 100644 index 000000000000..b6c3ed4c686b --- /dev/null +++ b/tools/clang-rename/clang-rename.el @@ -0,0 +1,79 @@ +;;; clang-rename.el --- Renames every occurrence of a symbol found at . -*- lexical-binding: t; -*- + +;; Keywords: tools, c + +;;; Commentary: + +;; To install clang-rename.el make sure the directory of this file is in your +;; `load-path' and add +;; +;; (require 'clang-rename) +;; +;; to your .emacs configuration. + +;;; Code: + +(defgroup clang-rename nil + "Integration with clang-rename" + :group 'c) + +(defcustom clang-rename-binary "clang-rename" + "Path to clang-rename executable." + :type '(file :must-match t) + :group 'clang-rename) + +;;;###autoload +(defun clang-rename (new-name) + "Rename all instances of the symbol at point to NEW-NAME using clang-rename." + (interactive "sEnter a new name: ") + (save-some-buffers :all) + ;; clang-rename should not be combined with other operations when undoing. + (undo-boundary) + (let ((output-buffer (get-buffer-create "*clang-rename*"))) + (with-current-buffer output-buffer (erase-buffer)) + (let ((exit-code (call-process + clang-rename-binary nil output-buffer nil + (format "-offset=%d" + ;; clang-rename wants file (byte) offsets, not + ;; buffer (character) positions. + (clang-rename--bufferpos-to-filepos + ;; Emacs treats one character after a symbol as + ;; part of the symbol, but clang-rename doesn’t. + ;; Use the beginning of the current symbol, if + ;; available, to resolve the inconsistency. + (or (car (bounds-of-thing-at-point 'symbol)) + (point)) + 'exact)) + (format "-new-name=%s" new-name) + "-i" (buffer-file-name)))) + (if (and (integerp exit-code) (zerop exit-code)) + ;; Success; revert current buffer so it gets the modifications. + (progn + (kill-buffer output-buffer) + (revert-buffer :ignore-auto :noconfirm :preserve-modes)) + ;; Failure; append exit code to output buffer and display it. + (let ((message (clang-rename--format-message + "clang-rename failed with %s %s" + (if (integerp exit-code) "exit status" "signal") + exit-code))) + (with-current-buffer output-buffer + (insert ?\n message ?\n)) + (message "%s" message) + (display-buffer output-buffer)))))) + +(defalias 'clang-rename--bufferpos-to-filepos + (if (fboundp 'bufferpos-to-filepos) + 'bufferpos-to-filepos + ;; Emacs 24 doesn’t have ‘bufferpos-to-filepos’, simulate it using + ;; ‘position-bytes’. + (lambda (position &optional _quality _coding-system) + (1- (position-bytes position))))) + +;; ‘format-message’ is new in Emacs 25.1. Provide a fallback for older +;; versions. +(defalias 'clang-rename--format-message + (if (fboundp 'format-message) 'format-message 'format)) + +(provide 'clang-rename) + +;;; clang-rename.el ends here diff --git a/tools/clang-rename/clang-rename.py b/tools/clang-rename/clang-rename.py new file mode 100644 index 000000000000..3cc6644ff8f0 --- /dev/null +++ b/tools/clang-rename/clang-rename.py @@ -0,0 +1,61 @@ +''' +Minimal clang-rename integration with Vim. + +Before installing make sure one of the following is satisfied: + +* clang-rename is in your PATH +* `g:clang_rename_path` in ~/.vimrc points to valid clang-rename executable +* `binary` in clang-rename.py points to valid to clang-rename executable + +To install, simply put this into your ~/.vimrc + + noremap cr :pyf /clang-rename.py + +IMPORTANT NOTE: Before running the tool, make sure you saved the file. + +All you have to do now is to place a cursor on a variable/function/class which +you would like to rename and press 'cr'. You will be prompted for a new +name if the cursor points to a valid symbol. +''' + +import vim +import subprocess +import sys + +def main(): + binary = 'clang-rename' + if vim.eval('exists("g:clang_rename_path")') == "1": + binary = vim.eval('g:clang_rename_path') + + # Get arguments for clang-rename binary. + offset = int(vim.eval('line2byte(line("."))+col(".")')) - 2 + if offset < 0: + print >> sys.stderr, '''Couldn\'t determine cursor position. + Is your file empty?''' + return + filename = vim.current.buffer.name + + new_name_request_message = 'type new name:' + new_name = vim.eval("input('{}\n')".format(new_name_request_message)) + + # Call clang-rename. + command = [binary, + filename, + '-i', + '-offset', str(offset), + '-new-name', str(new_name)] + # FIXME: make it possible to run the tool on unsaved file. + p = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + + if stderr: + print stderr + + # Reload all buffers in Vim. + vim.command("checktime") + + +if __name__ == '__main__': + main() diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 7d407ce3f649..b622d66af4ed 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -29,3 +29,4 @@ add_subdirectory(CodeGen) if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) add_subdirectory(libclang) endif() +add_subdirectory(Rename) diff --git a/unittests/Rename/CMakeLists.txt b/unittests/Rename/CMakeLists.txt new file mode 100644 index 000000000000..0b70eed8c9ba --- /dev/null +++ b/unittests/Rename/CMakeLists.txt @@ -0,0 +1,22 @@ +set(LLVM_LINK_COMPONENTS + support + ) + +# We'd like clang/unittests/Tooling/RewriterTestContext.h in the test. +include_directories(${CLANG_SOURCE_DIR}) + +add_extra_unittest(ClangRenameTests + RenameClassTest.cpp + ) + +target_link_libraries(ClangRenameTests + clangAST + clangASTMatchers + clangBasic + clangFormat + clangFrontend + clangRewrite + clangTooling + clangToolingCore + clangToolingRefactor + ) diff --git a/unittests/Rename/ClangRenameTest.h b/unittests/Rename/ClangRenameTest.h new file mode 100644 index 000000000000..0933dd5aaf4f --- /dev/null +++ b/unittests/Rename/ClangRenameTest.h @@ -0,0 +1,112 @@ +//===-- ClangRenameTests.cpp - clang-rename unit tests --------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "unittests/Tooling/RewriterTestContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/VirtualFileSystem.h" +#include "clang/Format/Format.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/PCHContainerOperations.h" +#include "clang/Tooling/Refactoring.h" +#include "clang/Tooling/Refactoring/Rename/RenamingAction.h" +#include "clang/Tooling/Refactoring/Rename/USRFindingAction.h" +#include "clang/Tooling/Tooling.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/MemoryBuffer.h" +#include "gtest/gtest.h" +#include +#include +#include + +namespace clang { +namespace clang_rename { +namespace test { + +struct Case { + std::string Before; + std::string After; + std::string OldName; + std::string NewName; +}; + +class ClangRenameTest : public testing::Test, + public testing::WithParamInterface { +protected: + void AppendToHeader(StringRef Code) { HeaderContent += Code.str(); } + + std::string runClangRenameOnCode(llvm::StringRef Code, + llvm::StringRef OldName, + llvm::StringRef NewName) { + std::string NewCode; + llvm::raw_string_ostream(NewCode) << llvm::format( + "#include \"%s\"\n%s", HeaderName.c_str(), Code.str().c_str()); + tooling::FileContentMappings FileContents = {{HeaderName, HeaderContent}, + {CCName, NewCode}}; + clang::RewriterTestContext Context; + Context.createInMemoryFile(HeaderName, HeaderContent); + clang::FileID InputFileID = Context.createInMemoryFile(CCName, NewCode); + + tooling::USRFindingAction FindingAction({}, {OldName}, false); + std::unique_ptr USRFindingActionFactory = + tooling::newFrontendActionFactory(&FindingAction); + + if (!tooling::runToolOnCodeWithArgs( + USRFindingActionFactory->create(), NewCode, {"-std=c++11"}, CCName, + "clang-rename", std::make_shared(), + FileContents)) + return ""; + + const std::vector> &USRList = + FindingAction.getUSRList(); + std::vector NewNames = {NewName}; + std::map FileToReplacements; + tooling::QualifiedRenamingAction RenameAction(NewNames, USRList, + FileToReplacements); + auto RenameActionFactory = tooling::newFrontendActionFactory(&RenameAction); + if (!tooling::runToolOnCodeWithArgs( + RenameActionFactory->create(), NewCode, {"-std=c++11"}, CCName, + "clang-rename", std::make_shared(), + FileContents)) + return ""; + + formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite, "llvm"); + return Context.getRewrittenText(InputFileID); + } + + void CompareSnippets(StringRef Expected, StringRef Actual) { + std::string ExpectedCode; + llvm::raw_string_ostream(ExpectedCode) << llvm::format( + "#include \"%s\"\n%s", HeaderName.c_str(), Expected.str().c_str()); + EXPECT_EQ(format(ExpectedCode), format(Actual)); + } + + std::string format(llvm::StringRef Code) { + tooling::Replacements Replaces = format::reformat( + format::getLLVMStyle(), Code, {tooling::Range(0, Code.size())}); + auto ChangedCode = tooling::applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast(ChangedCode)); + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()); + return ""; + } + return *ChangedCode; + } + + std::string HeaderContent; + std::string HeaderName = "header.h"; + std::string CCName = "input.cc"; +}; + +} // namespace test +} // namespace clang_rename +} // namesdpace clang diff --git a/unittests/Rename/RenameClassTest.cpp b/unittests/Rename/RenameClassTest.cpp new file mode 100644 index 000000000000..29b4594fb0a4 --- /dev/null +++ b/unittests/Rename/RenameClassTest.cpp @@ -0,0 +1,684 @@ +//===-- RenameClassTest.cpp - unit tests for renaming classes -------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ClangRenameTest.h" + +namespace clang { +namespace clang_rename { +namespace test { +namespace { + +class RenameClassTest : public ClangRenameTest { +public: + RenameClassTest() { + AppendToHeader(R"( + namespace a { + class Foo { + public: + struct Nested { + enum NestedEnum {E1, E2}; + }; + void func() {} + static int Constant; + }; + class Goo { + public: + struct Nested { + enum NestedEnum {E1, E2}; + }; + }; + int Foo::Constant = 1; + } // namespace a + namespace b { + class Foo {}; + } // namespace b + + #define MACRO(x) x + + template class ptr {}; + )"); + } +}; + +INSTANTIATE_TEST_CASE_P( + RenameClassTests, RenameClassTest, + testing::ValuesIn(std::vector({ + // basic classes + {"a::Foo f;", "b::Bar f;", "", ""}, + {"void f(a::Foo f) {}", "void f(b::Bar f) {}", "", ""}, + {"void f(a::Foo *f) {}", "void f(b::Bar *f) {}", "", ""}, + {"a::Foo f() { return a::Foo(); }", "b::Bar f() { return b::Bar(); }", + "", ""}, + {"namespace a {a::Foo f() { return Foo(); }}", + "namespace a {b::Bar f() { return b::Bar(); }}", "", ""}, + {"void f(const a::Foo& a1) {}", "void f(const b::Bar& a1) {}", "", ""}, + {"void f(const a::Foo* a1) {}", "void f(const b::Bar* a1) {}", "", ""}, + {"namespace a { void f(Foo a1) {} }", + "namespace a { void f(b::Bar a1) {} }", "", ""}, + {"void f(MACRO(a::Foo) a1) {}", "void f(MACRO(b::Bar) a1) {}", "", ""}, + {"void f(MACRO(a::Foo a1)) {}", "void f(MACRO(b::Bar a1)) {}", "", ""}, + {"a::Foo::Nested ns;", "b::Bar::Nested ns;", "", ""}, + {"auto t = a::Foo::Constant;", "auto t = b::Bar::Constant;", "", ""}, + {"a::Foo::Nested ns;", "a::Foo::Nested2 ns;", "a::Foo::Nested", + "a::Foo::Nested2"}, + + // use namespace and typedefs + {"using a::Foo; Foo gA;", "using b::Bar; b::Bar gA;", "", ""}, + {"using a::Foo; void f(Foo gA) {}", "using b::Bar; void f(Bar gA) {}", + "", ""}, + {"using a::Foo; namespace x { Foo gA; }", + "using b::Bar; namespace x { Bar gA; }", "", ""}, + {"struct S { using T = a::Foo; T a_; };", + "struct S { using T = b::Bar; T a_; };", "", ""}, + {"using T = a::Foo; T gA;", "using T = b::Bar; T gA;", "", ""}, + {"typedef a::Foo T; T gA;", "typedef b::Bar T; T gA;", "", ""}, + {"typedef MACRO(a::Foo) T; T gA;", "typedef MACRO(b::Bar) T; T gA;", "", + ""}, + + // struct members and other oddities + {"struct S : public a::Foo {};", "struct S : public b::Bar {};", "", + ""}, + {"struct F { void f(a::Foo a1) {} };", + "struct F { void f(b::Bar a1) {} };", "", ""}, + {"struct F { a::Foo a_; };", "struct F { b::Bar a_; };", "", ""}, + {"struct F { ptr a_; };", "struct F { ptr a_; };", "", + ""}, + + {"void f() { a::Foo::Nested ne; }", "void f() { b::Bar::Nested ne; }", + "", ""}, + {"void f() { a::Goo::Nested ne; }", "void f() { a::Goo::Nested ne; }", + "", ""}, + {"void f() { a::Foo::Nested::NestedEnum e; }", + "void f() { b::Bar::Nested::NestedEnum e; }", "", ""}, + {"void f() { auto e = a::Foo::Nested::NestedEnum::E1; }", + "void f() { auto e = b::Bar::Nested::NestedEnum::E1; }", "", ""}, + {"void f() { auto e = a::Foo::Nested::E1; }", + "void f() { auto e = b::Bar::Nested::E1; }", "", ""}, + + // templates + {"template struct Foo { T t; };\n" + "void f() { Foo foo; }", + "template struct Foo { T t; };\n" + "void f() { Foo foo; }", + "", ""}, + {"template struct Foo { a::Foo a; };", + "template struct Foo { b::Bar a; };", "", ""}, + {"template void f(T t) {}\n" + "void g() { f(a::Foo()); }", + "template void f(T t) {}\n" + "void g() { f(b::Bar()); }", + "", ""}, + {"template int f() { return 1; }\n" + "template <> int f() { return 2; }\n" + "int g() { return f(); }", + "template int f() { return 1; }\n" + "template <> int f() { return 2; }\n" + "int g() { return f(); }", + "", ""}, + {"struct Foo { template T foo(); };\n" + "void g() { Foo f; auto a = f.template foo(); }", + "struct Foo { template T foo(); };\n" + "void g() { Foo f; auto a = f.template foo(); }", + "", ""}, + + // The following two templates are distilled from regressions found in + // unique_ptr<> and type_traits.h + {"template struct outer {\n" + " typedef T type;\n" + " type Baz();\n" + " };\n" + " outer g_A;", + "template struct outer {\n" + " typedef T type;\n" + " type Baz();\n" + " };\n" + " outer g_A;", + "", ""}, + {"template struct nested { typedef T type; };\n" + "template struct outer { typename nested::type Foo(); " + "};\n" + "outer g_A;", + "template struct nested { typedef T type; };\n" + "template struct outer { typename nested::type Foo(); " + "};\n" + "outer g_A;", + "", ""}, + + // macros + {"#define FOO(T, t) T t\n" + "void f() { FOO(a::Foo, a1); FOO(a::Foo, a2); }", + "#define FOO(T, t) T t\n" + "void f() { FOO(b::Bar, a1); FOO(b::Bar, a2); }", + "", ""}, + {"#define FOO(n) a::Foo n\n" + " void f() { FOO(a1); FOO(a2); }", + "#define FOO(n) b::Bar n\n" + " void f() { FOO(a1); FOO(a2); }", + "", ""}, + + // Pointer to member functions + {"auto gA = &a::Foo::func;", "auto gA = &b::Bar::func;", "", ""}, + {"using a::Foo; auto gA = &Foo::func;", + "using b::Bar; auto gA = &b::Bar::func;", "", ""}, + {"using a::Foo; namespace x { auto gA = &Foo::func; }", + "using b::Bar; namespace x { auto gA = &Bar::func; }", "", ""}, + {"typedef a::Foo T; auto gA = &T::func;", + "typedef b::Bar T; auto gA = &T::func;", "", ""}, + {"auto gA = &MACRO(a::Foo)::func;", "auto gA = &MACRO(b::Bar)::func;", + "", ""}, + + // Short match inside a namespace + {"namespace a { void f(Foo a1) {} }", + "namespace a { void f(b::Bar a1) {} }", "", ""}, + + // Correct match. + {"using a::Foo; struct F { ptr a_; };", + "using b::Bar; struct F { ptr a_; };", "", ""}, + + // avoid false positives + {"void f(b::Foo a) {}", "void f(b::Foo a) {}", "", ""}, + {"namespace b { void f(Foo a) {} }", "namespace b { void f(Foo a) {} }", + "", ""}, + + // friends, everyone needs friends. + {"class Foo { int i; friend class a::Foo; };", + "class Foo { int i; friend class b::Bar; };", "", ""}, + })), ); + +TEST_P(RenameClassTest, RenameClasses) { + auto Param = GetParam(); + std::string OldName = Param.OldName.empty() ? "a::Foo" : Param.OldName; + std::string NewName = Param.NewName.empty() ? "b::Bar" : Param.NewName; + std::string Actual = runClangRenameOnCode(Param.Before, OldName, NewName); + CompareSnippets(Param.After, Actual); +} + +class NamespaceDetectionTest : public ClangRenameTest { +protected: + NamespaceDetectionTest() { + AppendToHeader(R"( + class Old {}; + namespace o1 { + class Old {}; + namespace o2 { + class Old {}; + namespace o3 { + class Old {}; + } // namespace o3 + } // namespace o2 + } // namespace o1 + )"); + } +}; + +INSTANTIATE_TEST_CASE_P( + RenameClassTest, NamespaceDetectionTest, + ::testing::ValuesIn(std::vector({ + // Test old and new namespace overlap. + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", + "o1::o2::o3::Old", "o1::o2::o3::New"}, + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { n3::New moo; } } }", + "o1::o2::o3::Old", "o1::o2::n3::New"}, + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { n2::n3::New moo; } } }", + "o1::o2::o3::Old", "o1::n2::n3::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { New moo; } }", "::o1::o2::Old", + "::o1::o2::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { n2::New moo; } }", "::o1::o2::Old", + "::o1::n2::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { ::n1::n2::New moo; } }", + "::o1::o2::Old", "::n1::n2::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { n1::n2::New moo; } }", "::o1::o2::Old", + "n1::n2::New"}, + + // Test old and new namespace with differing depths. + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", + "o1::o2::o3::Old", "::o1::New"}, + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", + "o1::o2::o3::Old", "::o1::o2::New"}, + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", + "o1::o2::o3::Old", "o1::New"}, + {"namespace o1 { namespace o2 { namespace o3 { Old moo; } } }", + "namespace o1 { namespace o2 { namespace o3 { New moo; } } }", + "o1::o2::o3::Old", "o1::o2::New"}, + {"Old moo;", "o1::New moo;", "::Old", "o1::New"}, + {"Old moo;", "o1::New moo;", "Old", "o1::New"}, + {"namespace o1 { ::Old moo; }", "namespace o1 { New moo; }", "Old", + "o1::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { ::New moo; } }", "::o1::o2::Old", + "::New"}, + {"namespace o1 { namespace o2 { Old moo; } }", + "namespace o1 { namespace o2 { New moo; } }", "::o1::o2::Old", "New"}, + + // Test moving into the new namespace at different levels. + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { New moo; } }", "::o1::o2::Old", + "::n1::n2::New"}, + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { New moo; } }", "::o1::o2::Old", + "n1::n2::New"}, + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { o2::New moo; } }", "::o1::o2::Old", + "::n1::o2::New"}, + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { o2::New moo; } }", "::o1::o2::Old", + "n1::o2::New"}, + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { ::o1::o2::New moo; } }", + "::o1::o2::Old", "::o1::o2::New"}, + {"namespace n1 { namespace n2 { o1::o2::Old moo; } }", + "namespace n1 { namespace n2 { o1::o2::New moo; } }", "::o1::o2::Old", + "o1::o2::New"}, + + // Test friends declarations. + {"class Foo { friend class o1::Old; };", + "class Foo { friend class o1::New; };", "o1::Old", "o1::New"}, + {"class Foo { int i; friend class o1::Old; };", + "class Foo { int i; friend class ::o1::New; };", "::o1::Old", + "::o1::New"}, + {"namespace o1 { class Foo { int i; friend class Old; }; }", + "namespace o1 { class Foo { int i; friend class New; }; }", "o1::Old", + "o1::New"}, + {"namespace o1 { class Foo { int i; friend class Old; }; }", + "namespace o1 { class Foo { int i; friend class New; }; }", + "::o1::Old", "::o1::New"}, + })), ); + +TEST_P(NamespaceDetectionTest, RenameClasses) { + auto Param = GetParam(); + std::string Actual = + runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); + CompareSnippets(Param.After, Actual); +} + +class TemplatedClassRenameTest : public ClangRenameTest { +protected: + TemplatedClassRenameTest() { + AppendToHeader(R"( + template struct Old { + T t_; + T f() { return T(); }; + static T s(T t) { return t; } + }; + namespace ns { + template struct Old { + T t_; + T f() { return T(); }; + static T s(T t) { return t; } + }; + } // namespace ns + + namespace o1 { + namespace o2 { + namespace o3 { + template struct Old { + T t_; + T f() { return T(); }; + static T s(T t) { return t; } + }; + } // namespace o3 + } // namespace o2 + } // namespace o1 + )"); + } +}; + +INSTANTIATE_TEST_CASE_P( + RenameClassTests, TemplatedClassRenameTest, + ::testing::ValuesIn(std::vector({ + {"Old gI; Old gB;", "New gI; New gB;", "Old", + "New"}, + {"ns::Old gI; ns::Old gB;", + "ns::New gI; ns::New gB;", "ns::Old", "ns::New"}, + {"auto gI = &Old::f; auto gB = &Old::f;", + "auto gI = &New::f; auto gB = &New::f;", "Old", "New"}, + {"auto gI = &ns::Old::f;", "auto gI = &ns::New::f;", + "ns::Old", "ns::New"}, + + {"int gI = Old::s(0); bool gB = Old::s(false);", + "int gI = New::s(0); bool gB = New::s(false);", "Old", + "New"}, + {"int gI = ns::Old::s(0); bool gB = ns::Old::s(false);", + "int gI = ns::New::s(0); bool gB = ns::New::s(false);", + "ns::Old", "ns::New"}, + + {"struct S { Old o_; };", "struct S { New o_; };", "Old", + "New"}, + {"struct S { ns::Old o_; };", "struct S { ns::New o_; };", + "ns::Old", "ns::New"}, + + {"auto a = reinterpret_cast*>(new Old);", + "auto a = reinterpret_cast*>(new New);", "Old", "New"}, + {"auto a = reinterpret_cast*>(new ns::Old);", + "auto a = reinterpret_cast*>(new ns::New);", + "ns::Old", "ns::New"}, + {"auto a = reinterpret_cast*>(new Old);", + "auto a = reinterpret_cast*>(new New);", "Old", + "New"}, + {"auto a = reinterpret_cast*>(new ns::Old);", + "auto a = reinterpret_cast*>(new ns::New);", + "ns::Old", "ns::New"}, + + {"Old& foo();", "New& foo();", "Old", "New"}, + {"ns::Old& foo();", "ns::New& foo();", "ns::Old", + "ns::New"}, + {"o1::o2::o3::Old& foo();", "o1::o2::o3::New& foo();", + "o1::o2::o3::Old", "o1::o2::o3::New"}, + {"namespace ns { Old& foo(); }", + "namespace ns { New& foo(); }", "ns::Old", "ns::New"}, + {"const Old& foo();", "const New& foo();", "Old", "New"}, + {"const ns::Old& foo();", "const ns::New& foo();", + "ns::Old", "ns::New"}, + + // FIXME: figure out why this only works when Moo gets + // specialized at some point. + {"template struct Moo { Old o_; }; Moo m;", + "template struct Moo { New o_; }; Moo m;", "Old", + "New"}, + {"template struct Moo { ns::Old o_; }; Moo m;", + "template struct Moo { ns::New o_; }; Moo m;", + "ns::Old", "ns::New"}, + })), ); + +TEST_P(TemplatedClassRenameTest, RenameTemplateClasses) { + auto Param = GetParam(); + std::string Actual = + runClangRenameOnCode(Param.Before, Param.OldName, Param.NewName); + CompareSnippets(Param.After, Actual); +} + +TEST_F(ClangRenameTest, RenameClassWithOutOfLineMembers) { + std::string Before = R"( + class Old { + public: + Old(); + ~Old(); + + Old* next(); + + private: + Old* next_; + }; + + Old::Old() {} + Old::~Old() {} + Old* Old::next() { return next_; } + )"; + std::string Expected = R"( + class New { + public: + New(); + ~New(); + + New* next(); + + private: + New* next_; + }; + + New::New() {} + New::~New() {} + New* New::next() { return next_; } + )"; + std::string After = runClangRenameOnCode(Before, "Old", "New"); + CompareSnippets(Expected, After); +} + +TEST_F(ClangRenameTest, RenameClassWithInlineMembers) { + std::string Before = R"( + class Old { + public: + Old() {} + ~Old() {} + + Old* next() { return next_; } + + private: + Old* next_; + }; + )"; + std::string Expected = R"( + class New { + public: + New() {} + ~New() {} + + New* next() { return next_; } + + private: + New* next_; + }; + )"; + std::string After = runClangRenameOnCode(Before, "Old", "New"); + CompareSnippets(Expected, After); +} + +// FIXME: no prefix qualifiers being added to the class definition and +// constructor. +TEST_F(ClangRenameTest, RenameClassWithNamespaceWithInlineMembers) { + std::string Before = R"( + namespace ns { + class Old { + public: + Old() {} + ~Old() {} + + Old* next() { return next_; } + + private: + Old* next_; + }; + } // namespace ns + )"; + std::string Expected = R"( + namespace ns { + class ns::New { + public: + ns::New() {} + ~New() {} + + New* next() { return next_; } + + private: + New* next_; + }; + } // namespace ns + )"; + std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); + CompareSnippets(Expected, After); +} + +// FIXME: no prefix qualifiers being added to the class definition and +// constructor. +TEST_F(ClangRenameTest, RenameClassWithNamespaceWithOutOfInlineMembers) { + std::string Before = R"( + namespace ns { + class Old { + public: + Old(); + ~Old(); + + Old* next(); + + private: + Old* next_; + }; + + Old::Old() {} + Old::~Old() {} + Old* Old::next() { return next_; } + } // namespace ns + )"; + std::string Expected = R"( + namespace ns { + class ns::New { + public: + ns::New(); + ~New(); + + New* next(); + + private: + New* next_; + }; + + New::ns::New() {} + New::~New() {} + New* New::next() { return next_; } + } // namespace ns + )"; + std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); + CompareSnippets(Expected, After); +} + +// FIXME: no prefix qualifiers being added to the definition. +TEST_F(ClangRenameTest, RenameClassInInheritedConstructor) { + // `using Base::Base;` will generate an implicit constructor containing usage + // of `::ns::Old` which should not be matched. + std::string Before = R"( + namespace ns { + class Old { + int x; + }; + class Base { + protected: + Old *moo_; + public: + Base(Old *moo) : moo_(moo) {} + }; + class Derived : public Base { + public: + using Base::Base; + }; + } // namespace ns + int main() { + ::ns::Old foo; + ::ns::Derived d(&foo); + return 0; + })"; + std::string Expected = R"( + namespace ns { + class ns::New { + int x; + }; + class Base { + protected: + New *moo_; + public: + Base(New *moo) : moo_(moo) {} + }; + class Derived : public Base { + public: + using Base::Base; + }; + } // namespace ns + int main() { + ::ns::New foo; + ::ns::Derived d(&foo); + return 0; + })"; + std::string After = runClangRenameOnCode(Before, "ns::Old", "ns::New"); + CompareSnippets(Expected, After); +} + +TEST_F(ClangRenameTest, DontRenameReferencesInImplicitFunction) { + std::string Before = R"( + namespace ns { + class Old { + }; + } // namespace ns + struct S { + int y; + ns::Old old; + }; + void f() { + S s1, s2, s3; + // This causes an implicit assignment operator to be created. + s1 = s2 = s3; + } + )"; + std::string Expected = R"( + namespace ns { + class ::new_ns::New { + }; + } // namespace ns + struct S { + int y; + ::new_ns::New old; + }; + void f() { + S s1, s2, s3; + // This causes an implicit assignment operator to be created. + s1 = s2 = s3; + } + )"; + std::string After = runClangRenameOnCode(Before, "ns::Old", "::new_ns::New"); + CompareSnippets(Expected, After); +} + +// FIXME: no prefix qualifiers being adding to the definition. +TEST_F(ClangRenameTest, ReferencesInLambdaFunctionParameters) { + std::string Before = R"( + template + class function; + template + class function { + public: + template + function(Functor f) {} + + function() {} + + R operator()(ArgTypes...) const {} + }; + + namespace ns { + class Old {}; + void f() { + function func; + } + } // namespace ns)"; + std::string Expected = R"( + template + class function; + template + class function { + public: + template + function(Functor f) {} + + function() {} + + R operator()(ArgTypes...) const {} + }; + + namespace ns { + class ::new_ns::New {}; + void f() { + function func; + } + } // namespace ns)"; + std::string After = runClangRenameOnCode(Before, "ns::Old", "::new_ns::New"); + CompareSnippets(Expected, After); +} + +} // anonymous namespace +} // namespace test +} // namespace clang_rename +} // namesdpace clang From 4fde676b9517155be056acca6c06502879f25860 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 30 Jun 2017 16:43:00 +0000 Subject: [PATCH 157/214] Use add_clang_unittest in the CMakeLists.txt for the moved unittest The unittest was moved in r306840 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306841 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Rename/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/Rename/CMakeLists.txt b/unittests/Rename/CMakeLists.txt index 0b70eed8c9ba..aa7609260cc0 100644 --- a/unittests/Rename/CMakeLists.txt +++ b/unittests/Rename/CMakeLists.txt @@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS # We'd like clang/unittests/Tooling/RewriterTestContext.h in the test. include_directories(${CLANG_SOURCE_DIR}) -add_extra_unittest(ClangRenameTests +add_clang_unittest(ClangRenameTests RenameClassTest.cpp ) From 4c75105321fb6af6242d84703a29d3402fe2c625 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 30 Jun 2017 16:58:36 +0000 Subject: [PATCH 158/214] Move ClassReplacements.cpp test from clang-rename tests to the clang-apply-replacements tests The ClassReplacements.cpp test in the clang-rename tests uses clang-apply-replacements. I moved it back to the clang-tools-extra repository for now to ensure that the clang-rename tests can pass when clang is compiled without clang-tools-extra. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306843 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/clang-rename/ClassReplacements.cpp | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 test/clang-rename/ClassReplacements.cpp diff --git a/test/clang-rename/ClassReplacements.cpp b/test/clang-rename/ClassReplacements.cpp deleted file mode 100644 index 2b478bbf900d..000000000000 --- a/test/clang-rename/ClassReplacements.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: rm -rf %t -// RUN: mkdir -p %t/fixes -// RUN: cat %s > %t.cpp -// RUN: clang-rename -offset=254 -new-name=Bar -export-fixes=%t/fixes/clang-rename.yaml %t.cpp -- -// RUN: clang-apply-replacements %t -// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s - -class Foo {}; // CHECK: class Bar {}; - -// Use grep -FUbo 'Foo' to get the correct offset of Cla when changing -// this file. From 431c8af92fa985129de38f1dd237b1b05478eb9d Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 30 Jun 2017 17:15:48 +0000 Subject: [PATCH 159/214] Attempt to fix the linkage error caused by r306840 on the mingw-RA-on-linux bot git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306844 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-rename/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt index f6a4f49f7aaf..771e3bdea6f0 100644 --- a/tools/clang-rename/CMakeLists.txt +++ b/tools/clang-rename/CMakeLists.txt @@ -1,3 +1,8 @@ +set(LLVM_LINK_COMPONENTS + Option + Support + ) + add_clang_executable(clang-rename ClangRename.cpp) target_link_libraries(clang-rename From 7f9026a90735e631c5ccdf07ea300f5b7866f6d3 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 30 Jun 2017 18:14:01 +0000 Subject: [PATCH 160/214] [X86] Move all atom CPUs to the same section of the switch and use fallthroughs like we do for other CPU generations. NFC This is prep work to add MOVBE to all Atom CPUs. This instruction didn't come in to the Nehalem/Westmere/SandyBridge/etc. line until later so there's no natural place to overlap the Atom CPUs into that part of the switch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306849 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index e1d1bf3ad176..c8326ab2736c 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -3224,7 +3224,6 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "cx16", true); break; case CK_Core2: - case CK_Bonnell: setFeatureEnabledImpl(Features, "ssse3", true); setFeatureEnabledImpl(Features, "fxsr", true); setFeatureEnabledImpl(Features, "cx16", true); @@ -3279,7 +3278,6 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "xsaveopt", true); LLVM_FALLTHROUGH; case CK_Westmere: - case CK_Silvermont: setFeatureEnabledImpl(Features, "aes", true); setFeatureEnabledImpl(Features, "pclmul", true); LLVM_FALLTHROUGH; @@ -3297,12 +3295,17 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "xsaves", true); setFeatureEnabledImpl(Features, "clflushopt", true); setFeatureEnabledImpl(Features, "mpx", true); + LLVM_FALLTHROUGH; + case CK_Silvermont: setFeatureEnabledImpl(Features, "aes", true); setFeatureEnabledImpl(Features, "pclmul", true); setFeatureEnabledImpl(Features, "sse4.2", true); + LLVM_FALLTHROUGH; + case CK_Bonnell: + setFeatureEnabledImpl(Features, "ssse3", true); setFeatureEnabledImpl(Features, "fxsr", true); setFeatureEnabledImpl(Features, "cx16", true); - break; + break; case CK_KNL: setFeatureEnabledImpl(Features, "avx512f", true); setFeatureEnabledImpl(Features, "avx512cd", true); From 9dd68b7525f9b8b30923b6b23f5b4fba33aec7a2 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 30 Jun 2017 18:14:02 +0000 Subject: [PATCH 161/214] [X86] Add a break to the last case of a few switches to prevent accidents in the future. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306850 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index c8326ab2736c..52646ae83b2e 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -3545,6 +3545,7 @@ void X86TargetInfo::setSSELevel(llvm::StringMap &Features, Features["avx512pf"] = Features["avx512dq"] = Features["avx512bw"] = Features["avx512vl"] = Features["avx512vbmi"] = Features["avx512ifma"] = Features["avx512vpopcntdq"] = false; + break; } } @@ -3577,6 +3578,7 @@ void X86TargetInfo::setMMXLevel(llvm::StringMap &Features, LLVM_FALLTHROUGH; case AMD3DNowAthlon: Features["3dnowa"] = false; + break; } } @@ -3611,6 +3613,7 @@ void X86TargetInfo::setXOPLevel(llvm::StringMap &Features, XOPEnum Level, LLVM_FALLTHROUGH; case XOP: Features["xop"] = false; + break; } } @@ -4180,6 +4183,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, break; default: Builder.defineMacro("_M_IX86_FP", Twine(0)); + break; } } From 912945a78d78ddb820481c3fd1ae1b112467f6ee Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 30 Jun 2017 18:14:04 +0000 Subject: [PATCH 162/214] [X86] Add RDRND feature to Goldmont. Add MOVBE to all Atom CPUs. Diffential Revision: https://reviews.llvm.org/D34842 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306851 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 2 ++ test/Preprocessor/predefined-arch-macros.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 52646ae83b2e..e1af6415b281 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -3288,6 +3288,7 @@ bool X86TargetInfo::initFeatureMap( break; case CK_Goldmont: setFeatureEnabledImpl(Features, "sha", true); + setFeatureEnabledImpl(Features, "rdrnd", true); setFeatureEnabledImpl(Features, "rdseed", true); setFeatureEnabledImpl(Features, "xsave", true); setFeatureEnabledImpl(Features, "xsaveopt", true); @@ -3302,6 +3303,7 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "sse4.2", true); LLVM_FALLTHROUGH; case CK_Bonnell: + setFeatureEnabledImpl(Features, "movbe", true); setFeatureEnabledImpl(Features, "ssse3", true); setFeatureEnabledImpl(Features, "fxsr", true); setFeatureEnabledImpl(Features, "cx16", true); diff --git a/test/Preprocessor/predefined-arch-macros.c b/test/Preprocessor/predefined-arch-macros.c index 146d005f3f96..da4c5d03574b 100644 --- a/test/Preprocessor/predefined-arch-macros.c +++ b/test/Preprocessor/predefined-arch-macros.c @@ -996,6 +996,7 @@ // CHECK_GLM_M32: #define __MPX__ 1 // CHECK_GLM_M32: #define __PCLMUL__ 1 // CHECK_GLM_M32: #define __POPCNT__ 1 +// CHECK_GLM_M32: #define __RDRND__ 1 // CHECK_GLM_M32: #define __RDSEED__ 1 // CHECK_GLM_M32: #define __SHA__ 1 // CHECK_GLM_M32: #define __SSE2__ 1 @@ -1034,6 +1035,7 @@ // CHECK_GLM_M64: #define __MPX__ 1 // CHECK_GLM_M64: #define __PCLMUL__ 1 // CHECK_GLM_M64: #define __POPCNT__ 1 +// CHECK_GLM_M64: #define __RDRND__ 1 // CHECK_GLM_M64: #define __RDSEED__ 1 // CHECK_GLM_M64: #define __SSE2__ 1 // CHECK_GLM_M64: #define __SSE3__ 1 From 77c1cc560fcefbc6f63434f0dd946fa2190e0411 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Fri, 30 Jun 2017 19:37:11 +0000 Subject: [PATCH 163/214] [ORE] Use LLVM's "diagnostics hotness" spelling Summary: Depends on https://reviews.llvm.org/D34864. To unify Clang and LLVM's spelling of "diagnostic[s] hotness", use the new "diagnostics hotness" spelling in LLVM, which was added in https://reviews.llvm.org/D34864. Reviewers: anemet, davidxl Reviewed By: anemet Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34865 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306862 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index c7e30fad7575..ba033d9413c1 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -228,7 +228,7 @@ namespace clang { Ctx.getDiagnosticHandler(); void *OldDiagnosticContext = Ctx.getDiagnosticContext(); Ctx.setDiagnosticHandler(DiagnosticHandler, this); - Ctx.setDiagnosticHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); + Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); std::unique_ptr OptRecordFile; if (!CodeGenOpts.OptRecordFile.empty()) { @@ -246,7 +246,7 @@ namespace clang { llvm::make_unique(OptRecordFile->os())); if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone) - Ctx.setDiagnosticHotnessRequested(true); + Ctx.setDiagnosticsHotnessRequested(true); } // Link each LinkModule into our module. From fcf6e44da02732ee08478890bf8ec1a56758ff73 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Fri, 30 Jun 2017 20:00:02 +0000 Subject: [PATCH 164/214] clang-format: Do not binpack initialization lists Summary: This patch tries to avoid binpacking when initializing lists/arrays, to allow things like: static int types[] = { registerType1(), registerType2(), registerType3(), }; std::map x = { { 0, "foo fjakfjaklf kljj" }, { 1, "bar fjakfjaklf kljj" }, { 2, "stuff fjakfjaklf kljj" }, }; This is similar to how dictionnaries are formatted, and actually corresponds to the same conditions: when initializing a container (and not just 'calling' a constructor). Such formatting involves 2 things: * Line breaks around the content of the block. This can be forced by adding a comma or comment after the last element * Elements should not be binpacked This patch considers the block is an initializer list if it either ends with a comma, or follows an assignment, which seems to provide a sensible approximation. Reviewers: krasimir, djasper Reviewed By: djasper Subscribers: malcolm.parsons, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34238 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306868 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 4 ++-- unittests/Format/FormatTest.cpp | 24 ++++++++++++++++++++---- unittests/Format/FormatTestJava.cpp | 5 ++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 92c8ad835adc..4197587a74c0 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -1063,12 +1063,12 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, Current.MatchingParen->Previous && Current.MatchingParen->Previous->is(tok::comma); AvoidBinPacking = - (Current.is(TT_ArrayInitializerLSquare) && EndsInComma) || - Current.is(TT_DictLiteral) || + EndsInComma || Current.is(TT_DictLiteral) || Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments || (NextNoComment && NextNoComment->isOneOf(TT_DesignatedInitializerPeriod, TT_DesignatedInitializerLSquare)); + BreakBeforeParameter = EndsInComma; if (Current.ParameterCount > 1) NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1); } else { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 64bb28e0be23..e070396ac05d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6004,7 +6004,10 @@ TEST_F(FormatTest, LayoutBraceInitializersInReturnStatement) { TEST_F(FormatTest, LayoutCxx11BraceInitializers) { verifyFormat("vector x{1, 2, 3, 4};"); verifyFormat("vector x{\n" - " 1, 2, 3, 4,\n" + " 1,\n" + " 2,\n" + " 3,\n" + " 4,\n" "};"); verifyFormat("vector x{{}, {}, {}, {}};"); verifyFormat("f({1, 2});"); @@ -6049,6 +6052,17 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) { "};"); verifyFormat("#define A {a, a},"); + // Binpacking only if there is no trailing comma + verifyFormat("const Aaaaaa aaaaa = {aaaaaaaaaa, bbbbbbbbbb,\n" + " cccccccccc, dddddddddd};", + getLLVMStyleWithColumns(50)); + verifyFormat("const Aaaaaa aaaaa = {\n" + " aaaaaaaaaaa,\n" + " bbbbbbbbbbb,\n" + " ccccccccccc,\n" + " ddddddddddd,\n" + "};", getLLVMStyleWithColumns(50)); + // Cases where distinguising braced lists and blocks is hard. verifyFormat("vector v{12} GUARDED_BY(mutex);"); verifyFormat("void f() {\n" @@ -6128,10 +6142,12 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) { " // Second element:\n" " 2};", getLLVMStyleWithColumns(30))); - // A trailing comma should still lead to an enforced line break. + // A trailing comma should still lead to an enforced line break and no + // binpacking. EXPECT_EQ("vector SomeVector = {\n" " // aaa\n" - " 1, 2,\n" + " 1,\n" + " 2,\n" "};", format("vector SomeVector = { // aaa\n" " 1, 2, };")); @@ -6297,7 +6313,7 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { " aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa}};"); // No column layout should be used here. - verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" + verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); verifyNoCrash("a<,"); diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 6e685f6703e1..b9cfaffb0181 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -237,7 +237,10 @@ TEST_F(FormatTestJava, EnumDeclarations) { TEST_F(FormatTestJava, ArrayInitializers) { verifyFormat("new int[] {1, 2, 3, 4};"); verifyFormat("new int[] {\n" - " 1, 2, 3, 4,\n" + " 1,\n" + " 2,\n" + " 3,\n" + " 4,\n" "};"); FormatStyle Style = getStyleWithColumns(65); From 1e786d52fd3187a3f27de9b1206d3a408e2c1864 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 30 Jun 2017 20:24:32 +0000 Subject: [PATCH 165/214] [clang-rename] Just return instead of calling exit(3) from main. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306873 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-rename/ClangRename.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/clang-rename/ClangRename.cpp b/tools/clang-rename/ClangRename.cpp index 0fdf9a39809f..cc18a05bcdbe 100644 --- a/tools/clang-rename/ClangRename.cpp +++ b/tools/clang-rename/ClangRename.cpp @@ -33,7 +33,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" -#include #include #include @@ -127,13 +126,13 @@ int main(int argc, const char **argv) { // Check the arguments for correctness. if (NewNames.empty()) { errs() << "clang-rename: -new-name must be specified.\n\n"; - exit(1); + return 1; } if (SymbolOffsets.empty() == QualifiedNames.empty()) { errs() << "clang-rename: -offset and -qualified-name can't be present at " "the same time.\n"; - exit(1); + return 1; } // Check if NewNames is a valid identifier in C++17. @@ -145,7 +144,7 @@ int main(int argc, const char **argv) { auto NewNameTokKind = Table.get(NewName).getTokenID(); if (!tok::isAnyIdentifier(NewNameTokKind)) { errs() << "ERROR: new name is not a valid identifier in C++17.\n\n"; - exit(1); + return 1; } } @@ -155,7 +154,7 @@ int main(int argc, const char **argv) { << ") must be equal to number of new names(" << NewNames.size() << ").\n\n"; cl::PrintHelpMessage(); - exit(1); + return 1; } auto Files = OP.getSourcePathList(); @@ -173,13 +172,13 @@ int main(int argc, const char **argv) { if (FindingAction.errorOccurred()) { // Diagnostics are already issued at this point. - exit(1); + return 1; } if (Force && PrevNames.size() < NewNames.size()) { // No matching PrevName for all NewNames. Without Force this is an error // above already. - exit(0); + return 0; } // Perform the renaming. @@ -199,7 +198,7 @@ int main(int argc, const char **argv) { llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None); if (EC) { llvm::errs() << "Error opening output file: " << EC.message() << '\n'; - exit(1); + return 1; } // Export replacements. @@ -212,7 +211,7 @@ int main(int argc, const char **argv) { yaml::Output YAML(OS); YAML << TUR; OS.close(); - exit(0); + return 0; } // Write every file to stdout. Right now we just barf the files without any @@ -236,5 +235,5 @@ int main(int argc, const char **argv) { } } - exit(ExitCode); + return ExitCode; } From 0ce8b803dc6e34c9938aeb37cd2c6460e529f0e0 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Fri, 30 Jun 2017 20:25:55 +0000 Subject: [PATCH 166/214] clang-format: add options to merge empty record body Summary: This patch introduces a few extra BraceWrapping options, similar to `SplitEmptyFunction`, to allow merging empty 'record' bodies (e.g. class, struct, union and namespace): * SplitEmptyClass * SplitEmptyStruct * SplitEmptyUnion * SplitEmptyNamespace The `SplitEmptyFunction` option name has also been simplified/ shortened (from `SplitEmptyFunctionBody`). These options are helpful when the correspond AfterXXX option is enabled, to allow merging the empty record: class Foo {}; In addition, this fixes an unexpected merging of short records, when the AfterXXXX options are used, which caused to be formatted like this: class Foo { void Foo(); }; This is now properly formatted as: class Foo { void Foo(); }; Reviewers: djasper, krasimir Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34395 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306874 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 24 +++- lib/Format/Format.cpp | 16 ++- lib/Format/FormatToken.h | 13 ++ lib/Format/UnwrappedLineFormatter.cpp | 28 +++- unittests/Format/FormatTest.cpp | 180 +++++++++++++++++++++++++- 5 files changed, 247 insertions(+), 14 deletions(-) diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 5b587a4db099..ee24c55fef61 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -717,7 +717,29 @@ struct FormatStyle { /// } /// \endcode /// - bool SplitEmptyFunctionBody; + bool SplitEmptyFunction; + /// \brief If ``false``, empty record (e.g. class, struct or union) body + /// can be put on a single line. This option is used only if the opening + /// brace of the record has already been wrapped, i.e. the `AfterClass` + /// (for classes) brace wrapping mode is set. + /// \code + /// class Foo vs. class Foo + /// {} { + /// } + /// \endcode + /// + bool SplitEmptyRecord; + /// \brief If ``false``, empty namespace body can be put on a single line. + /// This option is used only if the opening brace of the namespace has + /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is + /// set. + /// \code + /// namespace Foo vs. namespace Foo + /// {} { + /// } + /// \endcode + /// + bool SplitEmptyNamespace; }; /// \brief Control of individual brace wrapping cases. diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 94147fcbd2a6..e6657eb26a62 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -414,7 +414,9 @@ template <> struct MappingTraits { IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch); IO.mapOptional("BeforeElse", Wrapping.BeforeElse); IO.mapOptional("IndentBraces", Wrapping.IndentBraces); - IO.mapOptional("SplitEmptyFunctionBody", Wrapping.SplitEmptyFunctionBody); + IO.mapOptional("SplitEmptyFunction", Wrapping.SplitEmptyFunction); + IO.mapOptional("SplitEmptyRecord", Wrapping.SplitEmptyRecord); + IO.mapOptional("SplitEmptyNamespace", Wrapping.SplitEmptyNamespace); } }; @@ -490,7 +492,8 @@ static FormatStyle expandPresets(const FormatStyle &Style) { return Style; FormatStyle Expanded = Style; Expanded.BraceWrapping = {false, false, false, false, false, false, - false, false, false, false, false, true}; + false, false, false, false, false, true, + true, true}; switch (Style.BreakBeforeBraces) { case FormatStyle::BS_Linux: Expanded.BraceWrapping.AfterClass = true; @@ -503,7 +506,8 @@ static FormatStyle expandPresets(const FormatStyle &Style) { Expanded.BraceWrapping.AfterFunction = true; Expanded.BraceWrapping.AfterStruct = true; Expanded.BraceWrapping.AfterUnion = true; - Expanded.BraceWrapping.SplitEmptyFunctionBody = false; + Expanded.BraceWrapping.SplitEmptyFunction = false; + Expanded.BraceWrapping.SplitEmptyRecord = false; break; case FormatStyle::BS_Stroustrup: Expanded.BraceWrapping.AfterFunction = true; @@ -523,7 +527,8 @@ static FormatStyle expandPresets(const FormatStyle &Style) { break; case FormatStyle::BS_GNU: Expanded.BraceWrapping = {true, true, true, true, true, true, - true, true, true, true, true, true}; + true, true, true, true, true, true, + true, true}; break; case FormatStyle::BS_WebKit: Expanded.BraceWrapping.AfterFunction = true; @@ -560,7 +565,8 @@ FormatStyle getLLVMStyle() { LLVMStyle.BreakBeforeTernaryOperators = true; LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach; LLVMStyle.BraceWrapping = {false, false, false, false, false, false, - false, false, false, false, false, true}; + false, false, false, false, false, true, + true, true}; LLVMStyle.BreakAfterJavaFieldAnnotations = false; LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon; LLVMStyle.BreakBeforeInheritanceComma = false; diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index ddec578f89ae..0fe91adcd472 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -476,6 +476,19 @@ struct FormatToken { return MatchingParen && MatchingParen->opensBlockOrBlockTypeList(Style); } + /// \brief Return the actual namespace token, if this token starts a namespace + /// block. + const FormatToken *getNamespaceToken() const { + const FormatToken *NamespaceTok = this; + if (is(tok::comment)) + NamespaceTok = NamespaceTok->getNextNonComment(); + // Detect "(inline)? namespace" in the beginning of a line. + if (NamespaceTok && NamespaceTok->is(tok::kw_inline)) + NamespaceTok = NamespaceTok->getNextNonComment(); + return NamespaceTok && NamespaceTok->is(tok::kw_namespace) ? NamespaceTok + : nullptr; + } + private: // Disallow copying. FormatToken(const FormatToken &) = delete; diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 8836c07cac71..2005a2822924 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -136,10 +136,7 @@ class LevelIndentTracker { bool isNamespaceDeclaration(const AnnotatedLine *Line) { const FormatToken *NamespaceTok = Line->First; - // Detect "(inline)? namespace" in the beginning of a line. - if (NamespaceTok->is(tok::kw_inline)) - NamespaceTok = NamespaceTok->getNextNonComment(); - return NamespaceTok && NamespaceTok->is(tok::kw_namespace); + return NamespaceTok && NamespaceTok->getNamespaceToken(); } bool isEndOfNamespace(const AnnotatedLine *Line, @@ -216,10 +213,31 @@ class LineJoiner { if (TheLine->Last->is(TT_FunctionLBrace) && TheLine->First == TheLine->Last && - !Style.BraceWrapping.SplitEmptyFunctionBody && + !Style.BraceWrapping.SplitEmptyFunction && I[1]->First->is(tok::r_brace)) return tryMergeSimpleBlock(I, E, Limit); + // Handle empty record blocks where the brace has already been wrapped + if (TheLine->Last->is(tok::l_brace) && TheLine->First == TheLine->Last && + I != AnnotatedLines.begin()) { + bool EmptyBlock = I[1]->First->is(tok::r_brace); + + const FormatToken *Tok = I[-1]->First; + if (Tok && Tok->is(tok::comment)) + Tok = Tok->getNextNonComment(); + + if (Tok && Tok->getNamespaceToken()) + return !Style.BraceWrapping.SplitEmptyNamespace && EmptyBlock + ? tryMergeSimpleBlock(I, E, Limit) : 0; + + if (Tok && Tok->is(tok::kw_typedef)) + Tok = Tok->getNextNonComment(); + if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union, + Keywords.kw_interface)) + return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock + ? tryMergeSimpleBlock(I, E, Limit) : 0; + } + // FIXME: TheLine->Level != 0 might or might not be the right check to do. // If necessary, change to something smarter. bool MergeShortFunctions = diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e070396ac05d..b5f959f9c1f7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6571,12 +6571,12 @@ TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { MergeInlineOnly); } -TEST_F(FormatTest, SplitEmptyFunctionBody) { +TEST_F(FormatTest, SplitEmptyFunction) { FormatStyle Style = getLLVMStyle(); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; - Style.BraceWrapping.SplitEmptyFunctionBody = false; + Style.BraceWrapping.SplitEmptyFunction = false; Style.ColumnLimit = 40; verifyFormat("int f()\n" @@ -6639,6 +6639,178 @@ TEST_F(FormatTest, SplitEmptyFunctionBody) { Style); } +TEST_F(FormatTest, SplitEmptyClass) { + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterClass = true; + Style.BraceWrapping.SplitEmptyRecord = false; + + verifyFormat("class Foo\n" + "{};", + Style); + verifyFormat("/* something */ class Foo\n" + "{};", + Style); + verifyFormat("template class Foo\n" + "{};", + Style); + verifyFormat("class Foo\n" + "{\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef class Foo\n" + "{\n" + "} Foo_t;", + Style); +} + +TEST_F(FormatTest, SplitEmptyStruct) { + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterStruct = true; + Style.BraceWrapping.SplitEmptyRecord = false; + + verifyFormat("struct Foo\n" + "{};", + Style); + verifyFormat("/* something */ struct Foo\n" + "{};", + Style); + verifyFormat("template struct Foo\n" + "{};", + Style); + verifyFormat("struct Foo\n" + "{\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef struct Foo\n" + "{\n" + "} Foo_t;", + Style); + //typedef struct Bar {} Bar_t; +} + +TEST_F(FormatTest, SplitEmptyUnion) { + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterUnion = true; + Style.BraceWrapping.SplitEmptyRecord = false; + + verifyFormat("union Foo\n" + "{};", + Style); + verifyFormat("/* something */ union Foo\n" + "{};", + Style); + verifyFormat("union Foo\n" + "{\n" + " A,\n" + "};", + Style); + verifyFormat("typedef union Foo\n" + "{\n" + "} Foo_t;", + Style); +} + +TEST_F(FormatTest, SplitEmptyNamespace) { + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterNamespace = true; + Style.BraceWrapping.SplitEmptyNamespace = false; + + verifyFormat("namespace Foo\n" + "{};", + Style); + verifyFormat("/* something */ namespace Foo\n" + "{};", + Style); + verifyFormat("inline namespace Foo\n" + "{};", + Style); + verifyFormat("namespace Foo\n" + "{\n" + "void Bar();\n" + "};", + Style); +} + +TEST_F(FormatTest, NeverMergeShortRecords) { + FormatStyle Style = getLLVMStyle(); + + verifyFormat("class Foo {\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef class Foo {\n" + " Foo();\n" + "} Foo_t;", + Style); + verifyFormat("struct Foo {\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef struct Foo {\n" + " Foo();\n" + "} Foo_t;", + Style); + verifyFormat("union Foo {\n" + " A,\n" + "};", + Style); + verifyFormat("typedef union Foo {\n" + " A,\n" + "} Foo_t;", + Style); + verifyFormat("namespace Foo {\n" + "void Bar();\n" + "};", + Style); + + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterClass = true; + Style.BraceWrapping.AfterStruct = true; + Style.BraceWrapping.AfterUnion = true; + Style.BraceWrapping.AfterNamespace = true; + verifyFormat("class Foo\n" + "{\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef class Foo\n" + "{\n" + " Foo();\n" + "} Foo_t;", + Style); + verifyFormat("struct Foo\n" + "{\n" + " Foo();\n" + "};", + Style); + verifyFormat("typedef struct Foo\n" + "{\n" + " Foo();\n" + "} Foo_t;", + Style); + verifyFormat("union Foo\n" + "{\n" + " A,\n" + "};", + Style); + verifyFormat("typedef union Foo\n" + "{\n" + " A,\n" + "} Foo_t;", + Style); + verifyFormat("namespace Foo\n" + "{\n" + "void Bar();\n" + "};", + Style); +} + TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { // Elaborate type variable declarations. verifyFormat("struct foo a = {bar};\nint n;"); @@ -9371,7 +9543,9 @@ TEST_F(FormatTest, ParsesConfigurationBools) { CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch); CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse); CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces); - CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunctionBody); + CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction); + CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord); + CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace); } #undef CHECK_PARSE_BOOL From 9275ad44e059db448c53ea677ffd1901fa941e33 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 30 Jun 2017 20:57:39 +0000 Subject: [PATCH 167/214] Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR This is a short-term fix for PR33650 aimed to get the modules build bots green again. Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR macros to try to locally specialize a global template for a global type. That's not how C++ works. Instead, we now centrally define how to format vectors of fundamental types and of string (std::string and StringRef). We use flow formatting for the former cases, since that's the obvious right thing to do; in the latter case, it's less clear what the right choice is, but flow formatting is really bad for some cases (due to very long strings), so we pick block formatting. (Many of the cases that were using flow formatting for strings are improved by this change.) Other than the flow -> block formatting change for some vectors of strings, this should result in no functionality change. Differential Revision: https://reviews.llvm.org/D34907 Corresponding LLVM change is r306878. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306881 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 1 - lib/Tooling/Refactoring/AtomicChange.cpp | 1 - unittests/Tooling/RefactoringTest.cpp | 12 ++++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index e6657eb26a62..bb6781d79517 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -44,7 +44,6 @@ using clang::format::FormatStyle; -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string) LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory) namespace llvm { diff --git a/lib/Tooling/Refactoring/AtomicChange.cpp b/lib/Tooling/Refactoring/AtomicChange.cpp index 321bbfa2866a..79dd346acf72 100644 --- a/lib/Tooling/Refactoring/AtomicChange.cpp +++ b/lib/Tooling/Refactoring/AtomicChange.cpp @@ -12,7 +12,6 @@ #include "llvm/Support/YAMLTraits.h" #include -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string) LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::AtomicChange) namespace { diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index 495ac755b39d..15900940c887 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -1123,8 +1123,10 @@ TEST_F(AtomicChangeTest, AtomicChangeToYAML) { "Key: 'input.cpp:20'\n" "FilePath: input.cpp\n" "Error: ''\n" - "InsertedHeaders: [ a.h ]\n" - "RemovedHeaders: [ b.h ]\n" + "InsertedHeaders: \n" // Extra whitespace here! + " - a.h\n" + "RemovedHeaders: \n" // Extra whitespace here! + " - b.h\n" "Replacements: \n" // Extra whitespace here! " - FilePath: input.cpp\n" " Offset: 20\n" @@ -1143,8 +1145,10 @@ TEST_F(AtomicChangeTest, YAMLToAtomicChange) { "Key: 'input.cpp:20'\n" "FilePath: input.cpp\n" "Error: 'ok'\n" - "InsertedHeaders: [ a.h ]\n" - "RemovedHeaders: [ b.h ]\n" + "InsertedHeaders: \n" // Extra whitespace here! + " - a.h\n" + "RemovedHeaders: \n" // Extra whitespace here! + " - b.h\n" "Replacements: \n" // Extra whitespace here! " - FilePath: input.cpp\n" " Offset: 20\n" From e5f56874aee1c1181a1e645d2c1d147f0db882b0 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 30 Jun 2017 21:02:14 +0000 Subject: [PATCH 168/214] Fix a typo. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306882 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Profile/cxx-structors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Profile/cxx-structors.cpp b/test/Profile/cxx-structors.cpp index 8e0fac163d97..1af01babf3b1 100644 --- a/test/Profile/cxx-structors.cpp +++ b/test/Profile/cxx-structors.cpp @@ -33,7 +33,7 @@ Baz baz; Baz baz2(1); Quux qux("fi", "fo", "fum"); -// Profile data for complete constructors and destructors must absent. +// Profile data for complete constructors and destructors must be absent. // INSTR: @__profc__ZN3BazC1Ev = // INSTR: @__profc__ZN3BazC1Ei = From 4097751e3be4003747ad4445d5a75f940023156a Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 30 Jun 2017 21:02:14 +0000 Subject: [PATCH 169/214] [Profile] Do not assign counters to functions without bodies The root cause of the issues reported in D32406 and D34680 is that clang instruments functions without bodies. Make it stop doing that, and also teach it how to use old (incorrectly generated) profiles without crashing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306883 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPGO.cpp | 3 +++ .../Inputs/cxx-missing-bodies.proftext | 9 ++++++++ test/Profile/cxx-missing-bodies.cpp | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/Profile/Inputs/cxx-missing-bodies.proftext create mode 100644 test/Profile/cxx-missing-bodies.cpp diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 9e193531d0f6..c3d66c1dabc5 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -617,6 +617,9 @@ uint64_t PGOHash::finalize() { void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) { const Decl *D = GD.getDecl(); + if (!D->hasBody()) + return; + bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr(); llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); if (!InstrumentRegions && !PGOReader) diff --git a/test/Profile/Inputs/cxx-missing-bodies.proftext b/test/Profile/Inputs/cxx-missing-bodies.proftext new file mode 100644 index 000000000000..c07f297f74d1 --- /dev/null +++ b/test/Profile/Inputs/cxx-missing-bodies.proftext @@ -0,0 +1,9 @@ +??_GA@@UAEPAXI@Z +1 +1 +1 + +??_DA@@QAEXXZ +1 +1 +1 diff --git a/test/Profile/cxx-missing-bodies.cpp b/test/Profile/cxx-missing-bodies.cpp new file mode 100644 index 000000000000..fe926b3b2182 --- /dev/null +++ b/test/Profile/cxx-missing-bodies.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -S -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti -fprofile-instrument=clang | FileCheck %s --check-prefix=GEN +// +// Don't crash when presented profile data for functions without bodies: +// RUN: llvm-profdata merge %S/Inputs/cxx-missing-bodies.proftext -o %t.profdata +// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -S -emit-llvm -o /dev/null -triple=i386-pc-win32 -fno-rtti -fprofile-instrument-use-path=%t.profdata -w + +// GEN-NOT: __profn{{.*}}??_GA@@UAEPAXI@Z +// GEN-NOT: __profn{{.*}}??_DA@@QAEXXZ + +struct A { + virtual ~A(); +}; +struct B : A { + virtual ~B(); +}; + +B::~B() {} + +void foo() { + B c; +} From 4683fc76198a9e672cbf3118ddc05b27f0efbc8f Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 30 Jun 2017 22:33:24 +0000 Subject: [PATCH 170/214] [Parse] Use normalized attr name for late-parsing checks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306899 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 16 ++++++++-------- test/Sema/diagnose_if.c | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index d0ce9fc89583..06a9d70144d7 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -71,11 +71,18 @@ TypeResult Parser::ParseTypeName(SourceRange *Range, return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); } +/// \brief Normalizes an attribute name by dropping prefixed and suffixed __. +static StringRef normalizeAttrName(StringRef Name) { + if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) + return Name.drop_front(2).drop_back(2); + return Name; +} + /// isAttributeLateParsed - Return true if the attribute has arguments that /// require late parsing. static bool isAttributeLateParsed(const IdentifierInfo &II) { #define CLANG_ATTR_LATE_PARSED_LIST - return llvm::StringSwitch(II.getName()) + return llvm::StringSwitch(normalizeAttrName(II.getName())) #include "clang/Parse/AttrParserStringSwitches.inc" .Default(false); #undef CLANG_ATTR_LATE_PARSED_LIST @@ -200,13 +207,6 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs, } } -/// \brief Normalizes an attribute name by dropping prefixed and suffixed __. -static StringRef normalizeAttrName(StringRef Name) { - if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) - Name = Name.drop_front(2).drop_back(2); - return Name; -} - /// \brief Determine whether the given attribute has an identifier argument. static bool attributeHasIdentifierArg(const IdentifierInfo &II) { #define CLANG_ATTR_IDENTIFIER_ARG_LIST diff --git a/test/Sema/diagnose_if.c b/test/Sema/diagnose_if.c index 27689f49b431..38a3307d924a 100644 --- a/test/Sema/diagnose_if.c +++ b/test/Sema/diagnose_if.c @@ -153,3 +153,7 @@ void runAlwaysWarnWithArg(int a) { // Test that diagnose_if warnings generated in system headers are not ignored. #include "Inputs/diagnose-if-warn-system-header.h" + +// Bug: we would complain about `a` being undeclared if this was spelled +// __diagnose_if__. +void underbarName(int a) __attribute__((__diagnose_if__(a, "", "warning"))); From 7d6afdff43ab27efe4d841d6a235b732293b79cb Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 30 Jun 2017 22:40:17 +0000 Subject: [PATCH 171/214] Reinstate "Load lazily the template specialization in multi-module setups." It was reverted in r305460 but the issue appears to only break our self-host libcxx modules bot. Reapplying it will give us a chance to get a reproducer and fix the issue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306903 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 85 ++++++++++++++++------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index f07c1b1a39f1..4d9ddd2ff506 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -219,6 +219,30 @@ namespace clang { TypedefNameForLinkage(nullptr), HasPendingBody(false), IsDeclMarkedUsed(false) {} + template static + void AddLazySpecializations(T *D, + SmallVectorImpl& IDs) { + if (IDs.empty()) + return; + + // FIXME: We should avoid this pattern of getting the ASTContext. + ASTContext &C = D->getASTContext(); + + auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; + + if (auto &Old = LazySpecializations) { + IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); + std::sort(IDs.begin(), IDs.end()); + IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); + } + + auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; + *Result = IDs.size(); + std::copy(IDs.begin(), IDs.end(), Result + 1); + + LazySpecializations = Result; + } + template static Decl *getMostRecentDeclImpl(Redeclarable *D); static Decl *getMostRecentDeclImpl(...); @@ -247,7 +271,7 @@ namespace clang { void ReadFunctionDefinition(FunctionDecl *FD); void Visit(Decl *D); - void UpdateDecl(Decl *D); + void UpdateDecl(Decl *D, llvm::SmallVectorImpl&); static void setNextObjCCategory(ObjCCategoryDecl *Cat, ObjCCategoryDecl *Next) { @@ -1971,21 +1995,6 @@ ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { return Redecl; } -static DeclID *newDeclIDList(ASTContext &Context, DeclID *Old, - SmallVectorImpl &IDs) { - assert(!IDs.empty() && "no IDs to add to list"); - if (Old) { - IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); - std::sort(IDs.begin(), IDs.end()); - IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); - } - - auto *Result = new (Context) DeclID[1 + IDs.size()]; - *Result = IDs.size(); - std::copy(IDs.begin(), IDs.end(), Result + 1); - return Result; -} - void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); @@ -1994,12 +2003,7 @@ void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { // the specializations. SmallVector SpecIDs; ReadDeclIDList(SpecIDs); - - if (!SpecIDs.empty()) { - auto *CommonPtr = D->getCommonPtr(); - CommonPtr->LazySpecializations = newDeclIDList( - Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs); - } + ASTDeclReader::AddLazySpecializations(D, SpecIDs); } if (D->getTemplatedDecl()->TemplateOrInstantiation) { @@ -2026,12 +2030,7 @@ void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { // the specializations. SmallVector SpecIDs; ReadDeclIDList(SpecIDs); - - if (!SpecIDs.empty()) { - auto *CommonPtr = D->getCommonPtr(); - CommonPtr->LazySpecializations = newDeclIDList( - Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs); - } + ASTDeclReader::AddLazySpecializations(D, SpecIDs); } } @@ -2137,12 +2136,7 @@ void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { // This FunctionTemplateDecl owns a CommonPtr; read it. SmallVector SpecIDs; ReadDeclIDList(SpecIDs); - - if (!SpecIDs.empty()) { - auto *CommonPtr = D->getCommonPtr(); - CommonPtr->LazySpecializations = newDeclIDList( - Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs); - } + ASTDeclReader::AddLazySpecializations(D, SpecIDs); } } @@ -3688,6 +3682,9 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { Decl *D = Record.D; ProcessingUpdatesRAIIObj ProcessingUpdates(*this); DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); + + llvm::SmallVector PendingLazySpecializationIDs; + if (UpdI != DeclUpdateOffsets.end()) { auto UpdateOffsets = std::move(UpdI->second); DeclUpdateOffsets.erase(UpdI); @@ -3712,7 +3709,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, SourceLocation()); - Reader.UpdateDecl(D); + Reader.UpdateDecl(D, PendingLazySpecializationIDs); // We might have made this declaration interesting. If so, remember that // we need to hand it off to the consumer. @@ -3724,6 +3721,17 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { } } } + // Add the lazy specializations to the template. + assert((PendingLazySpecializationIDs.empty() || isa(D) || + isa(D) || isa(D)) && + "Must not have pending specializations"); + if (auto *CTD = dyn_cast(D)) + ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); + else if (auto *FTD = dyn_cast(D)) + ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); + else if (auto *VTD = dyn_cast(D)) + ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); + PendingLazySpecializationIDs.clear(); // Load the pending visible updates for this decl context, if it has any. auto I = PendingVisibleUpdates.find(ID); @@ -3920,7 +3928,8 @@ static void forAllLaterRedecls(DeclT *D, Fn F) { } } -void ASTDeclReader::UpdateDecl(Decl *D) { +void ASTDeclReader::UpdateDecl(Decl *D, + llvm::SmallVectorImpl &PendingLazySpecializationIDs) { while (Record.getIdx() < Record.size()) { switch ((DeclUpdateKind)Record.readInt()) { case UPD_CXX_ADDED_IMPLICIT_MEMBER: { @@ -3936,8 +3945,8 @@ void ASTDeclReader::UpdateDecl(Decl *D) { } case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: - // It will be added to the template's specializations set when loaded. - (void)Record.readDecl(); + // It will be added to the template's lazy specialization set. + PendingLazySpecializationIDs.push_back(ReadDeclID()); break; case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { From 5739844a09581298d1108c9aa91f2d74cd4962e5 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 30 Jun 2017 22:40:33 +0000 Subject: [PATCH 172/214] [ODRHash] Support Type TemplateArgument git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306904 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ODRHash.cpp | 3 +++ test/Modules/odr_hash.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index 5c8d151e0818..0e44a12257cb 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -146,7 +146,10 @@ void ODRHash::AddTemplateArgument(TemplateArgument TA) { switch (Kind) { case TemplateArgument::Null: + llvm_unreachable("Expected valid TemplateArgument"); case TemplateArgument::Type: + AddQualType(TA.getAsType()); + break; case TemplateArgument::Declaration: case TemplateArgument::NullPtr: case TemplateArgument::Integral: diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index f01c4e836a30..3b213971696c 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -1070,6 +1070,40 @@ S4 s4; // expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}} // expected-note@second.h:* {{declaration of 'x' does not match}} #endif + +#if defined(FIRST) +template struct U5 {}; +struct S5 { + U5 x; +}; +#elif defined(SECOND) +template struct U5 {}; +struct S5 { + U5 x; +}; +#else +S5 s5; +// expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +template struct U6 {}; +struct S6 { + U6 x; + U6 y; +}; +#elif defined(SECOND) +template struct U6 {}; +struct S6 { + U6 y; + U6 x; +}; +#else +S6 s6; +// expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} +// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} +#endif } namespace TemplateTypeParmType { From 7fd4191f69e7fdc107617a4beb0078cd0c7cf149 Mon Sep 17 00:00:00 2001 From: Hubert Tong Date: Fri, 30 Jun 2017 22:43:54 +0000 Subject: [PATCH 173/214] Fix PR 33189: Clang assertion on template destructor declaration Summary: This patch aims to fix the bug reported at https://bugs.llvm.org/show_bug.cgi?id=33189. Clang hits an assertion when a template destructor declaration is present. This is caused by later processing that does not expect to encounter a template when looking at a destructor. The resolution is to treat the destructor as being not declared when later processing is interested in the properties of the destructor of a class. Reviewers: rcraik, hubert.reinterpretcast, aaron.ballman, rsmith Reviewed By: rsmith Subscribers: rsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D33833 Patch by Kuang He! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306905 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclCXX.cpp | 5 +---- test/SemaTemplate/destructor-template.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 9f87fe12a9cd..07d128ba555b 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -1417,11 +1417,8 @@ CXXDestructorDecl *CXXRecordDecl::getDestructor() const { Context.getCanonicalType(ClassType)); DeclContext::lookup_result R = lookup(Name); - if (R.empty()) - return nullptr; - CXXDestructorDecl *Dtor = cast(R.front()); - return Dtor; + return R.empty() ? nullptr : dyn_cast(R.front()); } bool CXXRecordDecl::isAnyDestructorNoReturn() const { diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index 853ba492f8e7..6570b6456406 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -86,3 +86,9 @@ namespace PR16852 { template decltype(S().~S()) f(); // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} void g() { f(); } // expected-error {{no matching function for call to 'f'}} } + +class PR33189 +{ + template + ~PR33189() { } // expected-error{{destructor cannot be declared as a template}} +}; From 9a860738b816ad8756eb18113ff146c7f2899960 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Sat, 1 Jul 2017 00:06:27 +0000 Subject: [PATCH 174/214] Change enumerator default linkage type for C Redeclaration lookup should never find hidden enumerators in C, because they do not have linkage (C11 6.2.2/6) The linkage of an enumerator should be VisibleNoLinkage, and isHiddenDeclarationVisible should be checking hasExternalFormalLinkage. This is was reviewed as part of D31778, but splitted into a different commit for clarity. rdar://problem/31909368 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306917 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Visibility.h | 3 +++ include/clang/Sema/Lookup.h | 2 +- lib/AST/Decl.cpp | 4 +++- test/Index/linkage.c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/Visibility.h b/include/clang/Basic/Visibility.h index 6ac52ed6b5e1..cc839d789e7f 100644 --- a/include/clang/Basic/Visibility.h +++ b/include/clang/Basic/Visibility.h @@ -75,6 +75,9 @@ class LinkageInfo { static LinkageInfo none() { return LinkageInfo(NoLinkage, DefaultVisibility, false); } + static LinkageInfo visible_none() { + return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false); + } Linkage getLinkage() const { return (Linkage)linkage_; } Visibility getVisibility() const { return (Visibility)visibility_; } diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index fc16ad2e819e..ea32997d4066 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -275,7 +275,7 @@ class LookupResult { /// declarations, such as those in modules that have not yet been imported. bool isHiddenDeclarationVisible(NamedDecl *ND) const { return AllowHidden || - (isForRedeclaration() && ND->isExternallyVisible()); + (isForRedeclaration() && ND->hasExternalFormalLinkage()); } /// Sets whether tag declarations should be hidden by non-tag diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 8677b1155a60..267c6992af89 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1251,7 +1251,9 @@ static LinkageInfo computeLVForDecl(const NamedDecl *D, case Decl::EnumConstant: // C++ [basic.link]p4: an enumerator has the linkage of its enumeration. - return getLVForDecl(cast(D->getDeclContext()), computation); + if (D->getASTContext().getLangOpts().CPlusPlus) + return getLVForDecl(cast(D->getDeclContext()), computation); + return LinkageInfo::visible_none(); case Decl::Typedef: case Decl::TypeAlias: diff --git a/test/Index/linkage.c b/test/Index/linkage.c index ab006590b61c..b0dcb30990a0 100644 --- a/test/Index/linkage.c +++ b/test/Index/linkage.c @@ -20,7 +20,7 @@ void f16(void) { // CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External -// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External +// CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=NoLinkage // CHECK: VarDecl=x:4:5linkage=External // CHECK: FunctionDecl=foo:5:6linkage=External // CHECK: VarDecl=w:6:12linkage=Internal From f4f39fd907f26918104f7b899146bcb72030862d Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Sat, 1 Jul 2017 00:06:47 +0000 Subject: [PATCH 175/214] [Modules] Implement ODR-like semantics for tag types in C/ObjC Allow ODR for ObjC/C in the sense that we won't keep more that one definition around (merge them). However, ensure the decl pass the structural compatibility check in C11 6.2.7/1, for that, reuse the structural equivalence checks used by the ASTImporter. Few other considerations: - Create error diagnostics for tag types mismatches and thread them into the structural equivalence checks. - Note that by doing this we only support redefinition between types that are considered "compatible types" by C. This is mixed approach of the suggestions discussed in http://lists.llvm.org/pipermail/cfe-dev/2017-March/053257.html Differential Revision: https://reviews.llvm.org/D31778 rdar://problem/31909368 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306918 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTStructuralEquivalence.h | 6 +- include/clang/Basic/DiagnosticASTKinds.td | 11 ++- include/clang/Sema/Sema.h | 32 ++++--- lib/AST/ASTStructuralEquivalence.cpp | 58 ++++++++++--- lib/Parse/ParseDecl.cpp | 19 +++-- lib/Parse/ParseDeclCXX.cpp | 14 +++- lib/Sema/SemaDecl.cpp | 83 +++++++++++++++++-- lib/Sema/SemaType.cpp | 15 ++++ test/Modules/Inputs/F.framework/Headers/F.h | 1 + .../F.framework/Modules/module.modulemap | 7 ++ .../Modules/module.private.modulemap | 7 ++ .../Inputs/F.framework/PrivateHeaders/NS.h | 19 +++++ ...orated-type-specifier-from-hidden-module.m | 7 +- test/Modules/redefinition-c-tagtypes.m | 48 +++++++++++ test/Modules/redefinition-same-header.m | 10 +-- 15 files changed, 284 insertions(+), 53 deletions(-) create mode 100644 test/Modules/Inputs/F.framework/Headers/F.h create mode 100644 test/Modules/Inputs/F.framework/Modules/module.modulemap create mode 100644 test/Modules/Inputs/F.framework/Modules/module.private.modulemap create mode 100644 test/Modules/Inputs/F.framework/PrivateHeaders/NS.h create mode 100644 test/Modules/redefinition-c-tagtypes.m diff --git a/include/clang/AST/ASTStructuralEquivalence.h b/include/clang/AST/ASTStructuralEquivalence.h index 770bb5763fbd..23674c65f332 100644 --- a/include/clang/AST/ASTStructuralEquivalence.h +++ b/include/clang/AST/ASTStructuralEquivalence.h @@ -62,9 +62,11 @@ struct StructuralEquivalenceContext { StructuralEquivalenceContext( ASTContext &FromCtx, ASTContext &ToCtx, llvm::DenseSet> &NonEquivalentDecls, - bool StrictTypeSpelling = false, bool Complain = true) + bool StrictTypeSpelling = false, bool Complain = true, + bool ErrorOnTagTypeMismatch = false) : FromCtx(FromCtx), ToCtx(ToCtx), NonEquivalentDecls(NonEquivalentDecls), - StrictTypeSpelling(StrictTypeSpelling), Complain(Complain), + StrictTypeSpelling(StrictTypeSpelling), + ErrorOnTagTypeMismatch(ErrorOnTagTypeMismatch), Complain(Complain), LastDiagFromC2(false) {} DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID); diff --git a/include/clang/Basic/DiagnosticASTKinds.td b/include/clang/Basic/DiagnosticASTKinds.td index 652d06278557..b3cba2066edd 100644 --- a/include/clang/Basic/DiagnosticASTKinds.td +++ b/include/clang/Basic/DiagnosticASTKinds.td @@ -200,12 +200,17 @@ def note_odr_defined_here : Note<"also defined here">; def err_odr_function_type_inconsistent : Error< "external function %0 declared with incompatible types in different " "translation units (%1 vs. %2)">; -def warn_odr_tag_type_inconsistent : Warning< - "type %0 has incompatible definitions in different translation units">, - InGroup>; +def warn_odr_tag_type_inconsistent + : Warning<"type %0 has incompatible definitions in different translation " + "units">, + InGroup>; +def err_odr_tag_type_inconsistent + : Error<"type %0 has incompatible definitions in different translation " + "units">; def note_odr_tag_kind_here: Note< "%0 is a %select{struct|interface|union|class|enum}1 here">; def note_odr_field : Note<"field %0 has type %1 here">; +def note_odr_field_name : Note<"field has name %0 here">; def note_odr_missing_field : Note<"no corresponding field here">; def note_odr_bit_field : Note<"bit-field %0 with type %1 and length %2 here">; def note_odr_not_bit_field : Note<"field %0 is not a bit-field">; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 75ff5fdb37a1..95134d52f873 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1542,6 +1542,10 @@ class Sema { bool hasVisibleMergedDefinition(NamedDecl *Def); + /// Determine if \p D and \p Suggested have a structurally compatible + /// layout as described in C11 6.2.7/1. + bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); + /// Determine if \p D has a visible definition. If not, suggest a declaration /// that should be made visible to expose the definition. bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, @@ -1629,9 +1633,13 @@ class Sema { // struct SkipBodyInfo { - SkipBodyInfo() : ShouldSkip(false), Previous(nullptr) {} + SkipBodyInfo() + : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr), + New(nullptr) {} bool ShouldSkip; + bool CheckSameAsPrevious; NamedDecl *Previous; + NamedDecl *New; }; DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); @@ -2145,13 +2153,11 @@ class Sema { }; Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, - SourceLocation KWLoc, CXXScopeSpec &SS, - IdentifierInfo *Name, SourceLocation NameLoc, - AttributeList *Attr, AccessSpecifier AS, - SourceLocation ModulePrivateLoc, - MultiTemplateParamsArg TemplateParameterLists, - bool &OwnedDecl, bool &IsDependent, - SourceLocation ScopedEnumKWLoc, + SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, + SourceLocation NameLoc, AttributeList *Attr, + AccessSpecifier AS, SourceLocation ModulePrivateLoc, + MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, + bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, SkipBodyInfo *SkipBody = nullptr); @@ -2219,6 +2225,12 @@ class Sema { /// struct, or union). void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); + /// Perform ODR-like check for C/ObjC when merging tag types from modules. + /// Differently from C++, actually parse the body and reject / error out + /// in case of a structural mismatch. + bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, + SkipBodyInfo &SkipBody); + typedef void *SkippedDefinitionContext; /// \brief Invoked when we enter a tag definition that we're skipping. @@ -2272,8 +2284,8 @@ class Sema { Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, - AttributeList *Attrs, - SourceLocation EqualLoc, Expr *Val); + AttributeList *Attrs, SourceLocation EqualLoc, + Expr *Val); void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, Decl *EnumDecl, ArrayRef Elements, diff --git a/lib/AST/ASTStructuralEquivalence.cpp b/lib/AST/ASTStructuralEquivalence.cpp index eff1aa5e323d..ea7faab767ed 100644 --- a/lib/AST/ASTStructuralEquivalence.cpp +++ b/lib/AST/ASTStructuralEquivalence.cpp @@ -735,13 +735,28 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // Check for equivalent field names. IdentifierInfo *Name1 = Field1->getIdentifier(); IdentifierInfo *Name2 = Field2->getIdentifier(); - if (!::IsStructurallyEquivalent(Name1, Name2)) + if (!::IsStructurallyEquivalent(Name1, Name2)) { + if (Context.Complain) { + Context.Diag2(Owner2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) + << Context.ToCtx.getTypeDeclType(Owner2); + Context.Diag2(Field2->getLocation(), diag::note_odr_field_name) + << Field2->getDeclName(); + Context.Diag1(Field1->getLocation(), diag::note_odr_field_name) + << Field1->getDeclName(); + } return false; + } if (!IsStructurallyEquivalent(Context, Field1->getType(), Field2->getType())) { if (Context.Complain) { - Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(Owner2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(Owner2); Context.Diag2(Field2->getLocation(), diag::note_odr_field) << Field2->getDeclName() << Field2->getType(); @@ -753,7 +768,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, if (Field1->isBitField() != Field2->isBitField()) { if (Context.Complain) { - Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(Owner2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(Owner2); if (Field1->isBitField()) { Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field) @@ -780,7 +798,9 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, if (Bits1 != Bits2) { if (Context.Complain) { Context.Diag2(Owner2->getLocation(), - diag::warn_odr_tag_type_inconsistent) + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(Owner2); Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field) << Field2->getDeclName() << Field2->getType() << Bits2; @@ -799,7 +819,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, RecordDecl *D1, RecordDecl *D2) { if (D1->isUnion() != D2->isUnion()) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here) << D1->getDeclName() << (unsigned)D1->getTagKind(); @@ -927,7 +950,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, Field1 != Field1End; ++Field1, ++Field2) { if (Field2 == Field2End) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag1(Field1->getLocation(), diag::note_odr_field) << Field1->getDeclName() << Field1->getType(); @@ -942,7 +968,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, if (Field2 != Field2End) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag2(Field2->getLocation(), diag::note_odr_field) << Field2->getDeclName() << Field2->getType(); @@ -964,7 +993,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, EC1 != EC1End; ++EC1, ++EC2) { if (EC2 == EC2End) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator) << EC1->getDeclName() << EC1->getInitVal().toString(10); @@ -978,7 +1010,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, if (!llvm::APSInt::isSameValue(Val1, Val2) || !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator) << EC2->getDeclName() << EC2->getInitVal().toString(10); @@ -991,7 +1026,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, if (EC2 != EC2End) { if (Context.Complain) { - Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) + Context.Diag2(D2->getLocation(), + Context.ErrorOnTagTypeMismatch + ? diag::err_odr_tag_type_inconsistent + : diag::warn_odr_tag_type_inconsistent) << Context.ToCtx.getTypeDeclType(D2); Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator) << EC2->getDeclName() << EC2->getInitVal().toString(10); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 06a9d70144d7..07054546f42f 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4319,8 +4319,15 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, return; } - if (Tok.is(tok::l_brace) && TUK != Sema::TUK_Reference) - ParseEnumBody(StartLoc, TagDecl); + if (Tok.is(tok::l_brace) && TUK != Sema::TUK_Reference) { + Decl *D = SkipBody.CheckSameAsPrevious ? SkipBody.New : TagDecl; + ParseEnumBody(StartLoc, D); + if (SkipBody.CheckSameAsPrevious && + !Actions.ActOnDuplicateDefinition(DS, TagDecl, SkipBody)) { + DS.SetTypeSpecError(); + return; + } + } if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, NameLoc.isValid() ? NameLoc : StartLoc, @@ -4392,11 +4399,9 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { } // Install the enumerator constant into EnumDecl. - Decl *EnumConstDecl = Actions.ActOnEnumConstant(getCurScope(), EnumDecl, - LastEnumConstDecl, - IdentLoc, Ident, - attrs.getList(), EqualLoc, - AssignedVal.get()); + Decl *EnumConstDecl = Actions.ActOnEnumConstant( + getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, + attrs.getList(), EqualLoc, AssignedVal.get()); EnumAvailabilityDiags.back().done(); EnumConstantDecls.push_back(EnumConstDecl); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index b1a84e7ab943..2301284b7f43 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1910,8 +1910,18 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, else if (getLangOpts().CPlusPlus) ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType, TagOrTempResult.get()); - else - ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); + else { + Decl *D = + SkipBody.CheckSameAsPrevious ? SkipBody.New : TagOrTempResult.get(); + // Parse the definition body. + ParseStructUnionBody(StartLoc, TagType, D); + if (SkipBody.CheckSameAsPrevious && + !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.get(), + SkipBody)) { + DS.SetTypeSpecError(); + return; + } + } } if (!TagOrTempResult.isInvalid()) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index fd172def2dfe..59bfa49066c5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -13233,6 +13233,55 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, if (TUK == TUK_Friend || TUK == TUK_Reference) Redecl = NotForRedeclaration; + /// Create a new tag decl in C/ObjC. Since the ODR-like semantics for ObjC/C + /// implemented asks for structural equivalence checking, the returned decl + /// here is passed back to the parser, allowing the tag body to be parsed. + auto createTagFromNewDecl = [&]() -> TagDecl * { + assert(!getLangOpts().CPlusPlus && "not meant for C++ usage"); + // If there is an identifier, use the location of the identifier as the + // location of the decl, otherwise use the location of the struct/union + // keyword. + SourceLocation Loc = NameLoc.isValid() ? NameLoc : KWLoc; + TagDecl *New = nullptr; + + if (Kind == TTK_Enum) { + New = EnumDecl::Create(Context, SearchDC, KWLoc, Loc, Name, nullptr, + ScopedEnum, ScopedEnumUsesClassTag, + !EnumUnderlying.isNull()); + // If this is an undefined enum, bail. + if (TUK != TUK_Definition && !Invalid) + return nullptr; + if (EnumUnderlying) { + EnumDecl *ED = cast(New); + if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast()) + ED->setIntegerTypeSourceInfo(TI); + else + ED->setIntegerType(QualType(EnumUnderlying.get(), 0)); + ED->setPromotionType(ED->getIntegerType()); + } + } else { // struct/union + New = RecordDecl::Create(Context, Kind, SearchDC, KWLoc, Loc, Name, + nullptr); + } + + if (RecordDecl *RD = dyn_cast(New)) { + // Add alignment attributes if necessary; these attributes are checked + // when the ASTContext lays out the structure. + // + // It is important for implementing the correct semantics that this + // happen here (in ActOnTag). The #pragma pack stack is + // maintained as a result of parser callbacks which can occur at + // many points during the parsing of a struct declaration (because + // the #pragma tokens are effectively skipped over during the + // parsing of the struct). + if (TUK == TUK_Definition) { + AddAlignmentAttributesForRecord(RD); + AddMsStructLayoutForRecord(RD); + } + } + return New; + }; + LookupResult Previous(*this, Name, NameLoc, LookupTagName, Redecl); if (Name && SS.isNotEmpty()) { // We have a nested-name tag ('struct foo::bar'). @@ -13638,16 +13687,28 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, TSK_ExplicitSpecialization; } + // Note that clang allows ODR-like semantics for ObjC/C, i.e., do + // not keep more that one definition around (merge them). However, + // ensure the decl passes the structural compatibility check in + // C11 6.2.7/1 (or 6.1.2.6/1 in C89). NamedDecl *Hidden = nullptr; - if (SkipBody && getLangOpts().CPlusPlus && - !hasVisibleDefinition(Def, &Hidden)) { + if (SkipBody && !hasVisibleDefinition(Def, &Hidden)) { // There is a definition of this tag, but it is not visible. We // explicitly make use of C++'s one definition rule here, and // assume that this definition is identical to the hidden one // we already have. Make the existing definition visible and // use it in place of this one. - SkipBody->ShouldSkip = true; - makeMergedDefinitionVisible(Hidden); + if (!getLangOpts().CPlusPlus) { + // Postpone making the old definition visible until after we + // complete parsing the new one and do the structural + // comparison. + SkipBody->CheckSameAsPrevious = true; + SkipBody->New = createTagFromNewDecl(); + SkipBody->Previous = Hidden; + } else { + SkipBody->ShouldSkip = true; + makeMergedDefinitionVisible(Hidden); + } return Def; } else if (!IsExplicitSpecializationAfterInstantiation) { // A redeclaration in function prototype scope in C isn't @@ -13875,7 +13936,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // the ASTContext lays out the structure. // // It is important for implementing the correct semantics that this - // happen here (in act on tag decl). The #pragma pack stack is + // happen here (in ActOnTag). The #pragma pack stack is // maintained as a result of parser callbacks which can occur at // many points during the parsing of a struct declaration (because // the #pragma tokens are effectively skipped over during the @@ -14011,6 +14072,16 @@ void Sema::ActOnTagStartDefinition(Scope *S, Decl *TagD) { AddPushedVisibilityAttribute(Tag); } +bool Sema::ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, + SkipBodyInfo &SkipBody) { + if (!hasStructuralCompatLayout(Prev, SkipBody.New)) + return false; + + // Make the previous decl visible. + makeMergedDefinitionVisible(SkipBody.Previous); + return true; +} + Decl *Sema::ActOnObjCContainerStartDefinition(Decl *IDecl) { assert(isa(IDecl) && "ActOnObjCContainerStartDefinition - Not ObjCContainerDecl"); @@ -15432,7 +15503,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst, // different from T: // - every enumerator of every member of class T that is an unscoped // enumerated type - if (!TheEnumDecl->isScoped()) + if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped()) DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(), DeclarationNameInfo(Id, IdLoc)); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 8c8402e75e37..b19dcb2a5099 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTMutationListener.h" +#include "clang/AST/ASTStructuralEquivalence.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" @@ -7111,6 +7112,20 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, return false; } +bool Sema::hasStructuralCompatLayout(Decl *D, Decl *Suggested) { + llvm::DenseSet> NonEquivalentDecls; + if (!Suggested) + return false; + + // FIXME: Add a specific mode for C11 6.2.7/1 in StructuralEquivalenceContext + // and isolate from other C++ specific checks. + StructuralEquivalenceContext Ctx( + D->getASTContext(), Suggested->getASTContext(), NonEquivalentDecls, + false /*StrictTypeSpelling*/, true /*Complain*/, + true /*ErrorOnTagTypeMismatch*/); + return Ctx.IsStructurallyEquivalent(D, Suggested); +} + /// \brief Determine whether there is any declaration of \p D that was ever a /// definition (perhaps before module merging) and is currently visible. /// \param D The definition of the entity. diff --git a/test/Modules/Inputs/F.framework/Headers/F.h b/test/Modules/Inputs/F.framework/Headers/F.h new file mode 100644 index 000000000000..4f705f00e1ac --- /dev/null +++ b/test/Modules/Inputs/F.framework/Headers/F.h @@ -0,0 +1 @@ +// F.h diff --git a/test/Modules/Inputs/F.framework/Modules/module.modulemap b/test/Modules/Inputs/F.framework/Modules/module.modulemap new file mode 100644 index 000000000000..e414776c536b --- /dev/null +++ b/test/Modules/Inputs/F.framework/Modules/module.modulemap @@ -0,0 +1,7 @@ +framework module F [extern_c] [system] { + umbrella header "F.h" + module * { + export * + } + export * +} diff --git a/test/Modules/Inputs/F.framework/Modules/module.private.modulemap b/test/Modules/Inputs/F.framework/Modules/module.private.modulemap new file mode 100644 index 000000000000..69486a2a6410 --- /dev/null +++ b/test/Modules/Inputs/F.framework/Modules/module.private.modulemap @@ -0,0 +1,7 @@ +module F.Private [system] { + explicit module NS { + header "NS.h" + export * + } + export * +} diff --git a/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h b/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h new file mode 100644 index 000000000000..5e947ba90518 --- /dev/null +++ b/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h @@ -0,0 +1,19 @@ +struct NS { + int a; + int b; +}; + +enum NSE { + FST = 22, + SND = 43, + TRD = 55 +}; + +#define NS_ENUM(_type, _name) \ + enum _name : _type _name; \ + enum _name : _type + +typedef NS_ENUM(int, NSMyEnum) { + MinX = 11, + MinXOther = MinX, +}; diff --git a/test/Modules/elaborated-type-specifier-from-hidden-module.m b/test/Modules/elaborated-type-specifier-from-hidden-module.m index 0ca1c24bba00..571ccb9d95c0 100644 --- a/test/Modules/elaborated-type-specifier-from-hidden-module.m +++ b/test/Modules/elaborated-type-specifier-from-hidden-module.m @@ -4,12 +4,11 @@ @import ElaboratedTypeStructs.Empty; // The structs are now hidden. struct S1 *x; struct S2 *y; -// FIXME: compatible definition should not be an error. -struct S2 { int x; }; // expected-error {{redefinition}} +struct S2 { int x; }; struct S3 *z; // Incompatible definition. -struct S3 { float y; }; // expected-error {{redefinition}} -// expected-note@elaborated-type-structs.h:* 2 {{previous definition is here}} +struct S3 { float y; }; // expected-error {{has incompatible definitions}} // expected-note {{field has name}} +// expected-note@Inputs/elaborated-type-structs.h:3 {{field has name}} @import ElaboratedTypeStructs.Structs; diff --git a/test/Modules/redefinition-c-tagtypes.m b/test/Modules/redefinition-c-tagtypes.m new file mode 100644 index 000000000000..a01f11bd74c8 --- /dev/null +++ b/test/Modules/redefinition-c-tagtypes.m @@ -0,0 +1,48 @@ +// RUN: rm -rf %t.cache +// RUN: %clang_cc1 -fsyntax-only %s -fmodules -fmodules-cache-path=%t.cache \ +// RUN: -fimplicit-module-maps -F%S/Inputs -verify +// RUN: %clang_cc1 -fsyntax-only %s -fmodules -fmodules-cache-path=%t.cache \ +// RUN: -fimplicit-module-maps -F%S/Inputs -DCHANGE_TAGS -verify +#include "F/F.h" + +#ifndef CHANGE_TAGS +// expected-no-diagnostics +#endif + +struct NS { + int a; +#ifndef CHANGE_TAGS + int b; +#else + int c; // expected-note {{field has name 'c' here}} + // expected-error@redefinition-c-tagtypes.m:12 {{type 'struct NS' has incompatible definitions}} + // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:3 {{field has name 'b' here}} +#endif +}; + +enum NSE { + FST = 22, +#ifndef CHANGE_TAGS + SND = 43, +#else + SND = 44, // expected-note {{enumerator 'SND' with value 44 here}} + // expected-error@redefinition-c-tagtypes.m:23 {{type 'enum NSE' has incompatible definitions}} + // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:8 {{enumerator 'SND' with value 43 here}} +#endif + TRD = 55 +}; + +#define NS_ENUM(_type, _name) \ + enum _name : _type _name; \ + enum _name : _type + +typedef NS_ENUM(int, NSMyEnum) { + MinX = 11, +#ifndef CHANGE_TAGS + MinXOther = MinX, +#else + MinXOther = TRD, // expected-note {{enumerator 'MinXOther' with value 55 here}} + // expected-error@redefinition-c-tagtypes.m:39 {{type 'enum NSMyEnum' has incompatible definitions}} + // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:18 {{enumerator 'MinXOther' with value 11 here}} +#endif +}; diff --git a/test/Modules/redefinition-same-header.m b/test/Modules/redefinition-same-header.m index f1c6cbbcaa2e..8c180f643225 100644 --- a/test/Modules/redefinition-same-header.m +++ b/test/Modules/redefinition-same-header.m @@ -6,15 +6,7 @@ // expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} // expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} // expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} +// expected-warning@Inputs/SameHeader/C.h:9 {{typedef requires a name}} -// expected-error@Inputs/SameHeader/C.h:5 {{redefinition of 'aaa'}} -// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} -// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} -// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} - -// expected-error@Inputs/SameHeader/C.h:9 {{redefinition of 'fd_set'}} -// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} -// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} -// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} #include "A.h" // maps to a modular #include "C.h" // textual include From 2fa920a582d0d13b17f0f9855d221e5f4a78f4c0 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Sat, 1 Jul 2017 00:57:52 +0000 Subject: [PATCH 176/214] [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit. The following changes are made to the driver since 32-bit apps do not run on iOS 11 or later: - If the deployment target is set explicitly, either with a command-line option or an environment variable, the driver should report an error if the version is greater than iOS 10. - In the case where the deployment target is not set explicitly and the default is inferred from the target triple or SDK version, it should use a maximum default of iOS 10.99.99. rdar://problem/32230613 Differential Revision: https://reviews.llvm.org/D34529 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306922 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 3 ++ lib/Driver/ToolChains/Darwin.cpp | 28 ++++++++++++++-- test/Driver/darwin-version.c | 35 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index eb6dd37c148d..1a731975b3fe 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -138,6 +138,9 @@ def err_drv_cc_print_options_failure : Error< def err_drv_lto_without_lld : Error<"LTO requires -fuse-ld=lld">; def err_drv_preamble_format : Error< "incorrect format for -preamble-bytes=N,END">; +def err_invalid_ios_deployment_target : Error< + "invalid iOS deployment version '%0', iOS 10 is the maximum deployment " + "target for 32-bit targets">; def err_drv_conflicting_deployment_targets : Error< "conflicting deployment targets, both '%0' and '%1' are present in environment">; def err_arc_unsupported_on_runtime : Error< diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index b1f359e8a1fc..589c4b7f90f4 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1150,6 +1150,17 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { Args.getLastArg(options::OPT_mwatchos_version_min_EQ, options::OPT_mwatchos_simulator_version_min_EQ); + 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); + // 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. if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) || @@ -1191,6 +1202,14 @@ 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 there is no command-line argument to specify the Target version and // no environment variable defined, see if we can set the default based // on -isysroot. @@ -1308,8 +1327,6 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { llvm_unreachable("Unable to infer Darwin variant"); // Set the tool chain target information. - unsigned Major, Minor, Micro; - bool HadExtra; if (Platform == MacOS) { assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && "Unknown target platform!"); @@ -1325,6 +1342,13 @@ 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. + if (getTriple().isArch32Bit() && Major >= 11) { + Major = 10; + Minor = 99; + Micro = 99; + } } else if (Platform == TvOS) { if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, Micro, HadExtra) || HadExtra || diff --git a/test/Driver/darwin-version.c b/test/Driver/darwin-version.c index 8f08bb9dec4a..c11a2df37f98 100644 --- a/test/Driver/darwin-version.c +++ b/test/Driver/darwin-version.c @@ -10,6 +10,41 @@ // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-IOS3 %s // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0" + +// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \ +// RUN: %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err +// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s +// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0' + +// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err +// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s +// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0' + +// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err +// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS6 %s +// CHECK-VERSION-IOS6: invalid iOS deployment version '-mios-simulator-version-min=11.0' + +// RUN: %clang -target armv7-apple-ios11.1 -c -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS7 %s +// CHECK-VERSION-IOS7: thumbv7-apple-ios10.99.99 + +// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \ +// RUN: %clang -target arm64-apple-ios11.0 -c -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS8 %s +// CHECK-VERSION-IOS8: arm64-apple-ios11.0.0 + +// RUN: %clang -target arm64-apple-ios11.0 -miphoneos-version-min=11.0 -c -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS9 %s +// CHECK-VERSION-IOS9: arm64-apple-ios11.0.0 + +// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s +// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0 + +// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s +// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0 + // RUN: %clang -target i686-apple-darwin8 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-OSX4 %s // RUN: %clang -target i686-apple-darwin9 -mmacosx-version-min=10.4 -c %s -### 2>&1 | \ From da9338098f080931194e2272e54827c445feb00b Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Sat, 1 Jul 2017 02:00:05 +0000 Subject: [PATCH 177/214] [ODRHash] Revert r305104 - Skip inline namespaces when hashing. Test inline namespaces and handle them in the ODR hash again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306926 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ODRHash.cpp | 27 +++++++++------------------ lib/AST/StmtProfile.cpp | 5 ++++- test/Modules/odr_hash.cpp | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index 0e44a12257cb..3f66e58eb868 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -82,25 +82,13 @@ void ODRHash::AddDeclarationName(DeclarationName Name) { } void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) { - // Unlike the other pointer handling functions, allow null pointers here. - if (!NNS) { - AddBoolean(false); - return; + assert(NNS && "Expecting non-null pointer."); + const auto *Prefix = NNS->getPrefix(); + AddBoolean(Prefix); + if (Prefix) { + AddNestedNameSpecifier(Prefix); } - - // Skip inlined namespaces. auto Kind = NNS->getKind(); - if (Kind == NestedNameSpecifier::Namespace) { - if (NNS->getAsNamespace()->isInline()) { - return AddNestedNameSpecifier(NNS->getPrefix()); - } - } - - AddBoolean(true); - - // Process prefix - AddNestedNameSpecifier(NNS->getPrefix()); - ID.AddInteger(Kind); switch (Kind) { case NestedNameSpecifier::Identifier: @@ -441,7 +429,10 @@ class ODRTypeVisitor : public TypeVisitor { } void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) { - Hash.AddNestedNameSpecifier(NNS); + Hash.AddBoolean(NNS); + if (NNS) { + Hash.AddNestedNameSpecifier(NNS); + } } void AddIdentifierInfo(const IdentifierInfo *II) { diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 99a25f342526..f1fbe2806b5d 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -186,7 +186,10 @@ namespace { Hash.AddTemplateName(Name); } void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override { - Hash.AddNestedNameSpecifier(NNS); + ID.AddBoolean(NNS); + if (NNS) { + Hash.AddNestedNameSpecifier(NNS); + } } }; } diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index 3b213971696c..6e01e989a374 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -968,6 +968,24 @@ S9 s9; // expected-error@second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}} // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}} #endif + +namespace N10 { +#if defined(FIRST) +inline namespace A { struct X {}; } +struct S10 { + A::X x; +}; +#elif defined(SECOND) +inline namespace B { struct X {}; } +struct S10 { + B::X x; +}; +#else +S10 s10; +// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}} +// expected-note@first.h:* {{declaration of 'x' does not match}} +#endif +} } namespace TemplateSpecializationType { From 5dd23a26beff8678f71dd675ccc37eccf3c68886 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Sat, 1 Jul 2017 02:55:23 +0000 Subject: [PATCH 178/214] Update clang support for -mexecute-only/-mpure-code for backend change to use subtarget feature rather than command line option. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306928 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Arch/ARM.cpp | 4 +- test/CodeGen/arm-execute-only.c | 78 ++++++++++++++++++++++++++++++ test/Driver/arm-execute-only.c | 72 --------------------------- 3 files changed, 79 insertions(+), 75 deletions(-) create mode 100644 test/CodeGen/arm-execute-only.c diff --git a/lib/Driver/ToolChains/Arch/ARM.cpp b/lib/Driver/ToolChains/Arch/ARM.cpp index 4eac97620114..8cafd3c74bfb 100644 --- a/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/lib/Driver/ToolChains/Arch/ARM.cpp @@ -392,9 +392,7 @@ void arm::getARMTargetFeatures(const ToolChain &TC, if (B->getOption().matches(options::OPT_mlong_calls)) D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args); } - - CmdArgs.push_back("-backend-option"); - CmdArgs.push_back("-arm-execute-only"); + Features.push_back("+execute-only"); } } } diff --git a/test/CodeGen/arm-execute-only.c b/test/CodeGen/arm-execute-only.c new file mode 100644 index 000000000000..6d88ff611d68 --- /dev/null +++ b/test/CodeGen/arm-execute-only.c @@ -0,0 +1,78 @@ +// RUN: %clang -target armv6t2-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv6t2-eabi -### -mexecute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv6t2-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### -mexecute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### -mexecute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### -mexecute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + + +// -mpure-code flag for GCC compatibility +// RUN: %clang -target armv6t2-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv6t2-eabi -### -mpure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv6t2-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### -mpure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv7m-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### -mpure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv8m.base-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### -mpure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target armv8m.main-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// CHECK-NO-EXECUTE-ONLY-NOT: "+execute-only" +// CHECK-EXECUTE-ONLY: "+execute-only" + +void a() {} diff --git a/test/Driver/arm-execute-only.c b/test/Driver/arm-execute-only.c index a4854485e1e4..c226a7f3b4b1 100644 --- a/test/Driver/arm-execute-only.c +++ b/test/Driver/arm-execute-only.c @@ -1,39 +1,3 @@ -// RUN: %clang -target armv6t2-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv6t2-eabi -### -mexecute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv6t2-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### -mexecute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### -mexecute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### -mexecute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### -mexecute-only -mno-execute-only %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - // RUN: not %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \ // RUN: FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s @@ -45,42 +9,6 @@ // -mpure-code flag for GCC compatibility -// RUN: %clang -target armv6t2-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv6t2-eabi -### -mpure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv6t2-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### -mpure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv7m-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### -mpure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv8m.base-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### -mpure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY - -// RUN: %clang -target armv8m.main-eabi -### -mpure-code -mno-pure-code %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY - // RUN: not %clang -c -target thumbv6m-eabi -mpure-code %s 2>&1 | \ // RUN: FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s From 481160d03b45795911edb42471f199d35db7de08 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Sat, 1 Jul 2017 04:37:54 +0000 Subject: [PATCH 179/214] Fix indentation. This is an attempt to fix a failing bot: http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306944 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Darwin.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 589c4b7f90f4..7b61095c3ba9 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1342,13 +1342,13 @@ 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. - if (getTriple().isArch32Bit() && Major >= 11) { - Major = 10; - Minor = 99; - Micro = 99; - } + // 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. + if (getTriple().isArch32Bit() && Major >= 11) { + Major = 10; + Minor = 99; + Micro = 99; + } } else if (Platform == TvOS) { if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, Micro, HadExtra) || HadExtra || From 65139b8e3f4c84793ebd60966a1c6f18cef29ca4 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Sat, 1 Jul 2017 04:44:38 +0000 Subject: [PATCH 180/214] [Driver] Add -fdiagnostics-hotness-threshold Summary: Depends on https://reviews.llvm.org/D34867. Add a Clang frontend option to enable optimization remark hotness thresholds, which were added to LLVM in https://reviews.llvm.org/D34867. This prevents diagnostics that do not meet a minimum hotness threshold from being output. When generating optimization remarks for large codebases with a ton of cold code paths, this option can be used to limit the optimization remark output at a reasonable size. Discussion of this change can be read here: http://lists.llvm.org/pipermail/llvm-dev/2017-June/114377.html Reviewers: anemet, davidxl, hfinkel Reviewed By: anemet Subscribers: fhahn, cfe-commits Differential Revision: https://reviews.llvm.org/D34868 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306945 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsersManual.rst | 40 +++++++++++++++---- include/clang/Basic/DiagnosticDriverKinds.td | 4 +- include/clang/Driver/Options.td | 3 ++ include/clang/Frontend/CodeGenOptions.def | 4 ++ lib/CodeGen/CodeGenAction.cpp | 3 ++ lib/Driver/ToolChains/Clang.cpp | 6 +++ lib/Frontend/CompilerInvocation.cpp | 18 ++++++--- ...zation-remark-with-hotness-sample.proftext | 2 +- .../optimization-remark-with-hotness.c | 20 ++++++++-- 9 files changed, 80 insertions(+), 20 deletions(-) diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index 7362456202ba..ae038b21f2e1 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -322,18 +322,27 @@ output format of the diagnostics that it generates. by category, so it should be a high level category. We want dozens of these, not hundreds or thousands of them. +.. _opt_fsave-optimization-record: + +**-fsave-optimization-record** + Write optimization remarks to a YAML file. + + This option, which defaults to off, controls whether Clang writes + optimization reports to a YAML file. By recording diagnostics in a file, + using a structured YAML format, users can parse or sort the remarks in a + convenient way. + .. _opt_fdiagnostics-show-hotness: **-f[no-]diagnostics-show-hotness** Enable profile hotness information in diagnostic line. - This option, which defaults to off, controls whether Clang prints the - profile hotness associated with a diagnostics in the presence of - profile-guided optimization information. This is currently supported with - optimization remarks (see :ref:`Options to Emit Optimization Reports - `). The hotness information allows users to focus on the hot - optimization remarks that are likely to be more relevant for run-time - performance. + This option controls whether Clang prints the profile hotness associated + with diagnostics in the presence of profile-guided optimization information. + This is currently supported with optimization remarks (see + :ref:`Options to Emit Optimization Reports `). The hotness information + allows users to focus on the hot optimization remarks that are likely to be + more relevant for run-time performance. For example, in this output, the block containing the callsite of `foo` was executed 3000 times according to the profile data: @@ -344,6 +353,23 @@ output format of the diagnostics that it generates. sum += foo(x, x - 2); ^ + This option is implied when + :ref:`-fsave-optimization-record ` is used. + Otherwise, it defaults to off. + +.. _opt_fdiagnostics-hotness-threshold + +**-fdiagnostics-hotness-threshold** + Prevent optimization remarks from being output if they do not have at least + this hotness value. + + This option, which defaults to zero, controls the minimum hotness an + optimization remark would need in order to be output by Clang. This is + currently supported with optimization remarks (see :ref:`Options to Emit + Optimization Reports `) when profile hotness information in + diagnostics is enabled (see + :ref:`-fdiagnostics-show-hotness `). + .. _opt_fdiagnostics-fixit-info: **-f[no-]diagnostics-fixit-info** diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 1a731975b3fe..42e1e5edaf9e 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -198,8 +198,8 @@ def warn_drv_unused_argument : Warning< def warn_drv_empty_joined_argument : Warning< "joined argument expects additional value: '%0'">, InGroup; -def warn_drv_fdiagnostics_show_hotness_requires_pgo : Warning< - "argument '-fdiagnostics-show-hotness' requires profile-guided optimization information">, +def warn_drv_diagnostics_hotness_requires_pgo : Warning< + "argument '%0' requires profile-guided optimization information">, InGroup; def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 90791fbfd4e1..b65b984731f6 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -723,6 +723,9 @@ def fdiagnostics_print_source_range_info : Flag<["-"], "fdiagnostics-print-sourc HelpText<"Print source range spans in numeric form">; def fdiagnostics_show_hotness : Flag<["-"], "fdiagnostics-show-hotness">, Group, Flags<[CC1Option]>, HelpText<"Enable profile hotness information in diagnostic line">; +def fdiagnostics_hotness_threshold_EQ : Joined<["-"], "fdiagnostics-hotness-threshold=">, + Group, Flags<[CC1Option]>, MetaVarName<"">, + HelpText<"Prevent optimization remarks from being output if they do not have at least this profile count">; def fdiagnostics_show_option : Flag<["-"], "fdiagnostics-show-option">, Group, Flags<[CC1Option]>, HelpText<"Print option name with mappable diagnostics">; def fdiagnostics_show_note_include_stack : Flag<["-"], "fdiagnostics-show-note-include-stack">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 6eac39c75356..238bb231bdf5 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -261,6 +261,10 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0) /// Whether to report the hotness of the code region for optimization remarks. CODEGENOPT(DiagnosticsWithHotness, 1, 0) +/// The minimum hotness value a diagnostic needs in order to be included in +/// optimization diagnostics. +VALUE_CODEGENOPT(DiagnosticsHotnessThreshold, 32, 0) + /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index ba033d9413c1..4f03de55149b 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -229,6 +229,9 @@ namespace clang { void *OldDiagnosticContext = Ctx.getDiagnosticContext(); Ctx.setDiagnosticHandler(DiagnosticHandler, this); Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); + if (CodeGenOpts.DiagnosticsHotnessThreshold != 0) + Ctx.setDiagnosticsHotnessThreshold( + CodeGenOpts.DiagnosticsHotnessThreshold); std::unique_ptr OptRecordFile; if (!CodeGenOpts.OptRecordFile.empty()) { diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 342d628396da..3731aa83ef06 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4043,6 +4043,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_show_hotness, false)) CmdArgs.push_back("-fdiagnostics-show-hotness"); + if (const Arg *A = + Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) { + std::string Opt = std::string("-fdiagnostics-hotness-threshold=") + A->getValue(); + CmdArgs.push_back(Args.MakeArgString(Opt)); + } + if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); CmdArgs.push_back(A->getValue()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b1b10ddf965c..5851595dab7b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -909,12 +909,18 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DiagnosticsWithHotness = Args.hasArg(options::OPT_fdiagnostics_show_hotness); bool UsingSampleProfile = !Opts.SampleProfileFile.empty(); - - if (Opts.DiagnosticsWithHotness && - Opts.getProfileUse() == CodeGenOptions::ProfileNone && - !UsingSampleProfile) { - Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo); - } + bool UsingProfile = UsingSampleProfile || + (Opts.getProfileUse() != CodeGenOptions::ProfileNone); + + if (Opts.DiagnosticsWithHotness && !UsingProfile) + Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) + << "-fdiagnostics-show-hotness"; + + Opts.DiagnosticsHotnessThreshold = getLastArgUInt64Value( + Args, options::OPT_fdiagnostics_hotness_threshold_EQ, 0); + if (Opts.DiagnosticsHotnessThreshold > 0 && !UsingProfile) + Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) + << "-fdiagnostics-hotness-threshold="; // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile diff --git a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext index aeea583de4d4..730dc4a0d5b1 100644 --- a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext +++ b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext @@ -1,7 +1,7 @@ foo:0:0 0: 0 bar:29:29 - 6: foo:0 + 9: foo:0 main:0:0 0: 0 bar:0 diff --git a/test/Frontend/optimization-remark-with-hotness.c b/test/Frontend/optimization-remark-with-hotness.c index 30ead64b8eb5..875fc75ae159 100644 --- a/test/Frontend/optimization-remark-with-hotness.c +++ b/test/Frontend/optimization-remark-with-hotness.c @@ -15,12 +15,14 @@ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -verify +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ +// RUN: -verify // The clang version of the previous test. // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \ // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -Xclang -verify +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ +// RUN: -Xclang -verify // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ @@ -28,11 +30,18 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ -// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ +// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ // RUN: -check-prefix=HOTNESS_OFF %s // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ -// RUN: -Rpass=inline -Rpass-analysis=inline -fdiagnostics-show-hotness 2>&1 \ +// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness \ +// RUN: -fdiagnostics-hotness-threshold=100 2>&1 \ +// RUN: | FileCheck -allow-empty -check-prefix=THRESHOLD %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -Rpass=inline -Rpass-analysis=inline \ +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 2>&1 \ // RUN: | FileCheck -check-prefix=NO_PGO %s int foo(int x, int y) __attribute__((always_inline)); @@ -43,7 +52,10 @@ int sum = 0; void bar(int x) { // HOTNESS_OFF: foo inlined into bar // HOTNESS_OFF-NOT: hotness: + // THRESHOLD-NOT: inlined + // THRESHOLD-NOT: hotness // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information + // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information // expected-remark@+2 {{foo should always be inlined (cost=always) (hotness: 30)}} // expected-remark@+1 {{foo inlined into bar (hotness: 30)}} sum += foo(x, x - 2); From 315a27e4b8ea54421d9c1de57fe1e2ce2852580f Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Sat, 1 Jul 2017 04:54:53 +0000 Subject: [PATCH 181/214] Revert "[Driver] Add -fdiagnostics-hotness-threshold" Summary: The commit caused a documentation breakage. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306946 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsersManual.rst | 40 ++++--------------- include/clang/Basic/DiagnosticDriverKinds.td | 4 +- include/clang/Driver/Options.td | 3 -- include/clang/Frontend/CodeGenOptions.def | 4 -- lib/CodeGen/CodeGenAction.cpp | 3 -- lib/Driver/ToolChains/Clang.cpp | 6 --- lib/Frontend/CompilerInvocation.cpp | 18 +++------ ...zation-remark-with-hotness-sample.proftext | 2 +- .../optimization-remark-with-hotness.c | 20 ++-------- 9 files changed, 20 insertions(+), 80 deletions(-) diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index ae038b21f2e1..7362456202ba 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -322,27 +322,18 @@ output format of the diagnostics that it generates. by category, so it should be a high level category. We want dozens of these, not hundreds or thousands of them. -.. _opt_fsave-optimization-record: - -**-fsave-optimization-record** - Write optimization remarks to a YAML file. - - This option, which defaults to off, controls whether Clang writes - optimization reports to a YAML file. By recording diagnostics in a file, - using a structured YAML format, users can parse or sort the remarks in a - convenient way. - .. _opt_fdiagnostics-show-hotness: **-f[no-]diagnostics-show-hotness** Enable profile hotness information in diagnostic line. - This option controls whether Clang prints the profile hotness associated - with diagnostics in the presence of profile-guided optimization information. - This is currently supported with optimization remarks (see - :ref:`Options to Emit Optimization Reports `). The hotness information - allows users to focus on the hot optimization remarks that are likely to be - more relevant for run-time performance. + This option, which defaults to off, controls whether Clang prints the + profile hotness associated with a diagnostics in the presence of + profile-guided optimization information. This is currently supported with + optimization remarks (see :ref:`Options to Emit Optimization Reports + `). The hotness information allows users to focus on the hot + optimization remarks that are likely to be more relevant for run-time + performance. For example, in this output, the block containing the callsite of `foo` was executed 3000 times according to the profile data: @@ -353,23 +344,6 @@ output format of the diagnostics that it generates. sum += foo(x, x - 2); ^ - This option is implied when - :ref:`-fsave-optimization-record ` is used. - Otherwise, it defaults to off. - -.. _opt_fdiagnostics-hotness-threshold - -**-fdiagnostics-hotness-threshold** - Prevent optimization remarks from being output if they do not have at least - this hotness value. - - This option, which defaults to zero, controls the minimum hotness an - optimization remark would need in order to be output by Clang. This is - currently supported with optimization remarks (see :ref:`Options to Emit - Optimization Reports `) when profile hotness information in - diagnostics is enabled (see - :ref:`-fdiagnostics-show-hotness `). - .. _opt_fdiagnostics-fixit-info: **-f[no-]diagnostics-fixit-info** diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 42e1e5edaf9e..1a731975b3fe 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -198,8 +198,8 @@ def warn_drv_unused_argument : Warning< def warn_drv_empty_joined_argument : Warning< "joined argument expects additional value: '%0'">, InGroup; -def warn_drv_diagnostics_hotness_requires_pgo : Warning< - "argument '%0' requires profile-guided optimization information">, +def warn_drv_fdiagnostics_show_hotness_requires_pgo : Warning< + "argument '-fdiagnostics-show-hotness' requires profile-guided optimization information">, InGroup; def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index b65b984731f6..90791fbfd4e1 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -723,9 +723,6 @@ def fdiagnostics_print_source_range_info : Flag<["-"], "fdiagnostics-print-sourc HelpText<"Print source range spans in numeric form">; def fdiagnostics_show_hotness : Flag<["-"], "fdiagnostics-show-hotness">, Group, Flags<[CC1Option]>, HelpText<"Enable profile hotness information in diagnostic line">; -def fdiagnostics_hotness_threshold_EQ : Joined<["-"], "fdiagnostics-hotness-threshold=">, - Group, Flags<[CC1Option]>, MetaVarName<"">, - HelpText<"Prevent optimization remarks from being output if they do not have at least this profile count">; def fdiagnostics_show_option : Flag<["-"], "fdiagnostics-show-option">, Group, Flags<[CC1Option]>, HelpText<"Print option name with mappable diagnostics">; def fdiagnostics_show_note_include_stack : Flag<["-"], "fdiagnostics-show-note-include-stack">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 238bb231bdf5..6eac39c75356 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -261,10 +261,6 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0) /// Whether to report the hotness of the code region for optimization remarks. CODEGENOPT(DiagnosticsWithHotness, 1, 0) -/// The minimum hotness value a diagnostic needs in order to be included in -/// optimization diagnostics. -VALUE_CODEGENOPT(DiagnosticsHotnessThreshold, 32, 0) - /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 4f03de55149b..ba033d9413c1 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -229,9 +229,6 @@ namespace clang { void *OldDiagnosticContext = Ctx.getDiagnosticContext(); Ctx.setDiagnosticHandler(DiagnosticHandler, this); Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); - if (CodeGenOpts.DiagnosticsHotnessThreshold != 0) - Ctx.setDiagnosticsHotnessThreshold( - CodeGenOpts.DiagnosticsHotnessThreshold); std::unique_ptr OptRecordFile; if (!CodeGenOpts.OptRecordFile.empty()) { diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 3731aa83ef06..342d628396da 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4043,12 +4043,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_show_hotness, false)) CmdArgs.push_back("-fdiagnostics-show-hotness"); - if (const Arg *A = - Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) { - std::string Opt = std::string("-fdiagnostics-hotness-threshold=") + A->getValue(); - CmdArgs.push_back(Args.MakeArgString(Opt)); - } - if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); CmdArgs.push_back(A->getValue()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 5851595dab7b..b1b10ddf965c 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -909,18 +909,12 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DiagnosticsWithHotness = Args.hasArg(options::OPT_fdiagnostics_show_hotness); bool UsingSampleProfile = !Opts.SampleProfileFile.empty(); - bool UsingProfile = UsingSampleProfile || - (Opts.getProfileUse() != CodeGenOptions::ProfileNone); - - if (Opts.DiagnosticsWithHotness && !UsingProfile) - Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) - << "-fdiagnostics-show-hotness"; - - Opts.DiagnosticsHotnessThreshold = getLastArgUInt64Value( - Args, options::OPT_fdiagnostics_hotness_threshold_EQ, 0); - if (Opts.DiagnosticsHotnessThreshold > 0 && !UsingProfile) - Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) - << "-fdiagnostics-hotness-threshold="; + + if (Opts.DiagnosticsWithHotness && + Opts.getProfileUse() == CodeGenOptions::ProfileNone && + !UsingSampleProfile) { + Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo); + } // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile diff --git a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext index 730dc4a0d5b1..aeea583de4d4 100644 --- a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext +++ b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext @@ -1,7 +1,7 @@ foo:0:0 0: 0 bar:29:29 - 9: foo:0 + 6: foo:0 main:0:0 0: 0 bar:0 diff --git a/test/Frontend/optimization-remark-with-hotness.c b/test/Frontend/optimization-remark-with-hotness.c index 875fc75ae159..30ead64b8eb5 100644 --- a/test/Frontend/optimization-remark-with-hotness.c +++ b/test/Frontend/optimization-remark-with-hotness.c @@ -15,14 +15,12 @@ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ -// RUN: -verify +// RUN: -fdiagnostics-show-hotness -verify // The clang version of the previous test. // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \ // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ -// RUN: -Xclang -verify +// RUN: -fdiagnostics-show-hotness -Xclang -verify // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ @@ -30,18 +28,11 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ -// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ +// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ // RUN: -check-prefix=HOTNESS_OFF %s // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ -// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ -// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness \ -// RUN: -fdiagnostics-hotness-threshold=100 2>&1 \ -// RUN: | FileCheck -allow-empty -check-prefix=THRESHOLD %s -// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ -// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ -// RUN: -Rpass=inline -Rpass-analysis=inline \ -// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 2>&1 \ +// RUN: -Rpass=inline -Rpass-analysis=inline -fdiagnostics-show-hotness 2>&1 \ // RUN: | FileCheck -check-prefix=NO_PGO %s int foo(int x, int y) __attribute__((always_inline)); @@ -52,10 +43,7 @@ int sum = 0; void bar(int x) { // HOTNESS_OFF: foo inlined into bar // HOTNESS_OFF-NOT: hotness: - // THRESHOLD-NOT: inlined - // THRESHOLD-NOT: hotness // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information - // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information // expected-remark@+2 {{foo should always be inlined (cost=always) (hotness: 30)}} // expected-remark@+1 {{foo inlined into bar (hotness: 30)}} sum += foo(x, x - 2); From 6ac9c51ede0a50cca13dd4ac03562c036f7a3f48 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Sat, 1 Jul 2017 05:45:26 +0000 Subject: [PATCH 182/214] Un-revert "[Driver] Add -fdiagnostics-hotness-threshold" Summary: Un-revert https://reviews.llvm.org/D34868, but with a slight tweak to the documentation to fix an error -- I had used the wrong syntax for a link. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306948 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsersManual.rst | 40 +++++++++++++++---- include/clang/Basic/DiagnosticDriverKinds.td | 4 +- include/clang/Driver/Options.td | 3 ++ include/clang/Frontend/CodeGenOptions.def | 4 ++ lib/CodeGen/CodeGenAction.cpp | 3 ++ lib/Driver/ToolChains/Clang.cpp | 6 +++ lib/Frontend/CompilerInvocation.cpp | 18 ++++++--- ...zation-remark-with-hotness-sample.proftext | 2 +- .../optimization-remark-with-hotness.c | 20 ++++++++-- 9 files changed, 80 insertions(+), 20 deletions(-) diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index 7362456202ba..df6344af9102 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -322,18 +322,27 @@ output format of the diagnostics that it generates. by category, so it should be a high level category. We want dozens of these, not hundreds or thousands of them. +.. _opt_fsave-optimization-record: + +**-fsave-optimization-record** + Write optimization remarks to a YAML file. + + This option, which defaults to off, controls whether Clang writes + optimization reports to a YAML file. By recording diagnostics in a file, + using a structured YAML format, users can parse or sort the remarks in a + convenient way. + .. _opt_fdiagnostics-show-hotness: **-f[no-]diagnostics-show-hotness** Enable profile hotness information in diagnostic line. - This option, which defaults to off, controls whether Clang prints the - profile hotness associated with a diagnostics in the presence of - profile-guided optimization information. This is currently supported with - optimization remarks (see :ref:`Options to Emit Optimization Reports - `). The hotness information allows users to focus on the hot - optimization remarks that are likely to be more relevant for run-time - performance. + This option controls whether Clang prints the profile hotness associated + with diagnostics in the presence of profile-guided optimization information. + This is currently supported with optimization remarks (see + :ref:`Options to Emit Optimization Reports `). The hotness information + allows users to focus on the hot optimization remarks that are likely to be + more relevant for run-time performance. For example, in this output, the block containing the callsite of `foo` was executed 3000 times according to the profile data: @@ -344,6 +353,23 @@ output format of the diagnostics that it generates. sum += foo(x, x - 2); ^ + This option is implied when + :ref:`-fsave-optimization-record ` is used. + Otherwise, it defaults to off. + +.. _opt_fdiagnostics-hotness-threshold: + +**-fdiagnostics-hotness-threshold** + Prevent optimization remarks from being output if they do not have at least + this hotness value. + + This option, which defaults to zero, controls the minimum hotness an + optimization remark would need in order to be output by Clang. This is + currently supported with optimization remarks (see :ref:`Options to Emit + Optimization Reports `) when profile hotness information in + diagnostics is enabled (see + :ref:`-fdiagnostics-show-hotness `). + .. _opt_fdiagnostics-fixit-info: **-f[no-]diagnostics-fixit-info** diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 1a731975b3fe..42e1e5edaf9e 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -198,8 +198,8 @@ def warn_drv_unused_argument : Warning< def warn_drv_empty_joined_argument : Warning< "joined argument expects additional value: '%0'">, InGroup; -def warn_drv_fdiagnostics_show_hotness_requires_pgo : Warning< - "argument '-fdiagnostics-show-hotness' requires profile-guided optimization information">, +def warn_drv_diagnostics_hotness_requires_pgo : Warning< + "argument '%0' requires profile-guided optimization information">, InGroup; def warn_drv_clang_unsupported : Warning< "the clang compiler does not support '%0'">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 90791fbfd4e1..b65b984731f6 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -723,6 +723,9 @@ def fdiagnostics_print_source_range_info : Flag<["-"], "fdiagnostics-print-sourc HelpText<"Print source range spans in numeric form">; def fdiagnostics_show_hotness : Flag<["-"], "fdiagnostics-show-hotness">, Group, Flags<[CC1Option]>, HelpText<"Enable profile hotness information in diagnostic line">; +def fdiagnostics_hotness_threshold_EQ : Joined<["-"], "fdiagnostics-hotness-threshold=">, + Group, Flags<[CC1Option]>, MetaVarName<"">, + HelpText<"Prevent optimization remarks from being output if they do not have at least this profile count">; def fdiagnostics_show_option : Flag<["-"], "fdiagnostics-show-option">, Group, Flags<[CC1Option]>, HelpText<"Print option name with mappable diagnostics">; def fdiagnostics_show_note_include_stack : Flag<["-"], "fdiagnostics-show-note-include-stack">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 6eac39c75356..238bb231bdf5 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -261,6 +261,10 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0) /// Whether to report the hotness of the code region for optimization remarks. CODEGENOPT(DiagnosticsWithHotness, 1, 0) +/// The minimum hotness value a diagnostic needs in order to be included in +/// optimization diagnostics. +VALUE_CODEGENOPT(DiagnosticsHotnessThreshold, 32, 0) + /// Whether copy relocations support is available when building as PIE. CODEGENOPT(PIECopyRelocations, 1, 0) diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index ba033d9413c1..4f03de55149b 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -229,6 +229,9 @@ namespace clang { void *OldDiagnosticContext = Ctx.getDiagnosticContext(); Ctx.setDiagnosticHandler(DiagnosticHandler, this); Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); + if (CodeGenOpts.DiagnosticsHotnessThreshold != 0) + Ctx.setDiagnosticsHotnessThreshold( + CodeGenOpts.DiagnosticsHotnessThreshold); std::unique_ptr OptRecordFile; if (!CodeGenOpts.OptRecordFile.empty()) { diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 342d628396da..3731aa83ef06 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4043,6 +4043,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_show_hotness, false)) CmdArgs.push_back("-fdiagnostics-show-hotness"); + if (const Arg *A = + Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) { + std::string Opt = std::string("-fdiagnostics-hotness-threshold=") + A->getValue(); + CmdArgs.push_back(Args.MakeArgString(Opt)); + } + if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); CmdArgs.push_back(A->getValue()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b1b10ddf965c..5851595dab7b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -909,12 +909,18 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DiagnosticsWithHotness = Args.hasArg(options::OPT_fdiagnostics_show_hotness); bool UsingSampleProfile = !Opts.SampleProfileFile.empty(); - - if (Opts.DiagnosticsWithHotness && - Opts.getProfileUse() == CodeGenOptions::ProfileNone && - !UsingSampleProfile) { - Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo); - } + bool UsingProfile = UsingSampleProfile || + (Opts.getProfileUse() != CodeGenOptions::ProfileNone); + + if (Opts.DiagnosticsWithHotness && !UsingProfile) + Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) + << "-fdiagnostics-show-hotness"; + + Opts.DiagnosticsHotnessThreshold = getLastArgUInt64Value( + Args, options::OPT_fdiagnostics_hotness_threshold_EQ, 0); + if (Opts.DiagnosticsHotnessThreshold > 0 && !UsingProfile) + Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) + << "-fdiagnostics-hotness-threshold="; // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile diff --git a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext index aeea583de4d4..730dc4a0d5b1 100644 --- a/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext +++ b/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext @@ -1,7 +1,7 @@ foo:0:0 0: 0 bar:29:29 - 6: foo:0 + 9: foo:0 main:0:0 0: 0 bar:0 diff --git a/test/Frontend/optimization-remark-with-hotness.c b/test/Frontend/optimization-remark-with-hotness.c index 30ead64b8eb5..875fc75ae159 100644 --- a/test/Frontend/optimization-remark-with-hotness.c +++ b/test/Frontend/optimization-remark-with-hotness.c @@ -15,12 +15,14 @@ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -verify +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ +// RUN: -verify // The clang version of the previous test. // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \ // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \ // RUN: -Rpass-analysis=inline -Rpass-missed=inline \ -// RUN: -fdiagnostics-show-hotness -Xclang -verify +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \ +// RUN: -Xclang -verify // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ @@ -28,11 +30,18 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ -// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ +// RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \ // RUN: -check-prefix=HOTNESS_OFF %s // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ -// RUN: -Rpass=inline -Rpass-analysis=inline -fdiagnostics-show-hotness 2>&1 \ +// RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \ +// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness \ +// RUN: -fdiagnostics-hotness-threshold=100 2>&1 \ +// RUN: | FileCheck -allow-empty -check-prefix=THRESHOLD %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \ +// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \ +// RUN: -Rpass=inline -Rpass-analysis=inline \ +// RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 2>&1 \ // RUN: | FileCheck -check-prefix=NO_PGO %s int foo(int x, int y) __attribute__((always_inline)); @@ -43,7 +52,10 @@ int sum = 0; void bar(int x) { // HOTNESS_OFF: foo inlined into bar // HOTNESS_OFF-NOT: hotness: + // THRESHOLD-NOT: inlined + // THRESHOLD-NOT: hotness // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information + // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information // expected-remark@+2 {{foo should always be inlined (cost=always) (hotness: 30)}} // expected-remark@+1 {{foo inlined into bar (hotness: 30)}} sum += foo(x, x - 2); From 6439f18f22a00589c57821e2d15c67f9bb566ba3 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Sat, 1 Jul 2017 07:57:23 +0000 Subject: [PATCH 183/214] Changed Opts.EABIVersion type string to llvm::EABI enum class Summary: Changed EABIVersion type from string to llvm::EABI. It seems it was just a typo and this is intended implementation. Differential Revision: https://reviews.llvm.org/D34595 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306953 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetOptions.h | 3 ++- lib/Basic/Targets.cpp | 4 ++-- lib/CodeGen/BackendUtil.cpp | 6 +----- lib/Frontend/CompilerInvocation.cpp | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/clang/Basic/TargetOptions.h b/include/clang/Basic/TargetOptions.h index 6ca1ba39c8fb..9bb19c7b79df 100644 --- a/include/clang/Basic/TargetOptions.h +++ b/include/clang/Basic/TargetOptions.h @@ -18,6 +18,7 @@ #include #include #include "clang/Basic/OpenCLOptions.h" +#include "llvm/Target/TargetOptions.h" namespace clang { @@ -41,7 +42,7 @@ class TargetOptions { std::string ABI; /// The EABI version to use - std::string EABIVersion; + llvm::EABI EABIVersion; /// If given, the version string of the linker in use. std::string LinkerVersion; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index e1af6415b281..eae010a4bd5f 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -5443,7 +5443,7 @@ class ARMTargetInfo : public TargetInfo { if (Triple.getOS() == llvm::Triple::Linux || Triple.getOS() == llvm::Triple::UnknownOS) this->MCountName = - Opts.EABIVersion == "gnu" ? "\01__gnu_mcount_nc" : "\01mcount"; + Opts.EABIVersion == llvm::EABI::GNU ? "\01__gnu_mcount_nc" : "\01mcount"; } StringRef getABI() const override { return ABI; } @@ -6283,7 +6283,7 @@ class AArch64TargetInfo : public TargetInfo { if (Triple.getOS() == llvm::Triple::Linux) this->MCountName = "\01_mcount"; else if (Triple.getOS() == llvm::Triple::UnknownOS) - this->MCountName = Opts.EABIVersion == "gnu" ? "\01_mcount" : "mcount"; + this->MCountName = Opts.EABIVersion == llvm::EABI::GNU ? "\01_mcount" : "mcount"; } StringRef getABI() const override { return ABI; } diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index b528cb467b9b..9b3850abcce7 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -415,11 +415,7 @@ static void initTargetOptions(llvm::TargetOptions &Options, Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; // Set EABI version. - Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion) - .Case("4", llvm::EABI::EABI4) - .Case("5", llvm::EABI::EABI5) - .Case("gnu", llvm::EABI::GNU) - .Default(llvm::EABI::Default); + Options.EABIVersion = TargetOpts.EABIVersion; if (LangOpts.SjLjExceptions) Options.ExceptionModel = llvm::ExceptionHandling::SjLj; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 5851595dab7b..00f6b9b46f03 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2568,7 +2568,7 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value; else - Opts.EABIVersion = Value; + Opts.EABIVersion = EABIVersion; } Opts.CPU = Args.getLastArgValue(OPT_target_cpu); Opts.FPMath = Args.getLastArgValue(OPT_mfpmath); From 1124518852a283a657d709877b9b474f1fc7e5fc Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Sat, 1 Jul 2017 08:46:43 +0000 Subject: [PATCH 184/214] fix trivial typos; NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306954 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 2 +- lib/Driver/ToolChains/MipsLinux.cpp | 2 +- lib/Frontend/ModuleDependencyCollector.cpp | 2 +- lib/Sema/SemaDecl.cpp | 2 +- lib/Serialization/ASTReader.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index eae010a4bd5f..4f04489a4a10 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -2706,7 +2706,7 @@ class X86TargetInfo : public TargetInfo { CK_C3_2, /// This enumerator is a bit odd, as GCC no longer accepts -march=yonah. - /// Clang however has some logic to suport this. + /// Clang however has some logic to support this. // FIXME: Warn, deprecate, and potentially remove this. CK_Yonah, //@} diff --git a/lib/Driver/ToolChains/MipsLinux.cpp b/lib/Driver/ToolChains/MipsLinux.cpp index 709c396a64b7..b394208336ed 100644 --- a/lib/Driver/ToolChains/MipsLinux.cpp +++ b/lib/Driver/ToolChains/MipsLinux.cpp @@ -109,7 +109,7 @@ std::string MipsLLVMToolChain::findLibCxxIncludePath() const { void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && - "Only -lc++ (aka libxx) is suported in this toolchain."); + "Only -lc++ (aka libxx) is supported in this toolchain."); CmdArgs.push_back("-lc++"); CmdArgs.push_back("-lc++abi"); diff --git a/lib/Frontend/ModuleDependencyCollector.cpp b/lib/Frontend/ModuleDependencyCollector.cpp index 9b34d4211353..ede12aab6e69 100644 --- a/lib/Frontend/ModuleDependencyCollector.cpp +++ b/lib/Frontend/ModuleDependencyCollector.cpp @@ -248,7 +248,7 @@ std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src, // Always map a canonical src path to its real path into the YAML, by doing // this we map different virtual src paths to the same entry in the VFS // overlay, which is a way to emulate symlink inside the VFS; this is also - // needed for correctness, not doing that can lead to module redifinition + // needed for correctness, not doing that can lead to module redefinition // errors. addFileMapping(VirtualPath, CacheDst); return std::error_code(); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 59bfa49066c5..ef8a408f90de 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11975,7 +11975,7 @@ Sema::CheckForFunctionRedefinition(FunctionDecl *FD, if (canRedefineFunction(Definition, getLangOpts())) return; - // Don't emit an error when this is redifinition of a typo-corrected + // Don't emit an error when this is redefinition of a typo-corrected // definition. if (TypoCorrectedFunctionDefinitions.count(Definition)) return; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index f9421c788d93..3aee3c04001d 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -8263,7 +8263,7 @@ ASTReader::getSourceDescriptor(unsigned ID) { return ExternalASTSource::ASTSourceDescriptor(*M); // If there is only a single PCH, return it instead. - // Chained PCH are not suported. + // Chained PCH are not supported. const auto &PCHChain = ModuleMgr.pch_modules(); if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { ModuleFile &MF = ModuleMgr.getPrimaryModule(); From b872b4465911005979d9746d8e7a912d9fa4c402 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Sat, 1 Jul 2017 10:40:50 +0000 Subject: [PATCH 185/214] [OpenMP] Fix mapping of scalars for combined directives Combined directives like 'target parallel' have two captured statements. Sema has to check the right one from the right direction. Previously, Sema::IsOpenMPCapturedByRef would return false for mapped scalars on combined directives. This results in a wrong signature of the outlined function which triggers an assertion: void llvm::CallInst::init(llvm::FunctionType *, llvm::Value *, ArrayRef, ArrayRef, const llvm::Twine &): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed. Fixes PR30975 (and PR31985). New function was taken from clang-ykt. Differential Revision: https://reviews.llvm.org/D34888 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306956 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOpenMP.cpp | 29 ++++++++++++++++++++++++++--- test/OpenMP/target_map_codegen.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 2b7733d2adbd..49da0e499771 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -412,6 +412,30 @@ class DSAStackTy final { return false; } + /// Do the check specified in \a Check to all component lists at a given level + /// and return true if any issue is found. + bool checkMappableExprComponentListsForDeclAtLevel( + ValueDecl *VD, unsigned Level, + const llvm::function_ref< + bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, + OpenMPClauseKind)> &Check) { + if (isStackEmpty()) + return false; + + auto StartI = Stack.back().first.begin(); + auto EndI = Stack.back().first.end(); + if (std::distance(StartI, EndI) <= (int)Level) + return false; + std::advance(StartI, Level); + + auto MI = StartI->MappedExprComponents.find(VD); + if (MI != StartI->MappedExprComponents.end()) + for (auto &L : MI->second.Components) + if (Check(L, MI->second.Kind)) + return true; + return false; + } + /// Create a new mappable expression component list associated with a given /// declaration and initialize it with the provided list of components. void addMappableExpressionComponents( @@ -994,9 +1018,8 @@ bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { bool IsVariableUsedInMapClause = false; bool IsVariableAssociatedWithSection = false; - DSAStack->checkMappableExprComponentListsForDecl( - D, /*CurrentRegionOnly=*/true, - [&](OMPClauseMappableExprCommon::MappableExprComponentListRef + DSAStack->checkMappableExprComponentListsForDeclAtLevel( + D, Level, [&](OMPClauseMappableExprCommon::MappableExprComponentListRef MapExprComponents, OpenMPClauseKind WhereFoundClauseKind) { // Only the map clause information influences how a variable is diff --git a/test/OpenMP/target_map_codegen.cpp b/test/OpenMP/target_map_codegen.cpp index 4933bf31c2a5..69e80bb9505b 100644 --- a/test/OpenMP/target_map_codegen.cpp +++ b/test/OpenMP/target_map_codegen.cpp @@ -1056,6 +1056,9 @@ void implicit_maps_template_type_capture (int a){ // CK19: [[SIZE00:@.+]] = private {{.*}}constant [1 x i[[Z:64|32]]] [i[[Z:64|32]] 4] // CK19: [[MTYPE00:@.+]] = private {{.*}}constant [1 x i32] [i32 32] +// CK19: [[SIZE00n:@.+]] = private {{.*}}constant [1 x i[[Z:64|32]]] [i[[Z:64|32]] 4] +// CK19: [[MTYPE00n:@.+]] = private {{.*}}constant [1 x i32] [i32 32] + // CK19: [[SIZE01:@.+]] = private {{.*}}constant [1 x i[[Z]]] [i[[Z]] 400] // CK19: [[MTYPE01:@.+]] = private {{.*}}constant [1 x i32] [i32 33] @@ -1194,6 +1197,28 @@ void explicit_maps_single (int ii){ ++a; } + // Map of a scalar in nested region. + int b = a; + + // Region 00n + // CK19-DAG: call i32 @__tgt_target(i32 {{[^,]+}}, i8* {{[^,]+}}, i32 1, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[SIZE00n]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[MTYPE00n]]{{.+}}) + // CK19-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]] + // CK19-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]] + + // CK19-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0 + // CK19-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0 + // CK19-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to i32** + // CK19-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to i32** + // CK19-DAG: store i32* [[VAR0:%.+]], i32** [[CBP0]] + // CK19-DAG: store i32* [[VAR0]], i32** [[CP0]] + + // CK19: call void [[CALL00n:@.+]](i32* {{[^,]+}}) + #pragma omp target map(alloc:b) + #pragma omp parallel + { + ++b; + } + // Map of an array. int arra[100]; @@ -2388,6 +2413,7 @@ void explicit_maps_single (int ii){ } // CK19: define {{.+}}[[CALL00]] +// CK19: define {{.+}}[[CALL00n]] // CK19: define {{.+}}[[CALL01]] // CK19: define {{.+}}[[CALL02]] // CK19: define {{.+}}[[CALL03]] From ce9e71cd0837f7e5e4ea30a14d49d193cf6201e1 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Sat, 1 Jul 2017 16:30:02 +0000 Subject: [PATCH 186/214] [Bash-completion] Fixed a bug that ~ doesn't expanded to $HOME Summary: `~/build/bin/clang -f[tab]` was executed without ~ expanded to $HOME, so changed this by expanding ~ to path using eval. Differential Revision: https://reviews.llvm.org/D34925 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306957 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/bash-autocomplete.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index 775b1f45351a..4f9853accc88 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -24,7 +24,9 @@ _clang() arg="$w2=,$cur" fi - flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null ) + # expand ~ to $HOME + eval local path=${COMP_WORDS[0]} + flags=$( "$path" --autocomplete="$arg" 2>/dev/null ) # If clang is old that it does not support --autocomplete, # fall back to the filename completion. if [[ "$?" != 0 ]]; then From d958391d29c3f78385bd097f8adea009303baf12 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Sat, 1 Jul 2017 18:32:55 +0000 Subject: [PATCH 187/214] [Bash-autocompletion] Add support for older bash version. Summary: OS X seems to use older bash version which doesn't suport _init_completion and compopt, so add support for this. Reviewers: ruiu, v.g.vassilev, teemperor Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34924 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306962 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/bash-autocomplete.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh index 4f9853accc88..c28dc86b1309 100644 --- a/utils/bash-autocomplete.sh +++ b/utils/bash-autocomplete.sh @@ -1,15 +1,33 @@ # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this. + +_clang_filedir() +{ + # _filedir function provided by recent versions of bash-completion package is + # better than "compgen -f" because the former honors spaces in pathnames while + # the latter doesn't. So we use compgen only when _filedir is not provided. + _filedir 2> /dev/null || COMPREPLY=( $( compgen -f ) ) +} + _clang() { - local cur prev words cword arg flags - _init_completion -n : || return + local cur prev words cword arg flags w1 w2 + # If latest bash-completion is not supported just initialize COMPREPLY and + # initialize variables by setting manualy. + _init_completion -n 2> /dev/null + if [[ "$?" != 0 ]]; then + COMPREPLY=() + cword=$COMP_CWORD + cur="${COMP_WORDS[$cword]}" + fi # bash always separates '=' as a token even if there's no space before/after '='. # On the other hand, '=' is just a regular character for clang options that # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=". # So, we need to partially undo bash tokenization here for integrity. - local w1="${COMP_WORDS[$cword - 1]}" - local w2="${COMP_WORDS[$cword - 2]}" + w1="${COMP_WORDS[$cword - 1]}" + if [[ $cword > 1 ]]; then + w2="${COMP_WORDS[$cword - 2]}" + fi if [[ "$cur" == -* ]]; then # -foo arg="$cur" @@ -30,18 +48,18 @@ _clang() # If clang is old that it does not support --autocomplete, # fall back to the filename completion. if [[ "$?" != 0 ]]; then - _filedir + _clang_filedir return fi if [[ "$cur" == '=' ]]; then COMPREPLY=( $( compgen -W "$flags" -- "") ) elif [[ "$flags" == "" || "$arg" == "" ]]; then - _filedir + _clang_filedir else # Bash automatically appends a space after '=' by default. # Disable it so that it works nicely for options in the form of -foo=bar. - [[ "${flags: -1}" == '=' ]] && compopt -o nospace + [[ "${flags: -1}" == '=' ]] && compopt -o nospace 2> /dev/null COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) ) fi } From 17fb9ad1ae41e5b764e813c4e766ae5e2ce2b210 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sat, 1 Jul 2017 20:44:49 +0000 Subject: [PATCH 188/214] [modules] Teach clang how to merge typedef over anonymous structs in C mode. In C mode clang fails to merge the textually included definition with the one imported from a module. The C lookup rules fail to find the imported definition because its linkage is internal in non C++ mode. This patch reinstates some of the ODR merging rules for typedefs of anonymous tags for languages other than C++. Patch by Raphael Isemann and me (D34510). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306964 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 3 +-- lib/Sema/SemaDecl.cpp | 5 ++--- test/Index/usrs.m | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 267c6992af89..24d998391257 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1259,8 +1259,7 @@ static LinkageInfo computeLVForDecl(const NamedDecl *D, case Decl::TypeAlias: // A typedef declaration has linkage if it gives a type a name for // linkage purposes. - if (!D->getASTContext().getLangOpts().CPlusPlus || - !cast(D) + if (!cast(D) ->getAnonDeclWithTypedefName(/*AnyRedecl*/true)) return LinkageInfo::none(); break; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ef8a408f90de..ab2661cd7131 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1998,8 +1998,7 @@ static void filterNonConflictingPreviousTypedefDecls(Sema &S, // If both declarations give a tag declaration a typedef name for linkage // purposes, then they declare the same entity. - if (S.getLangOpts().CPlusPlus && - OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) && + if (OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) && Decl->getAnonDeclWithTypedefName()) continue; } @@ -2117,7 +2116,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, auto *OldTag = OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true); auto *NewTag = New->getAnonDeclWithTypedefName(); NamedDecl *Hidden = nullptr; - if (getLangOpts().CPlusPlus && OldTag && NewTag && + if (OldTag && NewTag && OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() && !hasVisibleDefinition(OldTag, &Hidden)) { // There is a definition of this tag, but it is not visible. Use it diff --git a/test/Index/usrs.m b/test/Index/usrs.m index 92c3a3fafee2..d0a860e1afad 100644 --- a/test/Index/usrs.m +++ b/test/Index/usrs.m @@ -119,7 +119,7 @@ -(int)methodWithFn:(void (*)(int *p))fn; // CHECK: usrs.m c:@SA@MyStruct Extent=[15:9 - 18:2] // CHECK: usrs.m c:@SA@MyStruct@FI@wa Extent=[16:3 - 16:9] // CHECK: usrs.m c:@SA@MyStruct@FI@moo Extent=[17:3 - 17:10] -// CHECK: usrs.m c:usrs.m@T@MyStruct Extent=[15:1 - 18:11] +// CHECK: usrs.m c:@T@MyStruct Extent=[15:1 - 18:11] // CHECK: usrs.m c:@E@Pizza Extent=[20:1 - 23:2] // CHECK: usrs.m c:@E@Pizza@CHEESE Extent=[21:3 - 21:9] // CHECK: usrs.m c:@E@Pizza@MUSHROOMS Extent=[22:3 - 22:12] From ae5fad5a9a55faf2510a32c4d55fc728c1f29427 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 1 Jul 2017 21:36:21 +0000 Subject: [PATCH 189/214] Add an option group for deprecated warnings. Add the removed -fslp-vectorize-aggressive and -fno-slp-vectorize-aggressive flags back under this group and test for the warning. Document the future removal in the ReleaseNotes. Differential Revision: https://reviews.llvm.org/D34926 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306965 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ReleaseNotes.rst | 10 ++++++++++ include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ include/clang/Driver/Options.td | 10 ++++++++++ lib/Driver/ToolChains/Clang.cpp | 6 ++++++ test/Driver/clang_f_opts.c | 4 ++++ 5 files changed, 32 insertions(+) diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index f9a3317811eb..0f49e3f979c9 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -60,6 +60,16 @@ New Compiler Flags The option .... +Deprecated Compiler Flags +------------------------- + +The following options are deprecated and ignored. They will be removed in +future versions of Clang. + +- -fslp-vectorize-aggressive used to enable the BB vectorizing pass. They have been superseeded + by the normal SLP vectorizer. +- -fno-slp-vectorize-aggressive used to be the default behavior of clang. + New Pragmas in Clang ----------------------- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 42e1e5edaf9e..a28d63182749 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -178,6 +178,8 @@ def warn_drv_optimization_value : Warning<"optimization level '%0' is not suppor InGroup; def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not supported">, InGroup; +def warn_ignored_clang_option : Warning<"the flag '%0' has been deprecated and will be ignored">, + InGroup; def warn_drv_unsupported_opt_for_target : Warning< "optimization flag '%0' is not supported for target '%1'">, InGroup; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index b65b984731f6..cdd4c94c432e 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -194,6 +194,16 @@ def clang_ignored_f_Group : OptionGroup<"">, def clang_ignored_m_Group : OptionGroup<"">, Group, Flags<[Ignored]>; +// Group for clang options in the process of deprecation. +// Please include the version that deprecated the flag as comment to allow +// easier garbage collection. +def clang_ignored_legacy_options_Group : OptionGroup<"">, + Group, Flags<[Ignored]>; + +// Retired with clang-5.0 +def : Flag<["-"], "fslp-vectorize-aggressive">, Group; +def : Flag<["-"], "fno-slp-vectorize-aggressive">, Group; + // Group that ignores all gcc optimizations that won't be implemented def clang_ignored_gcc_optimization_f_Group : OptionGroup< "">, Group, Flags<[Ignored]>; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 3731aa83ef06..5c5801134cd1 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -2974,6 +2974,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, A->claim(); } + for (const Arg *A : + Args.filtered(options::OPT_clang_ignored_legacy_options_Group)) { + D.Diag(diag::warn_ignored_clang_option) << A->getAsString(Args); + A->claim(); + } + claimNoWarnArgs(Args); Args.AddAllArgs(CmdArgs, options::OPT_R_Group); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index e4b72d69ca3f..c17cec6eba9b 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -356,6 +356,8 @@ // RUN: -ftree-vrp \ // RUN: -fno-devirtualize \ // RUN: -fno-devirtualize-speculatively \ +// RUN: -fslp-vectorize-aggressive \ +// RUN: -fno-slp-vectorize-aggressive \ // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING %s // CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported // CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported @@ -422,6 +424,8 @@ // CHECK-WARNING-DAG: optimization flag '-ftree-vrp' is not supported // CHECK-WARNING-DAG: optimization flag '-fno-devirtualize' is not supported // CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is not supported +// CHECK-WARNING-DAG: the flag '-fslp-vectorize-aggressive' has been deprecated and will be ignored +// CHECK-WARNING-DAG: the flag '-fno-slp-vectorize-aggressive' has been deprecated and will be ignored // Test that we mute the warning on these // RUN: %clang -### -finline-limit=1000 -Wno-invalid-command-line-argument \ From 58123a81df74bcd2051b11f77a6a38277764a0d7 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Sun, 2 Jul 2017 06:12:49 +0000 Subject: [PATCH 190/214] fix trivial typos in comments; NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306969 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 2 +- lib/Parse/ParseExpr.cpp | 4 ++-- test/Sema/warn-documentation.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 07054546f42f..a4610698c46d 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -6650,7 +6650,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { return; } - // If we get here, the operand to the typeof was an expresion. + // If we get here, the operand to the typeof was an expression. if (Operand.isInvalid()) { DS.SetTypeSpecError(); return; diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index aacb00e8be64..44b87af01abd 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1866,7 +1866,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, } } - // If we get here, the operand to the typeof/sizeof/alignof was an expresion. + // If we get here, the operand to the typeof/sizeof/alignof was an expression. isCastExpr = false; return Operand; } @@ -1972,7 +1972,7 @@ ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof)) Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo(); - // If we get here, the operand to the sizeof/alignof was an expresion. + // If we get here, the operand to the sizeof/alignof was an expression. if (!Operand.isInvalid()) Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(), ExprKind, diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 0c92b2aa029f..ccf374ccd060 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -1186,7 +1186,7 @@ class Predicate /// @brief A C++ wrapper class for providing threaded access to a value /// of type T. /// -/// A template specilization class. +/// A template specialization class. //---------------------------------------------------------------------- template<> class Predicate { From ae6cb8d28c844a6d45b3c64ae7338e9d1653784c Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Mon, 3 Jul 2017 08:49:44 +0000 Subject: [PATCH 191/214] fix trivial typos in comments; NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307007 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/clang/cindex.py | 2 +- lib/CodeGen/CGBlocks.cpp | 2 +- lib/CodeGen/CGCall.cpp | 2 +- lib/Frontend/Rewrite/RewriteModernObjC.cpp | 2 +- lib/Frontend/Rewrite/RewriteObjC.cpp | 2 +- www/analyzer/scripts/expandcollapse.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 5e70bde770f8..1ca580491906 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -782,7 +782,7 @@ def __repr__(self): # A C++ template type parameter CursorKind.TEMPLATE_TYPE_PARAMETER = CursorKind(27) -# A C++ non-type template paramater. +# A C++ non-type template parameter. CursorKind.TEMPLATE_NON_TYPE_PARAMETER = CursorKind(28) # A C++ template template parameter. diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 528a2b33acf8..f2de42b59300 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -1255,7 +1255,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, // For OpenCL passed block pointer can be private AS local variable or // global AS program scope variable (for the case with and without captures). - // Generic AS is used therefore to be able to accomodate both private and + // Generic AS is used therefore to be able to accommodate both private and // generic AS in one implementation. if (getLangOpts().OpenCL) selfTy = getContext().getPointerType(getContext().getAddrSpaceQualType( diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 13a156c7bbd7..cee656a62fe7 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -129,7 +129,7 @@ static void addExtParameterInfosForCall( paramInfos.resize(totalArgs); } -/// Adds the formal paramaters in FPT to the given prefix. If any parameter in +/// Adds the formal parameters in FPT to the given prefix. If any parameter in /// FPT has pass_object_size attrs, then we'll add parameters for those, too. static void appendParameterTypes(const CodeGenTypes &CGT, SmallVectorImpl &prefix, diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 83290a6fbc28..8e1a634cb723 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -6068,7 +6068,7 @@ void RewriteModernObjC::Initialize(ASTContext &context) { Preamble += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)\n"; } -/// RewriteIvarOffsetComputation - This rutine synthesizes computation of +/// RewriteIvarOffsetComputation - This routine synthesizes computation of /// ivar offset. void RewriteModernObjC::RewriteIvarOffsetComputation(ObjCIvarDecl *ivar, std::string &Result) { diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index 7d809c610c86..5a1e001d65b8 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -5052,7 +5052,7 @@ void RewriteObjCFragileABI::Initialize(ASTContext &context) { Preamble += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)\n"; } -/// RewriteIvarOffsetComputation - This rutine synthesizes computation of +/// RewriteIvarOffsetComputation - This routine synthesizes computation of /// ivar offset. void RewriteObjCFragileABI::RewriteIvarOffsetComputation(ObjCIvarDecl *ivar, std::string &Result) { diff --git a/www/analyzer/scripts/expandcollapse.js b/www/analyzer/scripts/expandcollapse.js index 593a9831c8b0..c3ae2864670e 100644 --- a/www/analyzer/scripts/expandcollapse.js +++ b/www/analyzer/scripts/expandcollapse.js @@ -81,7 +81,7 @@ function initExpandCollapse() { expander.onclick = function() { expandCollapse(this.id); // Hack for Opera - onmouseout callback is not invoked when page - // content changes dinamically and mouse pointer goes out of an element. + // content changes dynamically and mouse pointer goes out of an element. this.src = imgPath + (getCellInfo(this.id).expanded ? "arrows_light.gif" : "ellipses_light.gif"); From b9181e93ed98cd03533ebb9fa135ce59f5d9e46a Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 3 Jul 2017 10:12:24 +0000 Subject: [PATCH 192/214] Add a fixit for -Wobjc-protocol-property-synthesis rdar://32132756 Differential Revision: https://reviews.llvm.org/D34886 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307014 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ include/clang/Sema/Sema.h | 7 ++++--- lib/Parse/ParseObjc.cpp | 2 +- lib/Sema/SemaObjCProperty.cpp | 14 ++++++++++---- test/FixIt/fixit-add-synthesize-to-property.m | 14 ++++++++++++++ test/SemaObjC/default-synthesize-3.m | 4 ++-- test/SemaObjC/default-synthesize.m | 2 +- .../forward-protocol-incomplete-impl-warn.m | 2 +- 8 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 test/FixIt/fixit-add-synthesize-to-property.m diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 136e48ab5e54..805bcb2a3580 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1029,6 +1029,8 @@ def warn_auto_synthesizing_protocol_property :Warning< "auto property synthesis will not synthesize property %0" " declared in protocol %1">, InGroup>; +def note_add_synthesize_directive : Note< + "add a '@synthesize' directive">; def warn_no_autosynthesis_shared_ivar_property : Warning < "auto property synthesis will not synthesize property " "%0 because it cannot share an ivar with another synthesized property">, diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 95134d52f873..1fc0b2e502b7 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3358,9 +3358,10 @@ class Sema { /// DefaultSynthesizeProperties - This routine default synthesizes all /// properties which must be synthesized in the class's \@implementation. - void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, - ObjCInterfaceDecl *IDecl); - void DefaultSynthesizeProperties(Scope *S, Decl *D); + void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, + ObjCInterfaceDecl *IDecl, + SourceLocation AtEnd); + void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is /// an ivar synthesized for 'Method' and 'Method' is a property accessor diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index caa6323d3209..f7410b8a092a 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -2255,7 +2255,7 @@ Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { void Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) { assert(!Finished); - P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl); + P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl, AtEnd.getBegin()); for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], true/*Methods*/); diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 6c5716454874..62a771bcffa0 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1676,8 +1676,9 @@ static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl, /// \brief Default synthesizes all properties which must be synthesized /// in class's \@implementation. -void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, - ObjCInterfaceDecl *IDecl) { +void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, + ObjCInterfaceDecl *IDecl, + SourceLocation AtEnd) { ObjCInterfaceDecl::PropertyMap PropMap; ObjCInterfaceDecl::PropertyDeclOrder PropertyOrder; IDecl->collectPropertiesToImplement(PropMap, PropertyOrder); @@ -1725,6 +1726,10 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, diag::warn_auto_synthesizing_protocol_property) << Prop << Proto; Diag(Prop->getLocation(), diag::note_property_declare); + std::string FixIt = + (Twine("@synthesize ") + Prop->getName() + ";\n\n").str(); + Diag(AtEnd, diag::note_add_synthesize_directive) + << FixItHint::CreateInsertion(AtEnd, FixIt); } continue; } @@ -1764,7 +1769,8 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, } } -void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) { +void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D, + SourceLocation AtEnd) { if (!LangOpts.ObjCDefaultSynthProperties || LangOpts.ObjCRuntime.isFragile()) return; ObjCImplementationDecl *IC=dyn_cast_or_null(D); @@ -1772,7 +1778,7 @@ void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) { return; if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) if (!IDecl->isObjCRequiresPropertyDefs()) - DefaultSynthesizeProperties(S, IC, IDecl); + DefaultSynthesizeProperties(S, IC, IDecl, AtEnd); } static void DiagnoseUnimplementedAccessor( diff --git a/test/FixIt/fixit-add-synthesize-to-property.m b/test/FixIt/fixit-add-synthesize-to-property.m new file mode 100644 index 000000000000..19b2f4b73f01 --- /dev/null +++ b/test/FixIt/fixit-add-synthesize-to-property.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s + +@protocol P1 + +@property int prop; + +@end + +@interface I + +@end + +@implementation I +@end // CHECK: fix-it:{{.*}}:{[[@LINE]]:1-[[@LINE]]:1}:"@synthesize prop;\n\n" diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m index fe2b35f61523..9a05408aa060 100644 --- a/test/SemaObjC/default-synthesize-3.m +++ b/test/SemaObjC/default-synthesize-3.m @@ -173,13 +173,13 @@ @interface Okay : NSObject @end @implementation Okay // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} -@end +@end // expected-note 2 {{add a '@synthesize' directive}} @interface Fail : FooObject @end @implementation Fail // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} -@end +@end // expected-note 2 {{add a '@synthesize' directive}} // rdar://16089191 @class NSURL; diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m index 3f0ae0261daf..61ce9317c519 100644 --- a/test/SemaObjC/default-synthesize.m +++ b/test/SemaObjC/default-synthesize.m @@ -137,7 +137,7 @@ @interface MyClass @end @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}} -@end +@end // expected-note {{add a '@synthesize' directive}} // rdar://18152478 @protocol NSObject @end diff --git a/test/SemaObjC/forward-protocol-incomplete-impl-warn.m b/test/SemaObjC/forward-protocol-incomplete-impl-warn.m index c235e32316a9..583bb4dd891d 100644 --- a/test/SemaObjC/forward-protocol-incomplete-impl-warn.m +++ b/test/SemaObjC/forward-protocol-incomplete-impl-warn.m @@ -17,4 +17,4 @@ @interface IBImageCatalogDocument : NSObject @implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property 'Prop' declared in protocol 'DVTInvalidation'}} \ // expected-warning {{method 'invalidate' in protocol 'DVTInvalidation' not implemented}} -@end +@end // expected-note {{add a '@synthesize' directive}} From 0305311a4e50b9a1d54a9a1d050d93754f26f9cf Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 3 Jul 2017 10:34:46 +0000 Subject: [PATCH 193/214] [index] Remove 'implicit' role for message sends in implicit ObjC property references rdar://32375673 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307016 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexBody.cpp | 26 +++++++++++++++++++++++++- test/Index/Core/index-source.m | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/Index/IndexBody.cpp b/lib/Index/IndexBody.cpp index d3632b8b9b15..6bbd38102509 100644 --- a/lib/Index/IndexBody.cpp +++ b/lib/Index/IndexBody.cpp @@ -230,7 +230,31 @@ class BodyIndexer : public RecursiveASTVisitor { SmallVector Relations; addCallRole(Roles, Relations); Stmt *Containing = getParentStmt(); - if (E->isImplicit() || (Containing && isa(Containing))) + + auto IsImplicitProperty = [](const PseudoObjectExpr *POE) -> bool { + const auto *E = POE->getSyntacticForm(); + if (const auto *BinOp = dyn_cast(E)) + E = BinOp->getLHS(); + const auto *PRE = dyn_cast(E); + if (!PRE) + return false; + if (PRE->isExplicitProperty()) + return false; + if (const ObjCMethodDecl *Getter = PRE->getImplicitPropertyGetter()) { + // Class properties that are explicitly defined using @property + // declarations are represented implicitly as there is no ivar for + // class properties. + if (Getter->isClassMethod() && + Getter->getCanonicalDecl()->findPropertyDecl()) + return false; + } + return true; + }; + bool IsPropCall = Containing && isa(Containing); + // Implicit property message sends are not 'implicit'. + if ((E->isImplicit() || IsPropCall) && + !(IsPropCall && + IsImplicitProperty(cast(Containing)))) Roles |= (unsigned)SymbolRole::Implicit; if (isDynamic(E)) { diff --git a/test/Index/Core/index-source.m b/test/Index/Core/index-source.m index a64c34ad2ac1..c911973a70d6 100644 --- a/test/Index/Core/index-source.m +++ b/test/Index/Core/index-source.m @@ -413,3 +413,28 @@ void classReceivers() { (void)ClassReceivers.implicit; // CHECK: [[@LINE-1]]:9 | class/ObjC | ClassReceivers | c:objc(cs)ClassReceivers | _OBJC_CLASS_$_ClassReceivers | Ref,RelCont | rel: 1 } + +@interface ImplicitProperties + +- (int)implicit; +- (void)setImplicit:(int)x; + ++ (int)classImplicit; ++ (void)setClassImplicit:(int)y; + +@end + +void testImplicitProperties(ImplicitProperties *c) { + c.implicit = 0; +// CHECK: [[@LINE-1]]:5 | instance-method/ObjC | setImplicit: | c:objc(cs)ImplicitProperties(im)setImplicit: | -[ImplicitProperties setImplicit:] | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 2 +// CHECK-NEXT: RelCall,RelCont | testImplicitProperties | c:@F@testImplicitProperties + c.implicit; +// CHECK: [[@LINE-1]]:5 | instance-method/ObjC | implicit | c:objc(cs)ImplicitProperties(im)implicit | -[ImplicitProperties implicit] | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 2 +// CHECK-NEXT: RelCall,RelCont | testImplicitProperties | c:@F@testImplicitProperties + ImplicitProperties.classImplicit = 1; +// CHECK: [[@LINE-1]]:22 | class-method/ObjC | setClassImplicit: | c:objc(cs)ImplicitProperties(cm)setClassImplicit: | +[ImplicitProperties setClassImplicit:] | Ref,Call,RelCall,RelCont | rel: 1 +// CHECK-NEXT: RelCall,RelCont | testImplicitProperties | c:@F@testImplicitProperties + ImplicitProperties.classImplicit; +// CHECK: [[@LINE-1]]:22 | class-method/ObjC | classImplicit | c:objc(cs)ImplicitProperties(cm)classImplicit | +[ImplicitProperties classImplicit] | Ref,Call,RelCall,RelCont | rel: 1 +// CHECK-NEXT: RelCall,RelCont | testImplicitProperties | c:@F@testImplicitProperties +} From 71d3b5cd916106005ef23467e3f6c7fbca7bc499 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 3 Jul 2017 14:29:13 +0000 Subject: [PATCH 194/214] clang-format: [JS] space between pseudo keywords and template literals. Summary: Before: yield`foo`; After: yield `foo`; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34938 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307023 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 6 +++++- unittests/Format/FormatTestJS.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index d78a37532fe8..471f7e135852 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2300,7 +2300,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return false; - if (Left.is(tok::identifier) && Right.is(TT_TemplateString)) + // In tagged template literals ("html`bar baz`"), there is no space between + // the tag identifier and the template string. getIdentifierInfo makes sure + // that the identifier is not a pseudo keyword like `yield`, either. + if (Left.is(tok::identifier) && Left.Tok.getIdentifierInfo() == nullptr && + Right.is(TT_TemplateString)) return false; if (Right.is(tok::star) && Left.isOneOf(Keywords.kw_function, Keywords.kw_yield)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index e84f470687ec..db23902ef3eb 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1564,6 +1564,7 @@ TEST_F(FormatTestJS, TemplateStrings) { " aaaaa( //\n" " aaaaa)\n" " })`);"); + verifyFormat("yield `hello`;"); } TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { From 650ea04ef9a1eaa5513713a2cda0b980512aa7b5 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 3 Jul 2017 15:05:14 +0000 Subject: [PATCH 195/214] [clang-format] Support text proto messages Summary: This patch adds support for textual protocol buffer messages. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek, mgorny Differential Revision: https://reviews.llvm.org/D34441 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307029 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Format/Format.h | 5 +- lib/Format/ContinuationIndenter.cpp | 42 ++-- lib/Format/Format.cpp | 7 + lib/Format/FormatToken.h | 3 +- lib/Format/TokenAnnotator.cpp | 29 ++- lib/Format/UnwrappedLineParser.cpp | 33 ++- unittests/Format/CMakeLists.txt | 1 + unittests/Format/FormatTestTextProto.cpp | 251 +++++++++++++++++++++++ 8 files changed, 341 insertions(+), 30 deletions(-) create mode 100644 unittests/Format/FormatTestTextProto.cpp diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index ee24c55fef61..c5fea62423b8 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1120,7 +1120,10 @@ struct FormatStyle { /// (https://developers.google.com/protocol-buffers/). LK_Proto, /// Should be used for TableGen code. - LK_TableGen + LK_TableGen, + /// Should be used for Protocol Buffer messages in text format + /// (https://developers.google.com/protocol-buffers/). + LK_TextProto }; bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 4197587a74c0..3bf1cd8f7c13 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -66,6 +66,16 @@ static bool startsNextParameter(const FormatToken &Current, !Style.BreakBeforeInheritanceComma)); } +static bool opensProtoMessageField(const FormatToken &LessTok, + const FormatStyle &Style) { + if (LessTok.isNot(tok::less)) + return false; + return Style.Language == FormatStyle::LK_TextProto || + (Style.Language == FormatStyle::LK_Proto && + (LessTok.NestingLevel > 0 || + (LessTok.Previous && LessTok.Previous->is(tok::equal)))); +} + ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style, const AdditionalKeywords &Keywords, const SourceManager &SourceMgr, @@ -94,6 +104,13 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent, State.LowestLevelOnLine = 0; State.IgnoreStackForComparison = false; + if (Style.Language == FormatStyle::LK_TextProto) { + // We need this in order to deal with the bin packing of text fields at + // global scope. + State.Stack.back().AvoidBinPacking = true; + State.Stack.back().BreakBeforeParameter = true; + } + // The first token has already been indented and thus consumed. moveStateToNextToken(State, DryRun, /*Newline=*/false); return State; @@ -176,7 +193,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { return true; if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) || (Previous.is(TT_ArrayInitializerLSquare) && - Previous.ParameterCount > 1)) && + Previous.ParameterCount > 1) || + opensProtoMessageField(Previous, Style)) && Style.ColumnLimit > 0 && getLengthToMatchingParen(Previous) + State.Column - 1 > getColumnLimit(State)) @@ -501,13 +519,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, } } -static bool lessOpensProtoMessageField(const FormatToken &LessTok, - const LineState &State) { - assert(LessTok.is(tok::less)); - return LessTok.NestingLevel > 0 || - (LessTok.Previous && LessTok.Previous->is(tok::equal)); -} - unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, bool DryRun) { FormatToken &Current = *State.NextToken; @@ -650,9 +661,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, // before the corresponding } or ]. if (PreviousNonComment && (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || - (Style.Language == FormatStyle::LK_Proto && - PreviousNonComment->is(tok::less) && - lessOpensProtoMessageField(*PreviousNonComment, State)) || + opensProtoMessageField(*PreviousNonComment, Style) || (PreviousNonComment->is(TT_TemplateString) && PreviousNonComment->opensScope()))) State.Stack.back().BreakBeforeClosingBrace = true; @@ -695,7 +704,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return Current.NestingLevel == 0 ? State.FirstIndent : State.Stack.back().Indent; if ((Current.isOneOf(tok::r_brace, tok::r_square) || - (Current.is(tok::greater) && Style.Language == FormatStyle::LK_Proto)) && + (Current.is(tok::greater) && + (Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto))) && State.Stack.size() > 1) { if (Current.closesBlockOrBlockTypeList(Style)) return State.Stack[State.Stack.size() - 2].NestedBlockIndent; @@ -1050,8 +1061,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall, State.Stack.back().NestedBlockIndent); if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || - (Style.Language == FormatStyle::LK_Proto && Current.is(tok::less) && - lessOpensProtoMessageField(Current, State))) { + opensProtoMessageField(Current, Style)) { if (Current.opensBlockOrBlockTypeList(Style)) { NewIndent = Style.IndentWidth + std::min(State.Column, State.Stack.back().NestedBlockIndent); @@ -1064,7 +1074,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, Current.MatchingParen->Previous->is(tok::comma); AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) || - Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments || + Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto || + !Style.BinPackArguments || (NextNoComment && NextNoComment->isOneOf(TT_DesignatedInitializerPeriod, TT_DesignatedInitializerLSquare)); diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index bb6781d79517..aa4ed8c42a70 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -56,6 +56,7 @@ template <> struct ScalarEnumerationTraits { IO.enumCase(Value, "ObjC", FormatStyle::LK_ObjC); IO.enumCase(Value, "Proto", FormatStyle::LK_Proto); IO.enumCase(Value, "TableGen", FormatStyle::LK_TableGen); + IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto); } }; @@ -631,6 +632,12 @@ FormatStyle getLLVMStyle() { } FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { + if (Language == FormatStyle::LK_TextProto) { + FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto); + GoogleStyle.Language = FormatStyle::LK_TextProto; + return GoogleStyle; + } + FormatStyle GoogleStyle = getLLVMStyle(); GoogleStyle.Language = Language; diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 0fe91adcd472..ce107e2d82a2 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -466,7 +466,8 @@ struct FormatToken { (is(tok::l_brace) && (BlockKind == BK_Block || is(TT_DictLiteral) || (!Style.Cpp11BracedListStyle && NestingLevel == 0))) || - (is(tok::less) && Style.Language == FormatStyle::LK_Proto); + (is(tok::less) && (Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto)); } /// \brief Same as opensBlockOrBlockTypeList, but for the closing token. diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 471f7e135852..888b6b67458c 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -90,7 +90,8 @@ class AnnotatingParser { } if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace) || (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext && - Style.Language != FormatStyle::LK_Proto)) + Style.Language != FormatStyle::LK_Proto && + Style.Language != FormatStyle::LK_TextProto)) return false; // If a && or || is found and interpreted as a binary operator, this set // of angles is likely part of something like "a < b && c > d". If the @@ -453,7 +454,8 @@ class AnnotatingParser { FormatToken *Previous = CurrentToken->getPreviousNonComment(); if (((CurrentToken->is(tok::colon) && (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) || - Style.Language == FormatStyle::LK_Proto) && + Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto) && (Previous->Tok.getIdentifierInfo() || Previous->is(tok::string_literal))) Previous->Type = TT_SelectorName; @@ -536,8 +538,13 @@ class AnnotatingParser { } } if (Contexts.back().ColonIsDictLiteral || - Style.Language == FormatStyle::LK_Proto) { + Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto) { Tok->Type = TT_DictLiteral; + if (Style.Language == FormatStyle::LK_TextProto) { + if (FormatToken *Previous = Tok->getPreviousNonComment()) + Previous->Type = TT_SelectorName; + } } else if (Contexts.back().ColonIsObjCMethodExpr || Line.startsWith(TT_ObjCMethodSpecifier)) { Tok->Type = TT_ObjCMethodExpr; @@ -635,12 +642,22 @@ class AnnotatingParser { return false; break; case tok::l_brace: + if (Style.Language == FormatStyle::LK_TextProto) { + FormatToken *Previous =Tok->getPreviousNonComment(); + if (Previous && Previous->Type != TT_DictLiteral) + Previous->Type = TT_SelectorName; + } if (!parseBrace()) return false; break; case tok::less: if (parseAngle()) { Tok->Type = TT_TemplateOpener; + if (Style.Language == FormatStyle::LK_TextProto) { + FormatToken *Previous = Tok->getPreviousNonComment(); + if (Previous && Previous->Type != TT_DictLiteral) + Previous->Type = TT_SelectorName; + } } else { Tok->Type = TT_BinaryOperator; NonTemplateLess.insert(Tok); @@ -1572,7 +1589,8 @@ class ExpressionParser { return prec::Conditional; if (NextNonComment && Current->is(TT_SelectorName) && (NextNonComment->is(TT_DictLiteral) || - (Style.Language == FormatStyle::LK_Proto && + ((Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto) && NextNonComment->is(tok::less)))) return prec::Assignment; if (Current->is(TT_JsComputedPropertyName)) @@ -2274,7 +2292,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (Style.isCpp()) { if (Left.is(tok::kw_operator)) return Right.is(tok::coloncolon); - } else if (Style.Language == FormatStyle::LK_Proto) { + } else if (Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto) { if (Right.is(tok::period) && Left.isOneOf(Keywords.kw_optional, Keywords.kw_required, Keywords.kw_repeated, Keywords.kw_extend)) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index ba3a4c17ee12..4b57919d1929 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -286,7 +286,10 @@ void UnwrappedLineParser::parseFile() { !Line->InPPDirective && Style.Language != FormatStyle::LK_JavaScript; ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, MustBeDeclaration); - parseLevel(/*HasOpeningBrace=*/false); + if (Style.Language == FormatStyle::LK_TextProto) + parseBracedList(); + else + parseLevel(/*HasOpeningBrace=*/false); // Make sure to format the remaining tokens. flushComments(true); addUnwrappedLine(); @@ -832,6 +835,7 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::at: nextToken(); if (FormatTok->Tok.is(tok::l_brace)) { + nextToken(); parseBracedList(); break; } @@ -996,8 +1000,10 @@ void UnwrappedLineParser::parseStructuralElement() { switch (FormatTok->Tok.getKind()) { case tok::at: nextToken(); - if (FormatTok->Tok.is(tok::l_brace)) + if (FormatTok->Tok.is(tok::l_brace)) { + nextToken(); parseBracedList(); + } break; case tok::kw_enum: // Ignore if this is part of "template Tok.is(tok::l_brace)) + if (FormatTok->Tok.is(tok::l_brace)) { + nextToken(); parseBracedList(); - else if (Style.Language == FormatStyle::LK_Proto && - FormatTok->Tok.is(tok::less)) + } else if (Style.Language == FormatStyle::LK_Proto && + FormatTok->Tok.is(tok::less)) { + nextToken(); parseBracedList(/*ContinueOnSemicolons=*/false, /*ClosingBraceKind=*/tok::greater); + } break; case tok::l_square: parseSquare(); @@ -1345,6 +1354,7 @@ bool UnwrappedLineParser::tryToParseBracedList() { assert(FormatTok->BlockKind != BK_Unknown); if (FormatTok->BlockKind == BK_Block) return false; + nextToken(); parseBracedList(); return true; } @@ -1352,7 +1362,6 @@ bool UnwrappedLineParser::tryToParseBracedList() { bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons, tok::TokenKind ClosingBraceKind) { bool HasError = false; - nextToken(); // FIXME: Once we have an expression parser in the UnwrappedLineParser, // replace this by using parseAssigmentExpression() inside. @@ -1407,6 +1416,7 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons, // Assume there are no blocks inside a braced init list apart // from the ones we explicitly parse out (like lambdas). FormatTok->BlockKind = BK_BracedInit; + nextToken(); parseBracedList(); break; case tok::semi: @@ -1459,8 +1469,10 @@ void UnwrappedLineParser::parseParens() { break; case tok::at: nextToken(); - if (FormatTok->Tok.is(tok::l_brace)) + if (FormatTok->Tok.is(tok::l_brace)) { + nextToken(); parseBracedList(); + } break; case tok::kw_class: if (Style.Language == FormatStyle::LK_JavaScript) @@ -1508,8 +1520,10 @@ void UnwrappedLineParser::parseSquare() { } case tok::at: nextToken(); - if (FormatTok->Tok.is(tok::l_brace)) + if (FormatTok->Tok.is(tok::l_brace)) { + nextToken(); parseBracedList(); + } break; default: nextToken(); @@ -1836,6 +1850,7 @@ bool UnwrappedLineParser::parseEnum() { } // Parse enum body. + nextToken(); bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true); if (HasError) { if (FormatTok->is(tok::semi)) @@ -1870,6 +1885,7 @@ void UnwrappedLineParser::parseJavaEnumBody() { FormatTok = Tokens->setPosition(StoredPosition); if (IsSimple) { + nextToken(); parseBracedList(); addUnwrappedLine(); return; @@ -2081,6 +2097,7 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() { } if (FormatTok->is(tok::l_brace)) { FormatTok->BlockKind = BK_Block; + nextToken(); parseBracedList(); } else { nextToken(); diff --git a/unittests/Format/CMakeLists.txt b/unittests/Format/CMakeLists.txt index 5c04ba1143c6..fa7e32c33d9f 100644 --- a/unittests/Format/CMakeLists.txt +++ b/unittests/Format/CMakeLists.txt @@ -11,6 +11,7 @@ add_clang_unittest(FormatTests FormatTestObjC.cpp FormatTestProto.cpp FormatTestSelective.cpp + FormatTestTextProto.cpp NamespaceEndCommentsFixerTest.cpp SortImportsTestJS.cpp SortIncludesTest.cpp diff --git a/unittests/Format/FormatTestTextProto.cpp b/unittests/Format/FormatTestTextProto.cpp new file mode 100644 index 000000000000..83e58922147e --- /dev/null +++ b/unittests/Format/FormatTestTextProto.cpp @@ -0,0 +1,251 @@ +//===- unittest/Format/FormatTestProto.cpp --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "FormatTestUtils.h" +#include "clang/Format/Format.h" +#include "llvm/Support/Debug.h" +#include "gtest/gtest.h" + +#define DEBUG_TYPE "format-test" + +namespace clang { +namespace format { + +class FormatTestTextProto : public ::testing::Test { +protected: + static std::string format(llvm::StringRef Code, unsigned Offset, + unsigned Length, const FormatStyle &Style) { + DEBUG(llvm::errs() << "---\n"); + DEBUG(llvm::errs() << Code << "\n\n"); + std::vector Ranges(1, tooling::Range(Offset, Length)); + tooling::Replacements Replaces = reformat(Style, Code, Ranges); + auto Result = applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast(Result)); + DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); + return *Result; + } + + static std::string format(llvm::StringRef Code) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto); + Style.ColumnLimit = 60; // To make writing tests easier. + return format(Code, 0, Code.size(), Style); + } + + static void verifyFormat(llvm::StringRef Code) { + EXPECT_EQ(Code.str(), format(test::messUp(Code))); + } +}; + +TEST_F(FormatTestTextProto, KeepsTopLevelEntriesFittingALine) { + verifyFormat("field_a: OK field_b: OK field_c: OK field_d: OK field_e: OK"); +} + +TEST_F(FormatTestTextProto, SupportsMessageFields) { + verifyFormat("msg_field: {}"); + + verifyFormat("msg_field: {field_a: A}"); + + verifyFormat("msg_field: {field_a: \"OK\" field_b: 123}"); + + verifyFormat("msg_field: {\n" + " field_a: 1\n" + " field_b: OK\n" + " field_c: \"OK\"\n" + " field_d: 123\n" + " field_e: 23\n" + "}"); + + verifyFormat("msg_field{}"); + + verifyFormat("msg_field{field_a: A}"); + + verifyFormat("msg_field{field_a: \"OK\" field_b: 123}"); + + verifyFormat("msg_field{\n" + " field_a: 1\n" + " field_b: OK\n" + " field_c: \"OK\"\n" + " field_d: 123\n" + " field_e: 23.0\n" + " field_f: false\n" + " field_g: 'lala'\n" + " field_h: 1234.567e-89\n" + "}"); + + verifyFormat("msg_field: {msg_field{field_a: 1}}"); + + verifyFormat("id: \"ala.bala\"\n" + "item{type: ITEM_A rank: 1 score: 90.0}\n" + "item{type: ITEM_B rank: 2 score: 70.5}\n" + "item{\n" + " type: ITEM_A\n" + " rank: 3\n" + " score: 20.0\n" + " description: \"the third item has a description\"\n" + "}"); +} + +TEST_F(FormatTestTextProto, AvoidsTopLevelBinPacking) { + verifyFormat("field_a: OK\n" + "field_b: OK\n" + "field_c: OK\n" + "field_d: OK\n" + "field_e: OK\n" + "field_f: OK"); + + verifyFormat("field_a: OK\n" + "field_b: \"OK\"\n" + "field_c: \"OK\"\n" + "msg_field: {field_d: 123}\n" + "field_e: OK\n" + "field_f: OK"); + + verifyFormat("field_a: OK\n" + "field_b: \"OK\"\n" + "field_c: \"OK\"\n" + "msg_field: {field_d: 123 field_e: OK}"); + + verifyFormat("a: {\n" + " field_a: OK\n" + " field_b{field_c: OK}\n" + " field_d: OKOKOK\n" + " field_e: OK\n" + "}"); + + verifyFormat("field_a: OK,\n" + "field_b{field_c: OK},\n" + "field_d: OKOKOK,\n" + "field_e: OK"); +} + +TEST_F(FormatTestTextProto, AddsNewlinesAfterTrailingComments) { + verifyFormat("field_a: OK // Comment\n" + "field_b: 1"); + + verifyFormat("field_a: OK\n" + "msg_field: {\n" + " field_b: OK // Comment\n" + "}"); + + verifyFormat("field_a: OK\n" + "msg_field{\n" + " field_b: OK // Comment\n" + "}"); +} + +TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) { + // Single-line tests + verifyFormat("msg_field<>"); + verifyFormat("msg_field: <>"); + verifyFormat("msg_field"); + verifyFormat("msg_field: "); + verifyFormat("msg_field>"); + verifyFormat("msg_field>>"); + verifyFormat("msg_field: >>"); + verifyFormat("msg_field"); + verifyFormat("msg_field, field_c: OK>"); + verifyFormat("msg_field>"); + verifyFormat("msg_field: "); + verifyFormat("msg_field: , field_c: OK>"); + verifyFormat("msg_field: >"); + verifyFormat("field_a: \"OK\", msg_field: , field_c: {}"); + verifyFormat("field_a, msg_field: , field_c<>"); + verifyFormat("field_a msg_field: field_c<>"); + verifyFormat("field>, field<>> field: "); + + // Multiple lines tests + verifyFormat("msg_field<\n" + " field_a: OK\n" + " field_b: \"OK\"\n" + " field_c: 1\n" + " field_d: 12.5\n" + " field_e: OK\n" + ">"); + + verifyFormat("msg_field: <>\n" + "field_c: \"OK\",\n" + "msg_field: \n" + "field_e: OK\n" + "msg_field: "); + + verifyFormat("field_a: OK,\n" + "field_b,\n" + "field_d: <12.5>,\n" + "field_e: OK"); + + verifyFormat("field_a: OK\n" + "field_b\n" + "field_d: <12.5>\n" + "field_e: OKOKOK"); + + verifyFormat("msg_field<\n" + " field_a: OK,\n" + " field_b,\n" + " field_d: <12.5>,\n" + " field_e: OK\n" + ">"); + + verifyFormat("msg_field<\n" + " field_a: ,\n" + " field_b,\n" + " field_d: <12.5>,\n" + " field_e: OK,\n" + ">"); + + verifyFormat("msg_field: <\n" + " field_a: \"OK\"\n" + " msg_field: {field_b: OK}\n" + " field_g: OK\n" + " field_g: OK\n" + " field_g: OK\n" + ">"); + + verifyFormat("field_a{\n" + " field_d: ok\n" + " field_b: \n" + " field_d: ok\n" + " field_d: ok\n" + "}"); + + verifyFormat("field_a: {\n" + " field_d: ok\n" + " field_b: \n" + " field_d: ok\n" + " field_d: ok\n" + "}"); + + verifyFormat("field_a: >\n" + "field_b<\n" + " field_b1: <>\n" + " field_b2: ok,\n" + " field_b3: <\n" + " field_x{} // Comment\n" + " field_y: {field_z: 1}\n" + " field_w: ok\n" + " >\n" + " field{\n" + " field_x<> // Comment\n" + " field_y: \n" + " field_w: ok\n" + " msg_field: <\n" + " field: <>\n" + " field: \n" + " field: \n" + " field: \n" + " field: \n" + " field: ok\n" + " >\n" + " }\n" + ">\n" + "field: OK,\n" + "field_c>>"); +} + +} // end namespace tooling +} // end namespace clang From 063721498032b28ccb1bc0a4cb257882317113bb Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 3 Jul 2017 15:31:28 +0000 Subject: [PATCH 196/214] Revert "clang-format: [JS] space between pseudo keywords and template literals." This reverts commit 71d3b5cd916106005ef23467e3f6c7fbca7bc499. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307034 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 6 +----- unittests/Format/FormatTestJS.cpp | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 888b6b67458c..a7250cf16950 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2319,11 +2319,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return false; - // In tagged template literals ("html`bar baz`"), there is no space between - // the tag identifier and the template string. getIdentifierInfo makes sure - // that the identifier is not a pseudo keyword like `yield`, either. - if (Left.is(tok::identifier) && Left.Tok.getIdentifierInfo() == nullptr && - Right.is(TT_TemplateString)) + if (Left.is(tok::identifier) && Right.is(TT_TemplateString)) return false; if (Right.is(tok::star) && Left.isOneOf(Keywords.kw_function, Keywords.kw_yield)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index db23902ef3eb..e84f470687ec 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1564,7 +1564,6 @@ TEST_F(FormatTestJS, TemplateStrings) { " aaaaa( //\n" " aaaaa)\n" " })`);"); - verifyFormat("yield `hello`;"); } TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { From 2ea9de261c4475b62359e9ac613fb1ca09676418 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Mon, 3 Jul 2017 17:59:22 +0000 Subject: [PATCH 197/214] [clang] Implement -Wcast-qual for C++ Summary: This way, the behavior of that warning flag more closely resembles that of GCC. Do note that there is at least one false-negative (see FIXME in tests). Fixes PR4802. Testing: ``` ninja check-clang-sema check-clang-semacxx ``` Reviewers: dblaikie, majnemer, rnk Reviewed By: dblaikie, rnk Subscribers: mclow.lists, cfe-commits, alexfh, rnk Differential Revision: https://reviews.llvm.org/D33102 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307045 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ReleaseNotes.rst | 3 + lib/Sema/SemaCast.cpp | 94 +++++++++++++++------ test/Sema/warn-cast-qual.c | 31 +++++++ test/SemaCXX/warn-cast-qual.cpp | 140 ++++++++++++++++++++++++++++++++ 4 files changed, 244 insertions(+), 24 deletions(-) create mode 100644 test/SemaCXX/warn-cast-qual.cpp diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index 0f49e3f979c9..8f1515dafd97 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -52,6 +52,9 @@ Major New Features Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- -Wcast-qual was implemented for C++. C-style casts are now properly + diagnosed. + - -Wunused-lambda-capture warns when a variable explicitly captured by a lambda is not used in the body of the lambda. diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 7d534263f468..ba2049d8a606 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -143,6 +143,9 @@ namespace { }; } +static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, + QualType DestType); + // The Try functions attempt a specific way of casting. If they succeed, they // return TC_Success. If their way of casting is not appropriate for the given // arguments, they return TC_NotApplicable and *may* set diag to a diagnostic @@ -427,6 +430,10 @@ static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, /// the same kind of pointer (plain or to-member). Unlike the Sema function, /// this one doesn't care if the two pointers-to-member don't point into the /// same class. This is because CastsAwayConstness doesn't care. +/// And additionally, it handles C++ references. If both the types are +/// references, then their pointee types are returned, +/// else if only one of them is reference, it's pointee type is returned, +/// and the other type is returned as-is. static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) { const PointerType *T1PtrType = T1->getAs(), *T2PtrType = T2->getAs(); @@ -475,6 +482,26 @@ static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) { return true; } + const LValueReferenceType *T1RefType = T1->getAs(), + *T2RefType = T2->getAs(); + if (T1RefType && T2RefType) { + T1 = T1RefType->getPointeeType(); + T2 = T2RefType->getPointeeType(); + return true; + } + + if (T1RefType) { + T1 = T1RefType->getPointeeType(); + // T2 = T2; + return true; + } + + if (T2RefType) { + // T1 = T1; + T2 = T2RefType->getPointeeType(); + return true; + } + return false; } @@ -503,11 +530,13 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, // the rules are non-trivial. So first we construct Tcv *...cv* as described // in C++ 5.2.11p8. assert((SrcType->isAnyPointerType() || SrcType->isMemberPointerType() || - SrcType->isBlockPointerType()) && + SrcType->isBlockPointerType() || + DestType->isLValueReferenceType()) && "Source type is not pointer or pointer to member."); assert((DestType->isAnyPointerType() || DestType->isMemberPointerType() || - DestType->isBlockPointerType()) && - "Destination type is not pointer or pointer to member."); + DestType->isBlockPointerType() || + DestType->isLValueReferenceType()) && + "Destination type is not pointer or pointer to member, or reference."); QualType UnwrappedSrcType = Self.Context.getCanonicalType(SrcType), UnwrappedDestType = Self.Context.getCanonicalType(DestType); @@ -2177,6 +2206,8 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, bool ListInitialization) { + assert(Self.getLangOpts().CPlusPlus); + // Handle placeholders. if (isPlaceholder()) { // C-style casts can resolve __unknown_any types. @@ -2580,30 +2611,42 @@ void CastOperation::CheckCStyleCast() { if (Kind == CK_BitCast) checkCastAlign(); +} + +/// DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either +/// const, volatile or both. +static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, + QualType DestType) { + if (SrcExpr.isInvalid()) + return; + + QualType SrcType = SrcExpr.get()->getType(); + if (!((SrcType->isAnyPointerType() && DestType->isAnyPointerType()) || + DestType->isLValueReferenceType())) + return; - // -Wcast-qual QualType TheOffendingSrcType, TheOffendingDestType; Qualifiers CastAwayQualifiers; - if (SrcType->isAnyPointerType() && DestType->isAnyPointerType() && - CastsAwayConstness(Self, SrcType, DestType, true, false, - &TheOffendingSrcType, &TheOffendingDestType, - &CastAwayQualifiers)) { - int qualifiers = -1; - if (CastAwayQualifiers.hasConst() && CastAwayQualifiers.hasVolatile()) { - qualifiers = 0; - } else if (CastAwayQualifiers.hasConst()) { - qualifiers = 1; - } else if (CastAwayQualifiers.hasVolatile()) { - qualifiers = 2; - } - // This is a variant of int **x; const int **y = (const int **)x; - if (qualifiers == -1) - Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) << - SrcType << DestType; - else - Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) << - TheOffendingSrcType << TheOffendingDestType << qualifiers; - } + if (!CastsAwayConstness(Self, SrcType, DestType, true, false, + &TheOffendingSrcType, &TheOffendingDestType, + &CastAwayQualifiers)) + return; + + int qualifiers = -1; + if (CastAwayQualifiers.hasConst() && CastAwayQualifiers.hasVolatile()) { + qualifiers = 0; + } else if (CastAwayQualifiers.hasConst()) { + qualifiers = 1; + } else if (CastAwayQualifiers.hasVolatile()) { + qualifiers = 2; + } + // This is a variant of int **x; const int **y = (const int **)x; + if (qualifiers == -1) + Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) + << SrcType << DestType; + else + Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) + << TheOffendingSrcType << TheOffendingDestType << qualifiers; } ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, @@ -2624,6 +2667,9 @@ ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, if (Op.SrcExpr.isInvalid()) return ExprError(); + // -Wcast-qual + DiagnoseCastQual(Op.Self, Op.SrcExpr, Op.DestType); + return Op.complete(CStyleCastExpr::Create(Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.get(), &Op.BasePath, CastTypeInfo, LPLoc, RPLoc)); diff --git a/test/Sema/warn-cast-qual.c b/test/Sema/warn-cast-qual.c index dc11f5717ebe..a682cad75ed6 100644 --- a/test/Sema/warn-cast-qual.c +++ b/test/Sema/warn-cast-qual.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -fsyntax-only -Wcast-qual -verify %s #include @@ -26,4 +27,34 @@ void foo() { const char **charptrptrc; char **charptrptr = (char **)charptrptrc; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}} + + const char *constcharptr; + char *charptr = (char *)constcharptr; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}} + const char *constcharptr2 = (char *)constcharptr; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}} + const char *charptr2 = (char *)charptr; // no warning +} + +void bar_0() { + struct C { + const int a; + int b; + }; + + const struct C S = {0, 0}; + + *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + *(int *)(&S.b) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} +} + +void bar_1() { + struct C { + const int a; + int b; + }; + + struct C S = {0, 0}; + S.b = 0; // no warning + + *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + *(int *)(&S.b) = 0; // no warning } diff --git a/test/SemaCXX/warn-cast-qual.cpp b/test/SemaCXX/warn-cast-qual.cpp new file mode 100644 index 000000000000..d1f0cc73a63d --- /dev/null +++ b/test/SemaCXX/warn-cast-qual.cpp @@ -0,0 +1,140 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual -verify %s + +#include + +// do *NOT* warn on const_cast<>() +// use clang-tidy's cppcoreguidelines-pro-type-const-cast for that. +void foo_ptr() { + const char *const ptr = 0; + char *t0 = const_cast(ptr); // no warning + + volatile char *ptr2 = 0; + char *t1 = const_cast(ptr2); // no warning + + const volatile char *ptr3 = 0; + char *t2 = const_cast(ptr3); // no warning +} + +void cstr() { + void* p0 = (void*)(const void*)"txt"; // expected-warning {{cast from 'const void *' to 'void *' drops const qualifier}} + void* p1 = (void*)"txt"; // FIXME + char* p2 = (char*)"txt"; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}} +} + +void foo_0() { + const int a = 0; + + const int &a0 = a; // no warning + const int &a1 = (const int &)a; // no warning + + int &a2 = (int &)a; // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + const int &a3 = (int &)a; // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + int &a4 = (int &)((const int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + int &a5 = (int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + const int &a6 = (int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + const int &a7 = (int &)((const int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + const int &a8 = (const int &)((int &)a); // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} +} + +void foo_1() { + volatile int a = 0; + + volatile int &a0 = a; // no warning + volatile int &a1 = (volatile int &)a; // no warning + + int &a2 = (int &)a; // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + volatile int &a3 = (int &)a; // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + int &a4 = (int &)((volatile int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + int &a5 = (int &)((int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + volatile int &a6 = (int &)((int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + volatile int &a7 = (int &)((volatile int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} + volatile int &a8 = (volatile int &)((int &)a); // expected-warning {{cast from 'volatile int' to 'int &' drops volatile qualifier}} +} + +void foo_2() { + const volatile int a = 0; + + const volatile int &a0 = a; // no warning + const volatile int &a1 = (const volatile int &)a; // no warning + + int &a2 = (int &)a; // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + const volatile int &a3 = (int &)a; // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + int &a4 = (int &)((const volatile int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + int &a5 = (int &)((int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + const volatile int &a6 = (int &)((int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + const volatile int &a7 = (int &)((const volatile int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} + const volatile int &a8 = (const volatile int &)((int &)a); // expected-warning {{cast from 'const volatile int' to 'int &' drops const and volatile qualifiers}} +} + +void bar_0() { + const int *_a = 0; + const int **a = &_a; + + int **a0 = (int **)((const int **)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + int **a1 = (int **)((int **)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + + // const int **a2 = (int **)((int **)a); + // const int **a3 = (int **)((const int **)a); + + const int **a4 = (const int **)((int **)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} expected-warning {{cast from 'int **' to 'const int **' must have all intermediate pointers const qualified to be safe}} + const int **a5 = (const int **)((const int **)a); // no warning +} + +void bar_1() { + const int *_a = 0; + const int *&a = _a; + + int *&a0 = (int *&)((const int *&)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + int *&a1 = (int *&)((int *&)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + + // const int *&a2 = (int *&)((int *&)a); + // const int *&a3 = (int *&)((const int *&)a); + + const int *&a4 = (const int *&)((int *&)a); // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} expected-warning {{cast from 'int *' to 'const int *&' must have all intermediate pointers const qualified to be safe}} + const int *&a5 = (const int *&)((const int *&)a); // no warning +} + +void baz_0() { + struct C { + void A() {} + void B() const {} + }; + + const C S; + S.B(); + + ((C &)S).B(); // expected-warning {{cast from 'const C' to 'C &' drops const qualifier}} + ((C &)S).A(); // expected-warning {{cast from 'const C' to 'C &' drops const qualifier}} + + ((C *)&S)->B(); // expected-warning {{cast from 'const C *' to 'C *' drops const qualifier}} + ((C *)&S)->A(); // expected-warning {{cast from 'const C *' to 'C *' drops const qualifier}} +} + +void baz_1() { + struct C { + const int a; + int b; + + C() : a(0) {} + }; + + { + C S; + S.b = 0; + + (int &)(S.a) = 0; // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + (int &)(S.b) = 0; // no warning + + *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + *(int *)(&S.b) = 0; // no warning + } + { + const C S; + + (int &)(S.a) = 0; // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + (int &)(S.b) = 0; // expected-warning {{cast from 'const int' to 'int &' drops const qualifier}} + + *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + *(int *)(&S.b) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + } +} From 9330fda9a0ef108d03334f20319508e409bb356d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 4 Jul 2017 00:52:24 +0000 Subject: [PATCH 198/214] [Sema] Make BreakContinueFinder handle nested loops. We don't care about break or continue statements that aren't associated with the current loop, so make sure the visitor doesn't find them. Fixes https://bugs.llvm.org/show_bug.cgi?id=32648 . Differential Revision: https://reviews.llvm.org/D34568 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307051 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmt.cpp | 67 ++++++++++++++++++++++++++--- test/Sema/loop-control.c | 48 +++++++++++++++++++++ test/SemaCXX/warn-loop-analysis.cpp | 12 ++++++ 3 files changed, 121 insertions(+), 6 deletions(-) diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index eed10b077eb8..2a38a1f8e1d8 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1544,23 +1544,78 @@ namespace { // A visitor to determine if a continue or break statement is a // subexpression. - class BreakContinueFinder : public EvaluatedExprVisitor { + class BreakContinueFinder : public ConstEvaluatedExprVisitor { SourceLocation BreakLoc; SourceLocation ContinueLoc; + bool InSwitch = false; + public: - BreakContinueFinder(Sema &S, Stmt* Body) : + BreakContinueFinder(Sema &S, const Stmt* Body) : Inherited(S.Context) { Visit(Body); } - typedef EvaluatedExprVisitor Inherited; + typedef ConstEvaluatedExprVisitor Inherited; - void VisitContinueStmt(ContinueStmt* E) { + void VisitContinueStmt(const ContinueStmt* E) { ContinueLoc = E->getContinueLoc(); } - void VisitBreakStmt(BreakStmt* E) { - BreakLoc = E->getBreakLoc(); + void VisitBreakStmt(const BreakStmt* E) { + if (!InSwitch) + BreakLoc = E->getBreakLoc(); + } + + void VisitSwitchStmt(const SwitchStmt* S) { + if (const Stmt *Init = S->getInit()) + Visit(Init); + if (const Stmt *CondVar = S->getConditionVariableDeclStmt()) + Visit(CondVar); + if (const Stmt *Cond = S->getCond()) + Visit(Cond); + + // Don't return break statements from the body of a switch. + InSwitch = true; + if (const Stmt *Body = S->getBody()) + Visit(Body); + InSwitch = false; + } + + void VisitForStmt(const ForStmt *S) { + // Only visit the init statement of a for loop; the body + // has a different break/continue scope. + if (const Stmt *Init = S->getInit()) + Visit(Init); + } + + void VisitWhileStmt(const WhileStmt *) { + // Do nothing; the children of a while loop have a different + // break/continue scope. + } + + void VisitDoStmt(const DoStmt *) { + // Do nothing; the children of a while loop have a different + // break/continue scope. + } + + void VisitCXXForRangeStmt(const CXXForRangeStmt *S) { + // Only visit the initialization of a for loop; the body + // has a different break/continue scope. + if (const Stmt *Range = S->getRangeStmt()) + Visit(Range); + if (const Stmt *Begin = S->getBeginStmt()) + Visit(Begin); + if (const Stmt *End = S->getEndStmt()) + Visit(End); + } + + void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { + // Only visit the initialization of a for loop; the body + // has a different break/continue scope. + if (const Stmt *Element = S->getElement()) + Visit(Element); + if (const Stmt *Collection = S->getCollection()) + Visit(Collection); } bool ContinueFound() { return ContinueLoc.isValid(); } diff --git a/test/Sema/loop-control.c b/test/Sema/loop-control.c index 6c33e8437bd0..1fc35d10218e 100644 --- a/test/Sema/loop-control.c +++ b/test/Sema/loop-control.c @@ -119,3 +119,51 @@ void pr8880_23(int x, int y) { for ( ; ({ ++y; break; y;}); ++y) {} // expected-warning{{'break' is bound to loop, GCC binds it to switch}} } } + +void pr32648_1(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; switch (y) { case 0: break; } y;}); ++y) {} // no warning + } +} + +void pr32648_2(int x, int y) { + while(x) { + for ( ; ({ ++y; switch (y) { case 0: continue; } y;}); ++y) {} // expected-warning {{'continue' is bound to current loop, GCC binds it to the enclosing loop}} + } +} + +void pr32648_3(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; for (; y; y++) { break; } y;}); ++y) {} // no warning + } +} + +void pr32648_4(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; for (({ break; }); y; y++) { } y;}); ++y) {} // expected-warning{{'break' is bound to loop, GCC binds it to switch}} + } +} + +void pr32648_5(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; while (({ break; y; })) {} y;}); ++y) {} // expected-warning{{'break' is bound to current loop, GCC binds it to the enclosing loop}} + } +} + +void pr32648_6(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; do {} while (({ break; y; })); y;}); ++y) {} // expected-warning{{'break' is bound to current loop, GCC binds it to the enclosing loop}} + } +} + +void pr32648_7(int x, int y) { + switch(x) { + case 1: + for ( ; ({ ++y; do { break; } while (y); y;}); ++y) {} // no warning + } +} diff --git a/test/SemaCXX/warn-loop-analysis.cpp b/test/SemaCXX/warn-loop-analysis.cpp index 25ec7a7862ed..2934003848a2 100644 --- a/test/SemaCXX/warn-loop-analysis.cpp +++ b/test/SemaCXX/warn-loop-analysis.cpp @@ -202,6 +202,12 @@ void test7() { if (true) continue; i--; } + + // But do warn if the continue is in a nested loop. + for (;;i--) { // expected-note{{decremented here}} + for (int j = 0; j < 10; ++j) continue; + i--; // expected-warning{{decremented both}} + } } struct iterator { @@ -259,6 +265,12 @@ void test8() { if (true) continue; i--; } + + // But do warn if the continue is in a nested loop. + for (;;i--) { // expected-note{{decremented here}} + for (int j = 0; j < 10; ++j) continue; + i--; // expected-warning{{decremented both}} + } } int f(int); From fa27e41eb8de3f91ee3901e8de30df57449fabcc Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Tue, 4 Jul 2017 01:02:19 +0000 Subject: [PATCH 199/214] [CodeGen] Check key function for typeinfo import If the imported class does not have a key function, we should emit its typeinfo locally instead of attempting to import it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307052 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/ItaniumCXXABI.cpp | 10 +++++++--- test/CodeGenCXX/windows-itanium-type-info.cpp | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 39efb9f43921..e6d38aff340d 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -2732,7 +2732,9 @@ static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM, // function. bool IsDLLImport = RD->hasAttr(); if (CGM.getVTables().isVTableExternal(RD)) - return IsDLLImport ? false : true; + return IsDLLImport && !CGM.getTriple().isWindowsItaniumEnvironment() + ? false + : true; if (IsDLLImport) return true; @@ -2968,7 +2970,8 @@ static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM, if (RD->hasAttr()) return llvm::GlobalValue::WeakODRLinkage; if (CGM.getTriple().isWindowsItaniumEnvironment()) - if (RD->hasAttr()) + if (RD->hasAttr() && + ShouldUseExternalRTTIDescriptor(CGM, Ty)) return llvm::GlobalValue::ExternalLinkage; if (RD->isDynamicClass()) { llvm::GlobalValue::LinkageTypes LT = CGM.getVTableLinkage(RD); @@ -3181,7 +3184,8 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force, if (DLLExport || (RD && RD->hasAttr())) { TypeName->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); - } else if (CGM.getLangOpts().RTTI && RD && RD->hasAttr()) { + } else if (RD && RD->hasAttr() && + ShouldUseExternalRTTIDescriptor(CGM, Ty)) { TypeName->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); diff --git a/test/CodeGenCXX/windows-itanium-type-info.cpp b/test/CodeGenCXX/windows-itanium-type-info.cpp index ad89318f599e..285b59815da2 100644 --- a/test/CodeGenCXX/windows-itanium-type-info.cpp +++ b/test/CodeGenCXX/windows-itanium-type-info.cpp @@ -32,9 +32,15 @@ void f() { // CHECK-DAG: @_ZTV7derived = dllexport unnamed_addr constant // CHECK-DAG: @_ZTI4base = external dllimport constant -// CHECK-DAG: @_ZTS4base = external dllimport constant -// CHECK-NOT: @_ZTV4base = external dllimport constant // CHECK-EH-IMPORT: @_ZTS4base = linkonce_odr constant // CHECK-EH-IMPORT: @_ZTI4base = linkonce_odr constant +struct __declspec(dllimport) gatekeeper {}; +struct zuul : gatekeeper { + virtual ~zuul(); +}; +zuul::~zuul() {} + +// CHECK-DAG: @_ZTI10gatekeeper = linkonce_odr constant +// CHECK-DAG: @_ZTS10gatekeeper = linkonce_odr constant From 1389a66fc6a3afe6f18bfa84a69286481b4c3c93 Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Tue, 4 Jul 2017 11:50:23 +0000 Subject: [PATCH 200/214] [OpenCL] Rename err_opencl_enqueue_kernel_expected_type Rename err_opencl_enqueue_kernel_expected_type so that other builtins can use the same diagnostic. https://reviews.llvm.org/D34948 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307067 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 5 ++-- lib/Sema/SemaChecking.cpp | 33 +++++++++++---------- test/SemaOpenCL/cl20-device-side-enqueue.cl | 16 +++++----- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 805bcb2a3580..965f8fc0405a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -8457,8 +8457,6 @@ def err_opencl_builtin_to_addr_invalid_arg : Error< // OpenCL v2.0 s6.13.17 Enqueue kernel restrictions. def err_opencl_enqueue_kernel_incorrect_args : Error< "illegal call to enqueue_kernel, incorrect argument types">; -def err_opencl_enqueue_kernel_expected_type : Error< - "illegal call to enqueue_kernel, expected %0 argument type">; def err_opencl_enqueue_kernel_local_size_args : Error< "mismatch in number of block parameters and local size arguments passed">; def err_opencl_enqueue_kernel_invalid_local_size_type : Error< @@ -8468,6 +8466,9 @@ def err_opencl_enqueue_kernel_blocks_non_local_void_args : Error< def err_opencl_enqueue_kernel_blocks_no_args : Error< "blocks with parameters are not accepted in this prototype of enqueue_kernel call">; +def err_opencl_builtin_expected_type : Error< + "illegal call to %0, expected %1 argument type">; + // OpenCL v2.2 s2.1.2.3 - Vector Component Access def ext_opencl_ext_vector_type_rgba_selector: ExtWarn< "vector component name '%0' is an OpenCL version 2.2 feature">, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 845c4bf61b7a..41dafa82ca18 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -309,7 +309,8 @@ static bool SemaOpenCLBuiltinKernelWorkGroupSize(Sema &S, CallExpr *TheCall) { Expr *BlockArg = TheCall->getArg(0); if (!isBlockPointer(BlockArg)) { S.Diag(BlockArg->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) << "block"; + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "block"; return true; } return checkOpenCLBlockArgs(S, BlockArg); @@ -394,24 +395,24 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { // First argument always needs to be a queue_t type. if (!Arg0->getType()->isQueueT()) { S.Diag(TheCall->getArg(0)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) - << S.Context.OCLQueueTy; + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << S.Context.OCLQueueTy; return true; } // Second argument always needs to be a kernel_enqueue_flags_t enum value. if (!Arg1->getType()->isIntegerType()) { S.Diag(TheCall->getArg(1)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) - << "'kernel_enqueue_flags_t' (i.e. uint)"; + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "'kernel_enqueue_flags_t' (i.e. uint)"; return true; } // Third argument is always an ndrange_t type. if (Arg2->getType().getUnqualifiedType().getAsString() != "ndrange_t") { S.Diag(TheCall->getArg(2)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) - << "'ndrange_t'"; + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "'ndrange_t'"; return true; } @@ -420,8 +421,8 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { if (NumArgs == 4) { // check that the last argument is the right block type. if (!isBlockPointer(Arg3)) { - S.Diag(Arg3->getLocStart(), diag::err_opencl_enqueue_kernel_expected_type) - << "block"; + S.Diag(Arg3->getLocStart(), diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "block"; return true; } // we have a block type, check the prototype @@ -443,8 +444,8 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { // check common block argument. Expr *Arg6 = TheCall->getArg(6); if (!isBlockPointer(Arg6)) { - S.Diag(Arg6->getLocStart(), diag::err_opencl_enqueue_kernel_expected_type) - << "block"; + S.Diag(Arg6->getLocStart(), diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "block"; return true; } if (checkOpenCLBlockArgs(S, Arg6)) @@ -453,8 +454,8 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { // Forth argument has to be any integer type. if (!Arg3->getType()->isIntegerType()) { S.Diag(TheCall->getArg(3)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) - << "integer"; + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << "integer"; return true; } // check remaining common arguments. @@ -466,7 +467,8 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { Expr::NPC_ValueDependentIsNotNull) && !Arg4->getType()->getPointeeOrArrayElementType()->isClkEventT()) { S.Diag(TheCall->getArg(4)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << S.Context.getPointerType(S.Context.OCLClkEventTy); return true; } @@ -477,7 +479,8 @@ static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { !(Arg5->getType()->isPointerType() && Arg5->getType()->getPointeeType()->isClkEventT())) { S.Diag(TheCall->getArg(5)->getLocStart(), - diag::err_opencl_enqueue_kernel_expected_type) + diag::err_opencl_builtin_expected_type) + << TheCall->getDirectCallee() << S.Context.getPointerType(S.Context.OCLClkEventTy); return true; } diff --git a/test/SemaOpenCL/cl20-device-side-enqueue.cl b/test/SemaOpenCL/cl20-device-side-enqueue.cl index bafbe447ee28..3f6527afeadc 100644 --- a/test/SemaOpenCL/cl20-device-side-enqueue.cl +++ b/test/SemaOpenCL/cl20-device-side-enqueue.cl @@ -19,19 +19,19 @@ kernel void enqueue_kernel_tests() { return 0; }); - enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to enqueue_kernel, expected 'queue_t' argument type}} + enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}} return 0; }); - enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to enqueue_kernel, expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}} + enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}} return 0; }); - enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to enqueue_kernel, expected 'ndrange_t' argument type}} + enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}} return 0; }); - enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to enqueue_kernel, expected block argument}} + enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} enqueue_kernel(default_queue, flags, ndrange, ^(int i) { // expected-error{{blocks with parameters are not accepted in this prototype of enqueue_kernel call}} return 0; @@ -46,21 +46,21 @@ kernel void enqueue_kernel_tests() { return 0; }); - enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to enqueue_kernel, expected integer argument type}} + enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected integer argument type}} return 0; }); - enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to enqueue_kernel, expected 'clk_event_t *' argument type}} + enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}} { return 0; }); - enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, vptr, ^(void) // expected-error{{illegal call to enqueue_kernel, expected 'clk_event_t *' argument type}} + enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, vptr, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}} { return 0; }); - enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to enqueue_kernel, expected block argument}} + enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} // Testing the third overload type enqueue_kernel(default_queue, flags, ndrange, From e762c504a0b4cddf10389e46516492881b85e87b Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 4 Jul 2017 12:50:53 +0000 Subject: [PATCH 201/214] [index] Index nested name qualifiers in a forward declaration of a class template specialization rdar://33122110 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307074 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexDecl.cpp | 2 ++ test/Index/Core/index-source.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index d1127722c8ca..c5230c0f9acf 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -618,6 +618,8 @@ class IndexingDeclVisitor : public ConstDeclVisitor { Template.is() ? (Decl *)Template.get() : Template.get(); + if (!D->isThisDeclarationADefinition()) + IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D); IndexCtx.indexTagDecl( D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf), SpecializationOf)); diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 6d20fdd48e50..4864d6cf0150 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -496,3 +496,19 @@ void localStructuredBindingAndRef() { } } + +namespace rd33122110 { + +struct Outer { + template + struct Nested { }; +}; + +} + +template<> +struct rd33122110::Outer::Nested; +// CHECK: [[@LINE-1]]:8 | namespace/C++ | rd33122110 | c:@N@rd33122110 | | Ref,RelCont | rel: 1 +// CHECK-NEXT: RelCont | Nested | c:@N@rd33122110@S@Outer@S@Nested>#I +// CHECK: [[@LINE-3]]:20 | struct/C++ | Outer | c:@N@rd33122110@S@Outer | | Ref,RelCont | rel: 1 +// CHECK-NEXT: RelCont | Nested | c:@N@rd33122110@S@Outer@S@Nested>#I From e20a5f4e97e6bde6c10d591e8466b030b717d258 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 4 Jul 2017 15:30:21 +0000 Subject: [PATCH 202/214] clang-format: [JS] space between pseudo keywords and template literals. Summary: Before: yield`foo`; After: yield `foo`; This reinstates commit 71d3b5cd91 / r307023 and fixes the logic by introducing an explicit table of JavaScript pseudo keywords. Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34953 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307087 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 20 ++++++++++++++++++++ lib/Format/TokenAnnotator.cpp | 6 +++++- unittests/Format/FormatTestJS.cpp | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index ce107e2d82a2..4ea81baf59d6 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -21,6 +21,7 @@ #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" #include +#include namespace clang { namespace format { @@ -645,6 +646,13 @@ struct AdditionalKeywords { kw_var = &IdentTable.get("var"); kw_yield = &IdentTable.get("yield"); + JsExtraKeywords = std::unordered_set( + {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from, + kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set, + kw_type, kw_var, kw_yield, + // Keywords from the Java section. + kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface}); + kw_abstract = &IdentTable.get("abstract"); kw_assert = &IdentTable.get("assert"); kw_extends = &IdentTable.get("extends"); @@ -733,6 +741,18 @@ struct AdditionalKeywords { IdentifierInfo *kw_qsignals; IdentifierInfo *kw_slots; IdentifierInfo *kw_qslots; + + /// \brief Returns \c true if \p Tok is a true JavaScript identifier, returns + /// \c false if it is a keyword or a pseudo keyword. + bool IsJavaScriptIdentifier(const FormatToken &Tok) const { + return Tok.is(tok::identifier) && + JsExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == + JsExtraKeywords.end(); + } + +private: + /// \brief The JavaScript keywords beyond the C++ keyword set. + std::unordered_set JsExtraKeywords; }; } // namespace format diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a7250cf16950..821c33a3384f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2319,7 +2319,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return false; - if (Left.is(tok::identifier) && Right.is(TT_TemplateString)) + // In tagged template literals ("html`bar baz`"), there is no space between + // the tag identifier and the template string. getIdentifierInfo makes sure + // that the identifier is not a pseudo keyword like `yield`, either. + if (Left.is(tok::identifier) && Keywords.IsJavaScriptIdentifier(Left) && + Right.is(TT_TemplateString)) return false; if (Right.is(tok::star) && Left.isOneOf(Keywords.kw_function, Keywords.kw_yield)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index e84f470687ec..8c6068171364 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1622,6 +1622,7 @@ TEST_F(FormatTestJS, NestedTemplateStrings) { TEST_F(FormatTestJS, TaggedTemplateStrings) { verifyFormat("var x = html`

    `;"); + verifyFormat("yield `hello`;"); } TEST_F(FormatTestJS, CastSyntax) { From 2382d78024b46e906d5fdda758874f9d25ee3c6f Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Tue, 4 Jul 2017 19:55:56 +0000 Subject: [PATCH 203/214] Enable LLVM asan support for NetBSD/amd64 Summary: Enable LLVM asan sanitizer for NetBSD/amd64. Don't generate -ldl for dlopen(3)-like functions on NetBSD. These features are available in libc on NetBSD. Sponsored by Reviewers: joerg, eugenis, kcc, dim Reviewed By: dim Subscribers: #clang, #sanitizers Tags: #clang, #sanitizers Differential Revision: https://reviews.llvm.org/D34960 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307104 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/CommonArgs.cpp | 1 + lib/Driver/ToolChains/NetBSD.cpp | 13 +++++++++++++ lib/Driver/ToolChains/NetBSD.h | 1 + 3 files changed, 15 insertions(+) diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index e8bb703054de..00bd60bc24bb 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -524,6 +524,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC, CmdArgs.push_back("-lm"); // There's no libdl on FreeBSD or RTEMS. if (TC.getTriple().getOS() != llvm::Triple::FreeBSD && + TC.getTriple().getOS() != llvm::Triple::NetBSD && TC.getTriple().getOS() != llvm::Triple::RTEMS) CmdArgs.push_back("-ldl"); } diff --git a/lib/Driver/ToolChains/NetBSD.cpp b/lib/Driver/ToolChains/NetBSD.cpp index d7d3ad61df42..a1a3108cb28d 100644 --- a/lib/Driver/ToolChains/NetBSD.cpp +++ b/lib/Driver/ToolChains/NetBSD.cpp @@ -15,6 +15,7 @@ #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Options.h" +#include "clang/Driver/SanitizerArgs.h" #include "llvm/Option/ArgList.h" using namespace clang::driver; @@ -246,6 +247,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); + bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); unsigned Major, Minor, Micro; @@ -279,6 +281,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } + if (NeedsSanitizerDeps) + linkSanitizerRuntimeDeps(getToolChain(), CmdArgs); if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lc"); @@ -410,3 +414,12 @@ void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/g++", "", "", "", "", DriverArgs, CC1Args); } + +SanitizerMask NetBSD::getSupportedSanitizers() const { + const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; + SanitizerMask Res = ToolChain::getSupportedSanitizers(); + if (IsX86_64) { + Res |= SanitizerKind::Address; + } + return Res; +} diff --git a/lib/Driver/ToolChains/NetBSD.h b/lib/Driver/ToolChains/NetBSD.h index d53aa6867872..412d0815e81a 100644 --- a/lib/Driver/ToolChains/NetBSD.h +++ b/lib/Driver/ToolChains/NetBSD.h @@ -66,6 +66,7 @@ class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF { llvm::opt::ArgStringList &CC1Args) const override; bool IsUnwindTablesDefault() const override { return true; } + SanitizerMask getSupportedSanitizers() const override; protected: Tool *buildAssembler() const override; From 9ab24b50c19a33c6868f9dde7fce1dac915e6a6e Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Tue, 4 Jul 2017 19:57:18 +0000 Subject: [PATCH 204/214] [AMDGPU] Fix regressions on mesa/clover with libclc due to address space Currently AMDGPUTargetInfo does not initialize AddrSpaceMap in constructor, which causes regressions in mesa/clover with libclc. This patch fixes that. Differential Revision: https://reviews.llvm.org/D34987 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307105 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 28 ++++++++++++++++++---------- test/CodeGenOpenCL/address-spaces.cl | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 4f04489a4a10..4ff61eb52205 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -2049,7 +2049,7 @@ ArrayRef NVPTXTargetInfo::getGCCRegNames() const { return llvm::makeArrayRef(GCCRegNames); } -static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = { +static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = { 4, // Default 1, // opencl_global 3, // opencl_local @@ -2059,7 +2059,7 @@ static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = { 2, // cuda_constant 3 // cuda_shared }; -static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = { +static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = { 0, // Default 1, // opencl_global 3, // opencl_local @@ -2069,7 +2069,7 @@ static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = { 2, // cuda_constant 3 // cuda_shared }; -static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = { +static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = { 0, // Default 1, // opencl_global 3, // opencl_local @@ -2079,7 +2079,7 @@ static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = { 2, // cuda_constant 3 // cuda_shared }; -static const LangAS::Map AMDGPUOpenCLGenericIsZeroMap = { +static const LangAS::Map AMDGPUGenIsZeroDefIsPrivMap = { 5, // Default 1, // opencl_global 3, // opencl_local @@ -2184,20 +2184,28 @@ class AMDGPUTargetInfo final : public TargetInfo { : DataLayoutStringR600); assert(DataLayout->getAllocaAddrSpace() == AS.Private); + setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D || + Triple.getEnvironment() == llvm::Triple::OpenCL || + Triple.getEnvironmentName() == "amdgizcl" || + !isAMDGCN(Triple)); UseAddrSpaceMapMangling = true; } - void adjust(LangOptions &Opts) override { - TargetInfo::adjust(Opts); + void setAddressSpaceMap(bool DefaultIsPrivate) { if (isGenericZero(getTriple())) { - AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLGenericIsZeroMap - : &AMDGPUNonOpenCLGenericIsZeroMap; + AddrSpaceMap = DefaultIsPrivate ? &AMDGPUGenIsZeroDefIsPrivMap + : &AMDGPUGenIsZeroDefIsGenMap; } else { - AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLPrivateIsZeroMap - : &AMDGPUNonOpenCLPrivateIsZeroMap; + AddrSpaceMap = DefaultIsPrivate ? &AMDGPUPrivIsZeroDefIsPrivMap + : &AMDGPUPrivIsZeroDefIsGenMap; } } + void adjust(LangOptions &Opts) override { + TargetInfo::adjust(Opts); + setAddressSpaceMap(Opts.OpenCL || !isAMDGCN(getTriple())); + } + uint64_t getPointerWidthV(unsigned AddrSpace) const override { if (GPU <= GK_CAYMAN) return 32; diff --git a/test/CodeGenOpenCL/address-spaces.cl b/test/CodeGenOpenCL/address-spaces.cl index 7c665286547a..488b8f9d480e 100644 --- a/test/CodeGenOpenCL/address-spaces.cl +++ b/test/CodeGenOpenCL/address-spaces.cl @@ -4,6 +4,8 @@ // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,GIZ // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ +// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s +// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s // SPIR: i32* %arg // GIZ: i32 addrspace(5)* %arg From 16280f9d13d776349f9dacd3378e307d662f4769 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 5 Jul 2017 01:42:07 +0000 Subject: [PATCH 205/214] [modules ts] Declarations from a module interface unit are only visible outside the module if declared in an export block. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307115 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclBase.h | 2 +- include/clang/Sema/Sema.h | 2 ++ lib/AST/DeclBase.cpp | 2 +- lib/Parse/Parser.cpp | 2 ++ lib/Sema/Sema.cpp | 12 +++++++ lib/Sema/SemaDecl.cpp | 35 ++++++++++++------- lib/Sema/SemaLookup.cpp | 28 +++++++++++---- .../modules-ts/basic/basic.link/p2/module.cpp | 17 +++++++++ .../basic/basic.link/p2/module.cppm | 29 +++++++++++++++ .../modules-ts/basic/basic.link/p2/other.cpp | 16 +++++++++ .../dcl.module/dcl.module.import/p1.cpp | 4 +-- test/SemaCXX/modules-ts.cppm | 8 ++++- 12 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 test/CXX/modules-ts/basic/basic.link/p2/module.cpp create mode 100644 test/CXX/modules-ts/basic/basic.link/p2/module.cppm create mode 100644 test/CXX/modules-ts/basic/basic.link/p2/other.cpp diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 0f1f481ae49b..8658d886a982 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -749,7 +749,7 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// Set that this declaration is globally visible, even if it came from a /// module that is not visible. void setVisibleDespiteOwningModule() { - if (hasOwningModule()) + if (getModuleOwnershipKind() == ModuleOwnershipKind::VisibleWhenImported) setModuleOwnershipKind(ModuleOwnershipKind::Visible); } diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 1fc0b2e502b7..da961ab7e84c 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1266,6 +1266,7 @@ class Sema { void emitAndClearUnusedLocalTypedefWarnings(); + void ActOnStartOfTranslationUnit(); void ActOnEndOfTranslationUnit(); void CheckDelegatingCtorCycles(); @@ -1541,6 +1542,7 @@ class Sema { llvm::SmallVectorImpl *Modules); bool hasVisibleMergedDefinition(NamedDecl *Def); + bool hasMergedDefinitionInCurrentModule(NamedDecl *Def); /// Determine if \p D and \p Suggested have a structurally compatible /// layout as described in C11 6.2.7/1. diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index a0594a020362..842ae9b6cc8b 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -283,7 +283,7 @@ void Decl::setLexicalDeclContext(DeclContext *DC) { setLocalOwningModule(cast(DC)->getOwningModule()); } - assert((!hasOwningModule() || getOwningModule()) && + assert((!hasOwningModule() || getOwningModule() || isModulePrivate()) && "hidden declaration has no owning module"); } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index af29b5e9c673..1ed7ef966358 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -526,6 +526,8 @@ void Parser::LateTemplateParserCleanupCallback(void *P) { } bool Parser::ParseFirstTopLevelDecl(DeclGroupPtrTy &Result) { + Actions.ActOnStartOfTranslationUnit(); + // C11 6.9p1 says translation units must have at least one top-level // declaration. C++ doesn't have this restriction. We also don't want to // complain if we have a precompiled header, although technically if the PCH diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 34f5e26be810..dc9f977d41ac 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -705,6 +705,18 @@ void Sema::emitAndClearUnusedLocalTypedefWarnings() { UnusedLocalTypedefNameCandidates.clear(); } +/// This is called before the very first declaration in the translation unit +/// is parsed. Note that the ASTContext may have already injected some +/// declarations. +void Sema::ActOnStartOfTranslationUnit() { + if (getLangOpts().ModulesTS) { + // We start in the global module; all those declarations are implicitly + // module-private (though they do not have module linkage). + Context.getTranslationUnitDecl()->setModuleOwnershipKind( + Decl::ModuleOwnershipKind::ModulePrivate); + } +} + /// ActOnEndOfTranslationUnit - This is called at the very end of the /// translation unit when EOF is reached and all but the top-level scope is /// popped. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ab2661cd7131..31b24f91c1d9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -16054,8 +16054,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, return nullptr; } - // FIXME: Create a ModuleDecl and return it. - // FIXME: Most of this work should be done by the preprocessor rather than // here, in order to support macro import. @@ -16069,6 +16067,8 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, ModuleName += Piece.first->getName(); } + // FIXME: If we've already seen a module-declaration, report an error. + // If a module name was explicitly specified on the command line, it must be // correct. if (!getLangOpts().CurrentModule.empty() && @@ -16081,6 +16081,7 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, const_cast(getLangOpts()).CurrentModule = ModuleName; auto &Map = PP.getHeaderSearchInfo().getModuleMap(); + Module *Mod; switch (MDK) { case ModuleDeclKind::Module: { @@ -16099,12 +16100,9 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, } // Create a Module for the module that we're defining. - Module *Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName); + Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName); assert(Mod && "module creation should not fail"); - - // Enter the semantic scope of the module. - ActOnModuleBegin(ModuleLoc, Mod); - return nullptr; + break; } case ModuleDeclKind::Partition: @@ -16114,14 +16112,26 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, case ModuleDeclKind::Implementation: std::pair ModuleNameLoc( PP.getIdentifierInfo(ModuleName), Path[0].second); - - DeclResult Import = ActOnModuleImport(ModuleLoc, ModuleLoc, ModuleNameLoc); - if (Import.isInvalid()) + Mod = getModuleLoader().loadModule(ModuleLoc, Path, Module::AllVisible, + /*IsIncludeDirective=*/false); + if (!Mod) return nullptr; - return ConvertDeclToDeclGroup(Import.get()); + break; } - llvm_unreachable("unexpected module decl kind"); + // Enter the semantic scope of the module. + ModuleScopes.push_back({}); + ModuleScopes.back().Module = Mod; + ModuleScopes.back().OuterVisibleModules = std::move(VisibleModules); + VisibleModules.setVisible(Mod, ModuleLoc); + + // From now on, we have an owning module for all declarations we see. + // However, those declarations are module-private unless explicitly + // exported. + Context.getTranslationUnitDecl()->setLocalOwningModule(Mod); + + // FIXME: Create a ModuleDecl. + return nullptr; } DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, @@ -16310,6 +16320,7 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, CurContext->addDecl(D); PushDeclContext(S, D); + D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::VisibleWhenImported); return D; } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 2e7fb875a276..63b3f6a1cb2b 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1395,6 +1395,13 @@ bool Sema::hasVisibleMergedDefinition(NamedDecl *Def) { return false; } +bool Sema::hasMergedDefinitionInCurrentModule(NamedDecl *Def) { + for (Module *Merged : Context.getModulesWithMergedDefinition(Def)) + if (Merged->getTopLevelModuleName() == getLangOpts().CurrentModule) + return true; + return false; +} + template static bool hasVisibleDefaultArgument(Sema &S, const ParmDecl *D, @@ -1495,16 +1502,25 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { assert(D->isHidden() && "should not call this: not in slow case"); Module *DeclModule = SemaRef.getOwningModule(D); - assert(DeclModule && "hidden decl not from a module"); + if (!DeclModule) { + // A module-private declaration with no owning module means this is in the + // global module in the C++ Modules TS. This is visible within the same + // translation unit only. + // FIXME: Don't assume that "same translation unit" means the same thing + // as "not from an AST file". + assert(D->isModulePrivate() && "hidden decl has no module"); + return !D->isFromASTFile(); + } // If the owning module is visible, and the decl is not module private, // then the decl is visible too. (Module private is ignored within the same // top-level module.) - // FIXME: Check the owning module for module-private declarations rather than - // assuming "same AST file" is the same thing as "same module". - if ((!D->isFromASTFile() || !D->isModulePrivate()) && - (SemaRef.isModuleVisible(DeclModule) || - SemaRef.hasVisibleMergedDefinition(D))) + if (D->isModulePrivate() + ? DeclModule->getTopLevelModuleName() == + SemaRef.getLangOpts().CurrentModule || + SemaRef.hasMergedDefinitionInCurrentModule(D) + : SemaRef.isModuleVisible(DeclModule) || + SemaRef.hasVisibleMergedDefinition(D)) return true; // If this declaration is not at namespace scope nor module-private, diff --git a/test/CXX/modules-ts/basic/basic.link/p2/module.cpp b/test/CXX/modules-ts/basic/basic.link/p2/module.cpp new file mode 100644 index 000000000000..3fc6044d8e94 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.link/p2/module.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c++1z -fmodules-ts %S/module.cppm -emit-module-interface -o %t +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -fmodule-file=%t %s -verify +// expected-no-diagnostics +module M; + +// FIXME: Use of internal linkage entities should be rejected. +void use_from_module_impl() { + external_linkage_fn(); + module_linkage_fn(); + internal_linkage_fn(); + (void)external_linkage_class{}; + (void)module_linkage_class{}; + (void)internal_linkage_class{}; + (void)external_linkage_var; + (void)module_linkage_var; + (void)internal_linkage_var; +} diff --git a/test/CXX/modules-ts/basic/basic.link/p2/module.cppm b/test/CXX/modules-ts/basic/basic.link/p2/module.cppm new file mode 100644 index 000000000000..bb261700db84 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.link/p2/module.cppm @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -std=c++1z -fmodules-ts %s -verify +// expected-no-diagnostics +export module M; + +export int external_linkage_var; +int module_linkage_var; +static int internal_linkage_var; + +export void external_linkage_fn() {} +void module_linkage_fn() {} +static void internal_linkage_fn() {} + +export struct external_linkage_class {}; +struct module_linkage_class {}; +namespace { + struct internal_linkage_class {}; +} + +void use() { + external_linkage_fn(); + module_linkage_fn(); + internal_linkage_fn(); + (void)external_linkage_class{}; + (void)module_linkage_class{}; + (void)internal_linkage_class{}; + (void)external_linkage_var; + (void)module_linkage_var; + (void)internal_linkage_var; +} diff --git a/test/CXX/modules-ts/basic/basic.link/p2/other.cpp b/test/CXX/modules-ts/basic/basic.link/p2/other.cpp new file mode 100644 index 000000000000..8370777e7ed4 --- /dev/null +++ b/test/CXX/modules-ts/basic/basic.link/p2/other.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++1z -fmodules-ts %S/module.cppm -emit-module-interface -o %t +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -fmodule-file=%t %s -verify +import M; + +void use_from_module_impl() { + external_linkage_fn(); + module_linkage_fn(); // expected-error {{undeclared identifier}} + internal_linkage_fn(); // expected-error {{undeclared identifier}} + (void)external_linkage_class{}; + (void)module_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}} + (void)internal_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}} + // expected-note@module.cppm:9 {{here}} + (void)external_linkage_var; + (void)module_linkage_var; // expected-error {{undeclared identifier}} + (void)internal_linkage_var; // expected-error {{undeclared identifier}} +} diff --git a/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp b/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp index aaf43d6584a4..aad31b4b46d1 100644 --- a/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp +++ b/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %t // RUN: mkdir -p %t -// RUN: echo 'export module x; int a, b;' > %t/x.cppm -// RUN: echo 'export module x.y; int c;' > %t/x.y.cppm +// RUN: echo 'export module x; export int a, b;' > %t/x.cppm +// RUN: echo 'export module x.y; export int c;' > %t/x.y.cppm // // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm diff --git a/test/SemaCXX/modules-ts.cppm b/test/SemaCXX/modules-ts.cppm index 29122ec7dab5..2ea4958bffda 100644 --- a/test/SemaCXX/modules-ts.cppm +++ b/test/SemaCXX/modules-ts.cppm @@ -13,7 +13,13 @@ export module foo; // expected-note@modules-ts.cppm:* {{loaded from}} #endif -static int m; // ok, internal linkage, so no redefinition error +static int m; +#if TEST == 2 // FIXME: 'm' has internal linkage, so there should be no error here +// expected-error@-2 {{redefinition of '}} +// expected-note@-3 {{unguarded header; consider using #ifdef guards or #pragma once}} +// FIXME: We should drop the "header from" in this diagnostic. +// expected-note-re@modules-ts.cppm:1 {{'{{.*}}modules-ts.cppm' included multiple times, additional include site in header from module 'foo'}} +#endif int n; #if TEST >= 2 // expected-error@-2 {{redefinition of '}} From aae294bfd9bd98fd91c7a9eb00e09b5198046d87 Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Wed, 5 Jul 2017 04:58:24 +0000 Subject: [PATCH 206/214] [AMDGPU] Fix size and alignment of size_t and pointer types Differential Revision: https://reviews.llvm.org/D34995 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307121 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 20 ++++-- test/CodeGen/default-address-space.c | 2 +- test/CodeGenCXX/amdgcn-automatic-variable.cpp | 10 +-- .../amdgcn-automatic-variable.cl | 8 +-- test/CodeGenOpenCL/amdgpu-nullptr.cl | 48 ++++++------- test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl | 70 +++++++++++++++++++ test/Index/pipe-size.cl | 2 +- test/SemaCXX/amdgpu-sizeof-alignof.cpp | 47 +++++++++++++ 8 files changed, 167 insertions(+), 40 deletions(-) create mode 100644 test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl create mode 100644 test/SemaCXX/amdgpu-sizeof-alignof.cpp diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 4ff61eb52205..28e6d834ccf0 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -2189,6 +2189,15 @@ class AMDGPUTargetInfo final : public TargetInfo { Triple.getEnvironmentName() == "amdgizcl" || !isAMDGCN(Triple)); UseAddrSpaceMapMangling = true; + + // Set pointer width and alignment for target address space 0. + PointerWidth = PointerAlign = DataLayout->getPointerSizeInBits(); + if (getMaxPointerWidth() == 64) { + LongWidth = LongAlign = 64; + SizeType = UnsignedLong; + PtrDiffType = SignedLong; + IntPtrType = SignedLong; + } } void setAddressSpaceMap(bool DefaultIsPrivate) { @@ -2216,6 +2225,10 @@ class AMDGPUTargetInfo final : public TargetInfo { return 64; } + uint64_t getPointerAlignV(unsigned AddrSpace) const override { + return getPointerWidthV(AddrSpace); + } + uint64_t getMaxPointerWidth() const override { return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32; } @@ -2392,12 +2405,7 @@ class AMDGPUTargetInfo final : public TargetInfo { } /// \returns Target specific vtbl ptr address space. - unsigned getVtblPtrAddressSpace() const override { - // \todo: We currently have address spaces defined in AMDGPU Backend. It - // would be nice if we could use it here instead of using bare numbers (same - // applies to getDWARFAddressSpace). - return 2; // constant. - } + unsigned getVtblPtrAddressSpace() const override { return AS.Constant; } /// \returns If a target requires an address within a target specific address /// space \p AddressSpace to be converted in order to be used, then return the diff --git a/test/CodeGen/default-address-space.c b/test/CodeGen/default-address-space.c index fc5f55ffd6f4..becbc4ac504c 100644 --- a/test/CodeGen/default-address-space.c +++ b/test/CodeGen/default-address-space.c @@ -50,7 +50,7 @@ void test3() { // PIZ: %[[arrayidx:.*]] = getelementptr inbounds i32, i32 addrspace(4)* %[[r0]] // PIZ: store i32 0, i32 addrspace(4)* %[[arrayidx]] // CHECK-LABEL: define void @test4(i32* %a) -// CHECK: %[[alloca:.*]] = alloca i32*, align 4, addrspace(5) +// CHECK: %[[alloca:.*]] = alloca i32*, align 8, addrspace(5) // CHECK: %[[a_addr:.*]] = addrspacecast{{.*}} %[[alloca]] to i32** // CHECK: store i32* %a, i32** %[[a_addr]] // CHECK: %[[r0:.*]] = load i32*, i32** %[[a_addr]] diff --git a/test/CodeGenCXX/amdgcn-automatic-variable.cpp b/test/CodeGenCXX/amdgcn-automatic-variable.cpp index 7df27c28e6d2..a82275206c6d 100644 --- a/test/CodeGenCXX/amdgcn-automatic-variable.cpp +++ b/test/CodeGenCXX/amdgcn-automatic-variable.cpp @@ -15,8 +15,8 @@ void func2(void) { // CHECK: %lv1 = alloca i32, align 4, addrspace(5) // CHECK: %lv2 = alloca i32, align 4, addrspace(5) // CHECK: %la = alloca [100 x i32], align 4, addrspace(5) - // CHECK: %lp1 = alloca i32*, align 4, addrspace(5) - // CHECK: %lp2 = alloca i32*, align 4, addrspace(5) + // CHECK: %lp1 = alloca i32*, align 8, addrspace(5) + // CHECK: %lp2 = alloca i32*, align 8, addrspace(5) // CHECK: %lvc = alloca i32, align 4, addrspace(5) // CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32* @@ -34,12 +34,12 @@ void func2(void) { la[0] = 3; // CHECK: %[[r3:.*]] = addrspacecast i32* addrspace(5)* %lp1 to i32** - // CHECK: store i32* %[[r0]], i32** %[[r3]], align 4 + // CHECK: store i32* %[[r0]], i32** %[[r3]], align 8 int *lp1 = &lv1; // CHECK: %[[r4:.*]] = addrspacecast i32* addrspace(5)* %lp2 to i32** // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i32 0, i32 0 - // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 4 + // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 8 int *lp2 = la; // CHECK: call void @_Z5func1Pi(i32* %[[r0]]) @@ -80,3 +80,5 @@ void func4(int x) { // CHECK: call void @_Z5func1Pi(i32* %[[r0]]) func1(&x); } + +// CHECK-NOT: !opencl.ocl.version diff --git a/test/CodeGenOpenCL/amdgcn-automatic-variable.cl b/test/CodeGenOpenCL/amdgcn-automatic-variable.cl index 29309567ec71..19287c7d8998 100644 --- a/test/CodeGenOpenCL/amdgcn-automatic-variable.cl +++ b/test/CodeGenOpenCL/amdgcn-automatic-variable.cl @@ -22,8 +22,8 @@ void func2(void) { // CHECK: %la = alloca [100 x i32], align 4, addrspace(5) // CL12: %lp1 = alloca i32 addrspace(5)*, align 4, addrspace(5) // CL12: %lp2 = alloca i32 addrspace(5)*, align 4, addrspace(5) - // CL20: %lp1 = alloca i32*, align 4, addrspace(5) - // CL20: %lp2 = alloca i32*, align 4, addrspace(5) + // CL20: %lp1 = alloca i32*, align 8, addrspace(5) + // CL20: %lp2 = alloca i32*, align 8, addrspace(5) // CHECK: %lvc = alloca i32, align 4, addrspace(5) // CHECK: store i32 1, i32 addrspace(5)* %lv1 @@ -39,13 +39,13 @@ void func2(void) { // CL12: store i32 addrspace(5)* %lv1, i32 addrspace(5)* addrspace(5)* %lp1, align 4 // CL20: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32* - // CL20: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 4 + // CL20: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 8 int *lp1 = &lv1; // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32] addrspace(5)* %la, i32 0, i32 0 // CL12: store i32 addrspace(5)* %[[arraydecay]], i32 addrspace(5)* addrspace(5)* %lp2, align 4 // CL20: %[[r1:.*]] = addrspacecast i32 addrspace(5)* %[[arraydecay]] to i32* - // CL20: store i32* %[[r1]], i32* addrspace(5)* %lp2, align 4 + // CL20: store i32* %[[r1]], i32* addrspace(5)* %lp2, align 8 int *lp2 = la; // CL12: call void @func1(i32 addrspace(5)* %lv1) diff --git a/test/CodeGenOpenCL/amdgpu-nullptr.cl b/test/CodeGenOpenCL/amdgpu-nullptr.cl index 402be5760cf7..69f54fcaa483 100644 --- a/test/CodeGenOpenCL/amdgpu-nullptr.cl +++ b/test/CodeGenOpenCL/amdgpu-nullptr.cl @@ -27,13 +27,13 @@ private char *private_p = 0; // CHECK: @local_p = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4 local char *local_p = 0; -// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4 +// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8 global char *global_p = 0; -// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4 +// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8 constant char *constant_p = 0; -// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4 +// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8 generic char *generic_p = 0; // Test NULL as initializer. @@ -44,19 +44,19 @@ private char *private_p_NULL = NULL; // CHECK: @local_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4 local char *local_p_NULL = NULL; -// CHECK: @global_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4 +// CHECK: @global_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8 global char *global_p_NULL = NULL; -// CHECK: @constant_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4 +// CHECK: @constant_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8 constant char *constant_p_NULL = NULL; -// CHECK: @generic_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4 +// CHECK: @generic_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8 generic char *generic_p_NULL = NULL; // Test constant folding of null pointer. // A null pointer should be folded to a null pointer in the target address space. -// CHECK: @fold_generic = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 4 +// CHECK: @fold_generic = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 8 generic int *fold_generic = (global int*)(generic float*)(private char*)0; // CHECK: @fold_priv = local_unnamed_addr addrspace(1) global i16* null, align 4 @@ -104,8 +104,8 @@ int fold_int5_local = (int) &((local StructTy1*)0)->p2; // NOOPT: @test_static_var_private.sp3 = internal addrspace(1) global i8* null, align 4 // NOOPT: @test_static_var_private.sp4 = internal addrspace(1) global i8* null, align 4 // NOOPT: @test_static_var_private.sp5 = internal addrspace(1) global i8* null, align 4 -// NOOPT: @test_static_var_private.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4 -// NOOPT: @test_static_var_private.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 4 +// NOOPT: @test_static_var_private.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8 +// NOOPT: @test_static_var_private.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8 void test_static_var_private(void) { static private char *sp1 = 0; @@ -123,8 +123,8 @@ void test_static_var_private(void) { // NOOPT: @test_static_var_local.sp3 = internal addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4 // NOOPT: @test_static_var_local.sp4 = internal addrspace(1) global i8 addrspace(3)* null, align 4 // NOOPT: @test_static_var_local.sp5 = internal addrspace(1) global i8 addrspace(3)* null, align 4 -// NOOPT: @test_static_var_local.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4 -// NOOPT: @test_static_var_local.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 4 +// NOOPT: @test_static_var_local.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8 +// NOOPT: @test_static_var_local.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8 void test_static_var_local(void) { static local char *sp1 = 0; static local char *sp2 = NULL; @@ -143,9 +143,9 @@ void test_static_var_local(void) { // NOOPT: store i8* null, i8** %sp3, align 4 // NOOPT: store i8* null, i8** %sp4, align 4 // NOOPT: %[[SS1:.*]] = bitcast %struct.StructTy1* %SS1 to i8* -// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_private.SS1 to i8 addrspace(2)*), i64 32, i32 4, i1 false) +// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_private.SS1 to i8 addrspace(2)*), i64 32, i32 8, i1 false) // NOOPT: %[[SS2:.*]] = bitcast %struct.StructTy2* %SS2 to i8* -// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 4, i1 false) +// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 8, i1 false) void test_func_scope_var_private(void) { private char *sp1 = 0; private char *sp2 = NULL; @@ -163,9 +163,9 @@ void test_func_scope_var_private(void) { // NOOPT: store i8 addrspace(3)* null, i8 addrspace(3)** %sp3, align 4 // NOOPT: store i8 addrspace(3)* null, i8 addrspace(3)** %sp4, align 4 // NOOPT: %[[SS1:.*]] = bitcast %struct.StructTy1* %SS1 to i8* -// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_local.SS1 to i8 addrspace(2)*), i64 32, i32 4, i1 false) +// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_local.SS1 to i8 addrspace(2)*), i64 32, i32 8, i1 false) // NOOPT: %[[SS2:.*]] = bitcast %struct.StructTy2* %SS2 to i8* -// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 4, i1 false) +// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 8, i1 false) void test_func_scope_var_local(void) { local char *sp1 = 0; local char *sp2 = NULL; @@ -189,28 +189,28 @@ private char *p1; // CHECK: @p2 = weak local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4 local char *p2; -// CHECK: @p3 = common local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4 +// CHECK: @p3 = common local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8 constant char *p3; -// CHECK: @p4 = common local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4 +// CHECK: @p4 = common local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8 global char *p4; -// CHECK: @p5 = common local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4 +// CHECK: @p5 = common local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8 generic char *p5; // Test default initialization of sturcture. -// CHECK: @S1 = weak local_unnamed_addr addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4 +// CHECK: @S1 = weak local_unnamed_addr addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8 StructTy1 S1; -// CHECK: @S2 = common local_unnamed_addr addrspace(1) global %struct.StructTy2 zeroinitializer, align 4 +// CHECK: @S2 = common local_unnamed_addr addrspace(1) global %struct.StructTy2 zeroinitializer, align 8 StructTy2 S2; // Test default initialization of array. -// CHECK: @A1 = weak local_unnamed_addr addrspace(1) global [2 x %struct.StructTy1] [%struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }], align 4 +// CHECK: @A1 = weak local_unnamed_addr addrspace(1) global [2 x %struct.StructTy1] [%struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }], align 8 StructTy1 A1[2]; -// CHECK: @A2 = common local_unnamed_addr addrspace(1) global [2 x %struct.StructTy2] zeroinitializer, align 4 +// CHECK: @A2 = common local_unnamed_addr addrspace(1) global [2 x %struct.StructTy2] zeroinitializer, align 8 StructTy2 A2[2]; // Test comparison with 0. @@ -597,7 +597,7 @@ int test_and_ptr(private char* p1, local char* p2) { // Test folding of null pointer in function scope. // NOOPT-LABEL: test_fold_private // NOOPT: call void @test_fold_callee -// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 4 +// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 8 // NOOPT: %{{.*}} = sub i64 %{{.*}}, 0 // NOOPT: call void @test_fold_callee // NOOPT: %{{.*}} = add nsw i64 %{{.*}}, 0 @@ -612,7 +612,7 @@ void test_fold_private(void) { // NOOPT-LABEL: test_fold_local // NOOPT: call void @test_fold_callee -// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 4 +// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 8 // NOOPT: %{{.*}} = sub i64 %{{.*}}, 0 // NOOPT: call void @test_fold_callee // NOOPT: %{{.*}} = add nsw i64 %{{.*}}, sext (i32 ptrtoint (i32 addrspace(3)* addrspacecast (i32 addrspace(4)* null to i32 addrspace(3)*) to i32) to i64) diff --git a/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl b/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl new file mode 100644 index 000000000000..a5d438933fa4 --- /dev/null +++ b/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl @@ -0,0 +1,70 @@ +// RUN: %clang_cc1 -triple r600 -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s + +#ifdef __AMDGCN__ +#define PTSIZE 8 +#else +#define PTSIZE 4 +#endif + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable +#endif + +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __INTPTR_TYPE__ intptr_t; +typedef __UINTPTR_TYPE__ uintptr_t; +typedef global void *global_ptr_t; +typedef constant void *constant_ptr_t; +typedef local void *local_ptr_t; +typedef private void *private_ptr_t; + +void check(bool); + +void test() { + // CHECK-NOT: call void @check(i1 zeroext false) + check(sizeof(size_t) == PTSIZE); + check(__alignof__(size_t) == PTSIZE); + check(sizeof(intptr_t) == PTSIZE); + check(__alignof__(intptr_t) == PTSIZE); + check(sizeof(uintptr_t) == PTSIZE); + check(__alignof__(uintptr_t) == PTSIZE); + check(sizeof(ptrdiff_t) == PTSIZE); + check(__alignof__(ptrdiff_t) == PTSIZE); + + check(sizeof(char) == 1); + check(__alignof__(char) == 1); + check(sizeof(short) == 2); + check(__alignof__(short) == 2); + check(sizeof(int) == 4); + check(__alignof__(int) == 4); + check(sizeof(long) == 8); + check(__alignof__(long) == 8); +#ifdef cl_khr_fp16 + check(sizeof(half) == 2); + check(__alignof__(half) == 2); +#endif + check(sizeof(float) == 4); + check(__alignof__(float) == 4); +#ifdef cl_khr_fp64 + check(sizeof(double) == 8); + check(__alignof__(double) == 8); +#endif + + check(sizeof(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4)); + check(__alignof__(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4)); + check(sizeof(global_ptr_t) == PTSIZE); + check(__alignof__(global_ptr_t) == PTSIZE); + check(sizeof(constant_ptr_t) == PTSIZE); + check(__alignof__(constant_ptr_t) == PTSIZE); + check(sizeof(local_ptr_t) == 4); + check(__alignof__(private_ptr_t) == 4); +} diff --git a/test/Index/pipe-size.cl b/test/Index/pipe-size.cl index d07d7067da8c..cfe97935ee63 100644 --- a/test/Index/pipe-size.cl +++ b/test/Index/pipe-size.cl @@ -11,6 +11,6 @@ __kernel void testPipe( pipe int test ) // SPIR: store i32 4, i32* %s, align 4 // SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8 // SPIR64: store i32 8, i32* %s, align 4 - // AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 4 + // AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8 // AMD: store i32 8, i32 addrspace(5)* %s, align 4 } diff --git a/test/SemaCXX/amdgpu-sizeof-alignof.cpp b/test/SemaCXX/amdgpu-sizeof-alignof.cpp new file mode 100644 index 000000000000..97da71a1a3e2 --- /dev/null +++ b/test/SemaCXX/amdgpu-sizeof-alignof.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -triple amdgcn---amdgiz -std=c++11 -fsyntax-only -verify %s +// expected-no-diagnostics +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __INTPTR_TYPE__ intptr_t; +typedef __UINTPTR_TYPE__ uintptr_t; +typedef __attribute__((address_space(1))) void *global_ptr_t; +typedef __attribute__((address_space(2))) void *constant_ptr_t; +typedef __attribute__((address_space(3))) void *local_ptr_t; +typedef __attribute__((address_space(5))) void *private_ptr_t; + +void test() { + static_assert(sizeof(size_t) == 8, "bad size"); + static_assert(alignof(size_t) == 8, "bad alignment"); + static_assert(sizeof(intptr_t) == 8, "bad size"); + static_assert(alignof(intptr_t) == 8, "bad alignment"); + static_assert(sizeof(uintptr_t) == 8, "bad size"); + static_assert(alignof(uintptr_t) == 8, "bad alignment"); + static_assert(sizeof(ptrdiff_t) == 8, "bad size"); + static_assert(alignof(ptrdiff_t) == 8, "bad alignment"); + + static_assert(sizeof(char) == 1, "bad size"); + static_assert(alignof(char) == 1, "bad alignment"); + static_assert(sizeof(short) == 2, "bad size"); + static_assert(alignof(short) == 2, "bad alignment"); + static_assert(sizeof(int) == 4, "bad size"); + static_assert(alignof(int) == 4, "bad alignment"); + static_assert(sizeof(long) == 8, "bad size"); + static_assert(alignof(long) == 8, "bad alignment"); + static_assert(sizeof(long long) == 8, "bad size"); + static_assert(alignof(long long) == 8, "bad alignment"); + static_assert(sizeof(float) == 4, "bad size"); + static_assert(alignof(float) == 4, "bad alignment"); + static_assert(sizeof(double) == 8, "bad size"); + static_assert(alignof(double) == 8, "bad alignment"); + + static_assert(sizeof(void*) == 8, "bad size"); + static_assert(alignof(void*) == 8, "bad alignment"); + static_assert(sizeof(global_ptr_t) == 8, "bad size"); + static_assert(alignof(global_ptr_t) == 8, "bad alignment"); + static_assert(sizeof(constant_ptr_t) == 8, "bad size"); + static_assert(alignof(constant_ptr_t) == 8, "bad alignment"); + static_assert(sizeof(local_ptr_t) == 4, "bad size"); + static_assert(alignof(local_ptr_t) == 4, "bad alignment"); + static_assert(sizeof(private_ptr_t) == 4, "bad size"); + static_assert(alignof(private_ptr_t) == 4, "bad alignment"); +} From 50f735245d0803846df474e9f3229ac7f4d9f9b0 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Wed, 5 Jul 2017 05:37:45 +0000 Subject: [PATCH 207/214] fix trivial typos in comments; NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307123 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 4 ++-- lib/Sema/SemaLambda.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index e836135cf2f9..548a1e24f830 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -9508,7 +9508,7 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { case BO_Mul: if (Result.isComplexFloat()) { // This is an implementation of complex multiplication according to the - // constraints laid out in C11 Annex G. The implemantion uses the + // constraints laid out in C11 Annex G. The implemention uses the // following naming scheme: // (a + ib) * (c + id) ComplexValue LHS = Result; @@ -9589,7 +9589,7 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { case BO_Div: if (Result.isComplexFloat()) { // This is an implementation of complex division according to the - // constraints laid out in C11 Annex G. The implemantion uses the + // constraints laid out in C11 Annex G. The implemention uses the // following naming scheme: // (a + ib) / (c + id) ComplexValue LHS = Result; diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index d6b70610d461..46f2ba376006 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -1595,7 +1595,7 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, ContainsUnexpandedParameterPack); // If the lambda expression's call operator is not explicitly marked constexpr // and we are not in a dependent context, analyze the call operator to infer - // its constexpr-ness, supressing diagnostics while doing so. + // its constexpr-ness, suppressing diagnostics while doing so. if (getLangOpts().CPlusPlus1z && !CallOperator->isInvalidDecl() && !CallOperator->isConstexpr() && !isa(CallOperator->getBody()) && From c5dd58546ce4d20cd71cc26cb790e7f91c8f908f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 5 Jul 2017 07:47:11 +0000 Subject: [PATCH 208/214] [modules ts] Improve merging of module-private declarations. These cases occur frequently for declarations in the global module (above the module-declaration) in a Modules TS module interface. When we merge a definition from another module into such a module-private definition, ensure that we transitively make everything lexically within that definition visible to that translation unit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307129 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclBase.h | 2 +- lib/AST/DeclBase.cpp | 6 +- lib/Sema/SemaLookup.cpp | 92 ++++++++++++------- lib/Serialization/ASTReaderDecl.cpp | 2 + lib/Serialization/ASTWriter.cpp | 2 +- test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp | 33 +++++++ 6 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 8658d886a982..041f0fd484d4 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -749,7 +749,7 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { /// Set that this declaration is globally visible, even if it came from a /// module that is not visible. void setVisibleDespiteOwningModule() { - if (getModuleOwnershipKind() == ModuleOwnershipKind::VisibleWhenImported) + if (isHidden()) setModuleOwnershipKind(ModuleOwnershipKind::Visible); } diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 842ae9b6cc8b..cd2c83a02f59 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -283,8 +283,10 @@ void Decl::setLexicalDeclContext(DeclContext *DC) { setLocalOwningModule(cast(DC)->getOwningModule()); } - assert((!hasOwningModule() || getOwningModule() || isModulePrivate()) && - "hidden declaration has no owning module"); + assert( + (getModuleOwnershipKind() != ModuleOwnershipKind::VisibleWhenImported || + getOwningModule()) && + "hidden declaration has no owning module"); } void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 63b3f6a1cb2b..85596ed52e9d 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1396,6 +1396,13 @@ bool Sema::hasVisibleMergedDefinition(NamedDecl *Def) { } bool Sema::hasMergedDefinitionInCurrentModule(NamedDecl *Def) { + // FIXME: When not in local visibility mode, we can't tell the difference + // between a declaration being visible because we merged a local copy of + // the same declaration into it, and it being visible because its owning + // module is visible. + if (Def->getModuleOwnershipKind() == Decl::ModuleOwnershipKind::Visible && + getLangOpts().ModulesLocalVisibility) + return true; for (Module *Merged : Context.getModulesWithMergedDefinition(Def)) if (Merged->getTopLevelModuleName() == getLangOpts().CurrentModule) return true; @@ -1509,25 +1516,33 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { // FIXME: Don't assume that "same translation unit" means the same thing // as "not from an AST file". assert(D->isModulePrivate() && "hidden decl has no module"); - return !D->isFromASTFile(); + if (!D->isFromASTFile() || SemaRef.hasMergedDefinitionInCurrentModule(D)) + return true; + } else { + // If the owning module is visible, and the decl is not module private, + // then the decl is visible too. (Module private is ignored within the same + // top-level module.) + if (D->isModulePrivate() + ? DeclModule->getTopLevelModuleName() == + SemaRef.getLangOpts().CurrentModule || + SemaRef.hasMergedDefinitionInCurrentModule(D) + : SemaRef.isModuleVisible(DeclModule) || + SemaRef.hasVisibleMergedDefinition(D)) + return true; } - // If the owning module is visible, and the decl is not module private, - // then the decl is visible too. (Module private is ignored within the same - // top-level module.) - if (D->isModulePrivate() - ? DeclModule->getTopLevelModuleName() == - SemaRef.getLangOpts().CurrentModule || - SemaRef.hasMergedDefinitionInCurrentModule(D) - : SemaRef.isModuleVisible(DeclModule) || - SemaRef.hasVisibleMergedDefinition(D)) - return true; + // Determine whether a decl context is a file context for the purpose of + // visibility. This looks through some (export and linkage spec) transparent + // contexts, but not others (enums). + auto IsEffectivelyFileContext = [](const DeclContext *DC) { + return DC->isFileContext() || isa(DC) || + isa(DC); + }; - // If this declaration is not at namespace scope nor module-private, + // If this declaration is not at namespace scope // then it is visible if its lexical parent has a visible definition. DeclContext *DC = D->getLexicalDeclContext(); - if (!D->isModulePrivate() && DC && !DC->isFileContext() && - !isa(DC) && !isa(DC)) { + if (DC && !IsEffectivelyFileContext(DC)) { // For a parameter, check whether our current template declaration's // lexical context is visible, not whether there's some other visible // definition of it, because parameters aren't "within" the definition. @@ -1535,32 +1550,45 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { // In C++ we need to check for a visible definition due to ODR merging, // and in C we must not because each declaration of a function gets its own // set of declarations for tags in prototype scope. - if ((D->isTemplateParameter() || isa(D) - || (isa(DC) && !SemaRef.getLangOpts().CPlusPlus)) - ? isVisible(SemaRef, cast(DC)) - : SemaRef.hasVisibleDefinition(cast(DC))) { - if (SemaRef.CodeSynthesisContexts.empty() && - // FIXME: Do something better in this case. - !SemaRef.getLangOpts().ModulesLocalVisibility) { - // Cache the fact that this declaration is implicitly visible because - // its parent has a visible definition. - D->setVisibleDespiteOwningModule(); - } - return true; + bool VisibleWithinParent; + if (D->isTemplateParameter() || isa(D) || + (isa(DC) && !SemaRef.getLangOpts().CPlusPlus)) + VisibleWithinParent = isVisible(SemaRef, cast(DC)); + else if (D->isModulePrivate()) { + // A module-private declaration is only visible if an enclosing lexical + // parent was merged with another definition in the current module. + VisibleWithinParent = false; + do { + if (SemaRef.hasMergedDefinitionInCurrentModule(cast(DC))) { + VisibleWithinParent = true; + break; + } + DC = DC->getLexicalParent(); + } while (!IsEffectivelyFileContext(DC)); + } else { + VisibleWithinParent = SemaRef.hasVisibleDefinition(cast(DC)); } - return false; + + if (VisibleWithinParent && SemaRef.CodeSynthesisContexts.empty() && + // FIXME: Do something better in this case. + !SemaRef.getLangOpts().ModulesLocalVisibility) { + // Cache the fact that this declaration is implicitly visible because + // its parent has a visible definition. + D->setVisibleDespiteOwningModule(); + } + return VisibleWithinParent; } + // FIXME: All uses of DeclModule below this point should also check merged + // modules. + if (!DeclModule) + return false; + // Find the extra places where we need to look. llvm::DenseSet &LookupModules = SemaRef.getLookupModules(); if (LookupModules.empty()) return false; - if (!DeclModule) { - DeclModule = SemaRef.getOwningModule(D); - assert(DeclModule && "hidden decl not from a module"); - } - // If our lookup set contains the decl's module, it's visible. if (LookupModules.count(DeclModule)) return true; diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 4d9ddd2ff506..abed2586561a 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -573,6 +573,8 @@ void ASTDeclReader::VisitDecl(Decl *D) { else Reader.HiddenNamesMap[Owner].push_back(D); } + } else if (ModulePrivate) { + D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); } } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index c6129d326cb6..f7a49e41009d 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1462,7 +1462,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, } // Module map file - if (WritingModule) { + if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) { Record.clear(); auto &Map = PP.getHeaderSearchInfo().getModuleMap(); diff --git a/test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp b/test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp new file mode 100644 index 000000000000..734b89173df9 --- /dev/null +++ b/test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp @@ -0,0 +1,33 @@ +// RUN: rm -f %t +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t -DINTERFACE +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -fmodule-file=%t %s -verify -DIMPLEMENTATION +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -fmodule-file=%t %s -verify -DEARLY_IMPLEMENTATION +// RUN: %clang_cc1 -std=c++1z -fmodules-ts -fmodule-file=%t %s -verify -DUSER + +// expected-no-diagnostics + +#ifdef USER +import Foo; +#endif + +#ifdef EARLY_IMPLEMENTATION +module Foo; +#endif + +template struct type_template { + typedef T type; + void f(type); +}; + +template void type_template::f(type) {} + +template class = type_template> +struct default_template_args {}; + +#ifdef INTERFACE +export module Foo; +#endif + +#ifdef IMPLEMENTATION +module Foo; +#endif From 0fc70de55d536d0366cb6ee19fbfd23c7d3578a4 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Wed, 5 Jul 2017 09:44:07 +0000 Subject: [PATCH 209/214] Fix invalid warnings for header guards in preambles Fixes https://bugs.llvm.org/show_bug.cgi?id=33574 Differential Revision: https://reviews.llvm.org/D34882 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307134 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Preprocessor.h | 9 ++++----- lib/Lex/Lexer.cpp | 2 +- lib/Lex/PPLexerChange.cpp | 6 ------ lib/Lex/Preprocessor.cpp | 2 ++ lib/Parse/Parser.cpp | 2 ++ 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 712e1ab9fbf5..62090d6496ed 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1048,6 +1048,10 @@ class Preprocessor { /// which implicitly adds the builtin defines etc. void EnterMainSourceFile(); + /// \brief After parser warm-up, initialize the conditional stack from + /// the preamble. + void replayPreambleConditionalStack(); + /// \brief Inform the preprocessor callbacks that processing is complete. void EndSourceFile(); @@ -1733,11 +1737,6 @@ class Preprocessor { /// \brief Return true if we're in the top-level file, not in a \#include. bool isInPrimaryFile() const; - /// \brief Return true if we're in the main file (specifically, if we are 0 - /// (zero) levels deep \#include. This is used by the lexer to determine if - /// it needs to generate errors about unterminated \#if directives. - bool isInMainFile() const; - /// \brief Handle cases where the \#include name is expanded /// from a macro as multiple tokens, which need to be glued together. /// diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 012189aa6f9f..61bcef8cb760 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -2550,7 +2550,7 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) { return true; } - if (PP->isRecordingPreamble() && !PP->isInMainFile()) { + if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) { PP->setRecordedPreambleConditionalStack(ConditionalStack); ConditionalStack.clear(); } diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 1c0cd5636835..5a589d6a17b3 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -46,12 +46,6 @@ bool Preprocessor::isInPrimaryFile() const { }); } -bool Preprocessor::isInMainFile() const { - if (IsFileLexer()) - return IncludeMacroStack.size() == 0; - return true; -} - /// getCurrentLexer - Return the current file lexer being lexed from. Note /// that this ignores any potentially active macro expansions and _Pragma /// expansions going on at the time. diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index f9a399cd7fd7..63f39524d12a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -535,7 +535,9 @@ void Preprocessor::EnterMainSourceFile() { // Start parsing the predefines. EnterSourceFile(FID, nullptr, SourceLocation()); +} +void Preprocessor::replayPreambleConditionalStack() { // Restore the conditional stack from the preamble, if there is one. if (PreambleConditionalStack.isReplaying()) { CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack()); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 1ed7ef966358..4aa9a5971929 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -516,6 +516,8 @@ void Parser::Initialize() { // Prime the lexer look-ahead. ConsumeToken(); + + PP.replayPreambleConditionalStack(); } void Parser::LateTemplateParserCleanupCallback(void *P) { From d424218cf7ef6d233819a6d9759f8ae0aa750b58 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 5 Jul 2017 11:45:09 +0000 Subject: [PATCH 210/214] Add const to reference arguments of Diagnostic ctor git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307143 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Tooling/Core/Diagnostic.h | 6 +++--- lib/Tooling/Core/Diagnostic.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/clang/Tooling/Core/Diagnostic.h b/include/clang/Tooling/Core/Diagnostic.h index d657f16df183..b4920d4fe456 100644 --- a/include/clang/Tooling/Core/Diagnostic.h +++ b/include/clang/Tooling/Core/Diagnostic.h @@ -58,9 +58,9 @@ struct Diagnostic { Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel, StringRef BuildDirectory); - Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message, - llvm::StringMap &Fix, - SmallVector &Notes, Level DiagLevel, + Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message, + const llvm::StringMap &Fix, + const SmallVector &Notes, Level DiagLevel, llvm::StringRef BuildDirectory); /// \brief Name identifying the Diagnostic. diff --git a/lib/Tooling/Core/Diagnostic.cpp b/lib/Tooling/Core/Diagnostic.cpp index 3bbc2b901e38..9e4833f2eff4 100644 --- a/lib/Tooling/Core/Diagnostic.cpp +++ b/lib/Tooling/Core/Diagnostic.cpp @@ -35,9 +35,9 @@ Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, BuildDirectory(BuildDirectory) {} Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, - DiagnosticMessage &Message, - llvm::StringMap &Fix, - SmallVector &Notes, + const DiagnosticMessage &Message, + const llvm::StringMap &Fix, + const SmallVector &Notes, Level DiagLevel, llvm::StringRef BuildDirectory) : DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes), DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {} From 7b5f13bce7dd43d501c8344013bfbdd4906b123b Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Wed, 5 Jul 2017 12:24:01 +0000 Subject: [PATCH 211/214] [clang-format] Fix an uninitialized memory access git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307147 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 4ea81baf59d6..00a0abd64bd4 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -646,13 +646,6 @@ struct AdditionalKeywords { kw_var = &IdentTable.get("var"); kw_yield = &IdentTable.get("yield"); - JsExtraKeywords = std::unordered_set( - {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from, - kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set, - kw_type, kw_var, kw_yield, - // Keywords from the Java section. - kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface}); - kw_abstract = &IdentTable.get("abstract"); kw_assert = &IdentTable.get("assert"); kw_extends = &IdentTable.get("extends"); @@ -680,6 +673,15 @@ struct AdditionalKeywords { kw_qsignals = &IdentTable.get("Q_SIGNALS"); kw_slots = &IdentTable.get("slots"); kw_qslots = &IdentTable.get("Q_SLOTS"); + + // Keep this at the end of the constructor to make sure everything here is + // already initialized. + JsExtraKeywords = std::unordered_set( + {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from, + kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set, + kw_type, kw_var, kw_yield, + // Keywords from the Java section. + kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface}); } // Context sensitive keywords. From 3bc8b20692bc76deb504155e1e52b9a09e7188f9 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 5 Jul 2017 12:57:32 +0000 Subject: [PATCH 212/214] [driver][mips] Remove redundant curly brackets. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307151 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Arch/Mips.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Driver/ToolChains/Arch/Mips.cpp b/lib/Driver/ToolChains/Arch/Mips.cpp index 33eff32b9731..d60ecfc2708e 100644 --- a/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/lib/Driver/ToolChains/Arch/Mips.cpp @@ -227,12 +227,11 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, O.matches(options::OPT_fno_PIE) || O.matches(options::OPT_fno_pie)); } - if (IsN64 && NonPIC) { + if (IsN64 && NonPIC) Features.push_back("+noabicalls"); - } else { + else AddTargetFeature(Args, Features, options::OPT_mno_abicalls, options::OPT_mabicalls, "noabicalls"); - } mips::FloatABI FloatABI = mips::getMipsFloatABI(D, Args); if (FloatABI == mips::FloatABI::Soft) { From 4d43c48558a063c449eeb550dc420aed6bf3c13e Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 5 Jul 2017 12:57:37 +0000 Subject: [PATCH 213/214] [driver][mips] Use AddTargetFeature to check arguments and add feature flags. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307152 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Arch/Mips.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Driver/ToolChains/Arch/Mips.cpp b/lib/Driver/ToolChains/Arch/Mips.cpp index d60ecfc2708e..66fa05c595f4 100644 --- a/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/lib/Driver/ToolChains/Arch/Mips.cpp @@ -297,13 +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"); - - if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) { - if (A->getOption().matches(options::OPT_mmadd4)) - Features.push_back("-nomadd4"); - else - Features.push_back("+nomadd4"); - } + AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4, + "nomadd4"); } mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) { From ef0d9ebb56107e5d236dda0b8b37c32c6e216a39 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Wed, 5 Jul 2017 13:19:47 +0000 Subject: [PATCH 214/214] [SystemZ] Simplify handling of ISA revisions This moves determination of the ISA revision from the CPU name to one single place, removing a bunch of duplicated code. It also makes the supported ISA revisions available as feature strings. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307156 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 48 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 28e6d834ccf0..41bf3100ea2a 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -7424,13 +7424,14 @@ class SystemZTargetInfo : public TargetInfo { static const Builtin::Info BuiltinInfo[]; static const char *const GCCRegNames[]; std::string CPU; + int ISARevision; bool HasTransactionalExecution; bool HasVector; public: SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &) - : TargetInfo(Triple), CPU("z10"), HasTransactionalExecution(false), - HasVector(false) { + : TargetInfo(Triple), CPU("z10"), ISARevision(8), + HasTransactionalExecution(false), HasVector(false) { IntMaxType = SignedLong; Int64Type = SignedLong; TLSSupported = true; @@ -7452,14 +7453,7 @@ class SystemZTargetInfo : public TargetInfo { Builder.defineMacro("__zarch__"); Builder.defineMacro("__LONG_DOUBLE_128__"); - const std::string ISARev = llvm::StringSwitch(CPU) - .Cases("arch8", "z10", "8") - .Cases("arch9", "z196", "9") - .Cases("arch10", "zEC12", "10") - .Cases("arch11", "z13", "11") - .Default(""); - if (!ISARev.empty()) - Builder.defineMacro("__ARCH__", ISARev); + Builder.defineMacro("__ARCH__", Twine(ISARevision)); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"); @@ -7492,37 +7486,35 @@ class SystemZTargetInfo : public TargetInfo { BuiltinVaListKind getBuiltinVaListKind() const override { return TargetInfo::SystemZBuiltinVaList; } + int getISARevision(const StringRef &Name) const { + return llvm::StringSwitch(Name) + .Cases("arch8", "z10", 8) + .Cases("arch9", "z196", 9) + .Cases("arch10", "zEC12", 10) + .Cases("arch11", "z13", 11) + .Default(-1); + } bool setCPU(const std::string &Name) override { CPU = Name; - bool CPUKnown = llvm::StringSwitch(Name) - .Case("z10", true) - .Case("arch8", true) - .Case("z196", true) - .Case("arch9", true) - .Case("zEC12", true) - .Case("arch10", true) - .Case("z13", true) - .Case("arch11", true) - .Default(false); - - return CPUKnown; + ISARevision = getISARevision(CPU); + return ISARevision != -1; } bool initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeaturesVec) const override { - if (CPU == "zEC12" || CPU == "arch10") - Features["transactional-execution"] = true; - if (CPU == "z13" || CPU == "arch11") { + int ISARevision = getISARevision(CPU); + if (ISARevision >= 10) Features["transactional-execution"] = true; + if (ISARevision >= 11) Features["vector"] = true; - } return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } bool handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) override { HasTransactionalExecution = false; + HasVector = false; for (const auto &Feature : Features) { if (Feature == "+transactional-execution") HasTransactionalExecution = true; @@ -7541,6 +7533,10 @@ class SystemZTargetInfo : public TargetInfo { bool hasFeature(StringRef Feature) const override { return llvm::StringSwitch(Feature) .Case("systemz", true) + .Case("arch8", ISARevision >= 8) + .Case("arch9", ISARevision >= 9) + .Case("arch10", ISARevision >= 10) + .Case("arch11", ISARevision >= 11) .Case("htm", HasTransactionalExecution) .Case("vx", HasVector) .Default(false);