From 14b6ba77710d6431794d65c7d58c6f29c3dc956e Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 9 Feb 2011 21:04:32 +0000 Subject: [PATCH] AST, Sema, Serialization: keep track of cudaConfigureCall git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125216 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 10 ++++++++++ include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ include/clang/Serialization/ASTBitCodes.h | 5 ++++- include/clang/Serialization/ASTReader.h | 6 ++++++ lib/AST/ASTContext.cpp | 1 + lib/Sema/SemaDecl.cpp | 13 +++++++++++++ lib/Serialization/ASTReader.cpp | 12 ++++++++++++ lib/Serialization/ASTWriter.cpp | 9 +++++++++ test/SemaCUDA/config-type.cu | 3 +++ 9 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/SemaCUDA/config-type.cu diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 8a05730154..911a50cf67 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -210,6 +210,9 @@ class ASTContext { /// \brief Type for the Block descriptor for Blocks CodeGen. mutable RecordDecl *BlockDescriptorExtendedType; + /// \brief Declaration for the CUDA cudaConfigureCall function. + FunctionDecl *cudaConfigureCallDecl; + TypeSourceInfo NullTypeSourceInfo; /// \brief Keeps track of all declaration attributes. @@ -541,6 +544,13 @@ public: return QualType(); } + void setcudaConfigureCallDecl(FunctionDecl *FD) { + cudaConfigureCallDecl = FD; + } + FunctionDecl *getcudaConfigureCallDecl() { + return cudaConfigureCallDecl; + } + /// This gets the struct used to keep track of pointer to blocks, complete /// with captured variables. QualType getBlockParmType(bool BlockHasCopyDispose, diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 05905c23f1..2cca767360 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3049,6 +3049,8 @@ def err_deleted_function_use : Error<"attempt to use a deleted function">; def err_kern_type_not_void_return : Error< "kernel function type %0 must have void return type">; +def err_config_scalar_return : Error< + "CUDA special function 'cudaConfigureCall' must have scalar return type">; def err_cannot_pass_objc_interface_to_vararg : Error< diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 5c9a3086cb..13e857511f 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -347,7 +347,10 @@ namespace clang { CXX_BASE_SPECIFIER_OFFSETS = 37, /// \brief Record code for #pragma diagnostic mappings. - DIAG_PRAGMA_MAPPINGS = 38 + DIAG_PRAGMA_MAPPINGS = 38, + + /// \brief Record code for special CUDA declarations. + CUDA_SPECIAL_DECL_REFS = 39 }; /// \brief Record types used within a source manager block. diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index ae9820b72f..6c6a271a3e 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -575,6 +575,12 @@ private: /// The AST context tracks a few important types, such as va_list, directly. llvm::SmallVector SpecialTypes; + /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. + /// + /// The AST context tracks a few important decls, currently cudaConfigureCall, + /// directly. + llvm::SmallVector CUDASpecialDeclRefs; + //@} /// \brief Diagnostic IDs and their mappings that the user changed. diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 30fe791e6d..d6c89c947c 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -197,6 +197,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, CFConstantStringTypeDecl(0), NSConstantStringTypeDecl(0), ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0), + cudaConfigureCallDecl(0), NullTypeSourceInfo(QualType()), SourceMgr(SM), LangOpts(LOpts), ABI(createCXXABI(t)), Target(t), Idents(idents), Selectors(sels), diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ac8e042545..d756de5e2d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4110,6 +4110,19 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } MarkUnusedFileScopedDecl(NewFD); + + if (getLangOptions().CUDA) + if (IdentifierInfo *II = NewFD->getIdentifier()) + if (!NewFD->isInvalidDecl() && + NewFD->getDeclContext()->getRedeclContext()->isTranslationUnit()) { + if (II->isStr("cudaConfigureCall")) { + if (!R->getAs()->getResultType()->isScalarType()) + Diag(NewFD->getLocation(), diag::err_config_scalar_return); + + Context.setcudaConfigureCallDecl(NewFD); + } + } + return NewFD; } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0fc62ab96a..559d927dac 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2152,6 +2152,11 @@ ASTReader::ReadASTBlock(PerFileData &F) { PragmaDiagMappings.insert(PragmaDiagMappings.end(), Record.begin(), Record.end()); break; + + case CUDA_SPECIAL_DECL_REFS: + // Later tables overwrite earlier ones. + CUDASpecialDeclRefs.swap(Record); + break; } First = false; } @@ -2496,6 +2501,13 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { Context->setInt128Installed(); ReadPragmaDiagnosticMappings(Context->getDiagnostics()); + + // If there were any CUDA special declarations, deserialize them. + if (!CUDASpecialDeclRefs.empty()) { + assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); + Context->setcudaConfigureCallDecl( + cast(GetDecl(CUDASpecialDeclRefs[0]))); + } } /// \brief Retrieve the name of the original source file name diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index fdd5800e9c..a5af03cfb0 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2545,6 +2545,11 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); } + RecordData CUDASpecialDeclRefs; + if (Context.getcudaConfigureCallDecl()) { + AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); + } + // Write the remaining AST contents. RecordData Record; Stream.EnterSubblock(AST_BLOCK_ID, 5); @@ -2659,6 +2664,10 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, if (!SemaDeclRefs.empty()) Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); + // Write the record containing CUDA-specific declaration references. + if (!CUDASpecialDeclRefs.empty()) + Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); + // Some simple statistics Record.clear(); Record.push_back(NumStatements); diff --git a/test/SemaCUDA/config-type.cu b/test/SemaCUDA/config-type.cu new file mode 100644 index 0000000000..a469d38d3e --- /dev/null +++ b/test/SemaCUDA/config-type.cu @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void cudaConfigureCall(unsigned gridSize, unsigned blockSize); // expected-error {{must have scalar return type}} -- 2.40.0