Index: clang/include/clang/Interpreter/Interpreter.h =================================================================== --- clang/include/clang/Interpreter/Interpreter.h +++ clang/include/clang/Interpreter/Interpreter.h @@ -36,6 +36,8 @@ namespace clang { class CompilerInstance; + +namespace caas { class IncrementalExecutor; class IncrementalParser; @@ -104,6 +106,7 @@ llvm::Expected getExecutionEngine(); llvm::Expected Parse(llvm::StringRef Code); + llvm::Error ExecuteModule(std::unique_ptr &M); llvm::Error Execute(PartialTranslationUnit &T); llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr); llvm::Expected CompileDtorCall(CXXRecordDecl *CXXRD); @@ -136,6 +139,8 @@ Expr *SynthesizeExpr(Expr *E); + std::unique_ptr GenModule(); + private: size_t getEffectivePTUSize() const; @@ -145,6 +150,7 @@ llvm::SmallVector ValuePrintingInfo; }; +} // namespace caas } // namespace clang #endif // LLVM_CLANG_INTERPRETER_INTERPRETER_H Index: clang/include/clang/Interpreter/PartialTranslationUnit.h =================================================================== --- clang/include/clang/Interpreter/PartialTranslationUnit.h +++ clang/include/clang/Interpreter/PartialTranslationUnit.h @@ -24,6 +24,7 @@ class TranslationUnitDecl; +namespace caas { /// The class keeps track of various objects created as part of processing /// incremental inputs. struct PartialTranslationUnit { @@ -32,6 +33,7 @@ /// The llvm IR produced for the input. std::unique_ptr TheModule; }; +} // namespace caas } // namespace clang #endif // LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H Index: clang/include/clang/Interpreter/Value.h =================================================================== --- clang/include/clang/Interpreter/Value.h +++ clang/include/clang/Interpreter/Value.h @@ -49,9 +49,11 @@ namespace clang { class ASTContext; -class Interpreter; class QualType; +namespace caas { +class Interpreter; + #if defined(_WIN32) // REPL_EXTERNAL_VISIBILITY are symbols that we need to be able to locate // at runtime. On Windows, this requires them to be exported from any of the @@ -137,6 +139,7 @@ void setOpaqueType(void *Ty) { OpaqueType = Ty; } void *getPtr() const; + void **getPtrAddress() const; void setPtr(void *Ptr) { Data.m_Ptr = Ptr; } #define X(type, name) \ @@ -203,6 +206,6 @@ return Data.m_Ptr; return (void *)as(); } - +} // namespace caas } // namespace clang #endif Index: clang/lib/Headers/CMakeLists.txt =================================================================== --- clang/lib/Headers/CMakeLists.txt +++ clang/lib/Headers/CMakeLists.txt @@ -19,6 +19,7 @@ tgmath.h unwind.h varargs.h + __clang_interpreter_runtime_printvalue.h ) set(arm_common_files Index: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h =================================================================== --- /dev/null +++ clang/lib/Headers/__clang_interpreter_runtime_printvalue.h @@ -0,0 +1,261 @@ +//===--- __clang_interpreter_runtime_printvalue.h ---*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines runtime functions used to print STL components in +// clang-repl. They are very heavy so we should only include it once and on +// demand. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_INTERPRETER_RUNTIME_PRINT_VALUE_H +#define LLVM_CLANG_INTERPRETER_RUNTIME_PRINT_VALUE_H + +#if !defined(__CLANG_REPL__) +#error "This file should only be included by clang-repl!" +#endif + +#include +#include +#include +#include +#include + +// FIXME: We should include it somewhere instead of duplicating it... +#if __has_attribute(visibility) && \ + (!(defined(_WIN32) || defined(__CYGWIN__)) || \ + (defined(__MINGW32__) && defined(__clang__))) +#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) +#define __REPL_EXTERNAL_VISIBILITY __attribute__((visibility("default"))) +#else +#define __REPL_EXTERNAL_VISIBILITY +#endif +#else +#if defined(_WIN32) +#define __REPL_EXTERNAL_VISIBILITY __declspec(dllexport) +#endif +#endif + +// Fallback. +template ::value>::type * = nullptr> +inline std::string PrintValueRuntime(const T &) { + return "{not representable}"; +} + +#ifndef __DECL_PRINT_VALUE_RUNTIME +#define __DECL_PRINT_VALUE_RUNTIME(type) \ + __REPL_EXTERNAL_VISIBILITY std::string PrintValueRuntime(const type *__Ptr) +__DECL_PRINT_VALUE_RUNTIME(void); +__DECL_PRINT_VALUE_RUNTIME(void *); +__DECL_PRINT_VALUE_RUNTIME(bool); +__DECL_PRINT_VALUE_RUNTIME(char); +__DECL_PRINT_VALUE_RUNTIME(signed char); +__DECL_PRINT_VALUE_RUNTIME(short); +__DECL_PRINT_VALUE_RUNTIME(unsigned short); +__DECL_PRINT_VALUE_RUNTIME(int); +__DECL_PRINT_VALUE_RUNTIME(unsigned int); +__DECL_PRINT_VALUE_RUNTIME(long); +__DECL_PRINT_VALUE_RUNTIME(long long); +__DECL_PRINT_VALUE_RUNTIME(unsigned long); +__DECL_PRINT_VALUE_RUNTIME(unsigned long long); +__DECL_PRINT_VALUE_RUNTIME(float); +__DECL_PRINT_VALUE_RUNTIME(double); +__DECL_PRINT_VALUE_RUNTIME(long double); +__DECL_PRINT_VALUE_RUNTIME(char *const); +__DECL_PRINT_VALUE_RUNTIME(char *); +#endif + +namespace __repl_runtime_detail { + +// Custom void_t implementation for C++11 compatibility +template struct __repl_void_impl { typedef void type; }; + +// Helper to deduce the type of the expression 'std::begin(std::declval())' +template +using __repl_begin_result = decltype(std::begin(std::declval())); + +// Helper to deduce the type of the expression 'std::end(std::declval())' +template +using __repl_end_result = decltype(std::end(std::declval())); + +// Type trait to check if a type is iterable +template +struct __is_iterable : std::false_type {}; + +template +struct __is_iterable, + __repl_end_result>::type> + : std::true_type {}; + +// Type trait to check if a type is std::pair +template struct __is_pair : std::false_type {}; + +template +struct __is_pair> : std::true_type {}; + +// Type trait to check if a type is std::map (or any associative container with +// mapped_type) +template struct __is_map : std::false_type {}; + +template +struct __is_map::type> + : std::true_type {}; + +// The type of the elements is std::pair, and the container is a map like type. +template < + typename Container, typename Elt, + typename std::enable_if<__is_pair::value && __is_map::value, + bool>::type = true> +std::string __PrintCollectionElt(const Elt &Val) { + return PrintValueRuntime(&Val.first) + " => " + + PrintValueRuntime(&Val.second); +} + +// The type of the elements is std::pair, and the container isn't a map-like +// type. +template ::value && + !__is_map::value, + bool>::type = true> +std::string __PrintCollectionElt(const Elt &Val) { + return TuplePairPrintValue(&Val); +} + +template ::value, bool>::type = true> +std::string __PrintCollectionElt(const Elt &Val) { + return PrintValueRuntime(&Val); +} + +template (), + std::size_t TupleSize = std::tuple_size()> +struct __TupleLikePrinter { + static std::string print(const Tuple *T) { + constexpr std::size_t EltNum = TupleSize - N; + std::string Str; + // Not the first element. + if (EltNum != 0) + Str += ", "; + Str += PrintValueRuntime(&std::get(*T)); + // If N+1 is not smaller than the size of the tuple, + // reroute the call to the printing function to the + // no-op specialisation to stop recursion. + constexpr std::size_t Nm1 = N - 1; + Str += __TupleLikePrinter::print((const Tuple *)T); + return Str; + } +}; + +template +struct __TupleLikePrinter { + static std::string print(const Tuple *T) { return ""; } +}; + +template inline std::string TuplePairPrintValue(const T *Val) { + std::string Str("{ "); + Str += __TupleLikePrinter::print(Val); + Str += " }"; + return Str; +} + +struct __StdVectorBool { + bool Value; + __StdVectorBool(bool V) : Value(V) {} +}; +template +std::string __PrintCollectionElt(const __StdVectorBool &Val) { + return PrintValueRuntime(&Val.Value); +} + +} // namespace __repl_runtime_detail + +template ::value, + bool>::type = true> +inline std::string PrintValueRuntime(const Container *C) { + std::string Str("{ "); + + for (auto Beg = C->begin(), End = C->end(); Beg != End; Beg++) { + if (Beg != C->begin()) + Str += ", "; + Str += __repl_runtime_detail::__PrintCollectionElt(*Beg); + } + Str += " }"; + return Str; +} + +template +inline std::string PrintValueRuntime(const T (*Obj)[N]) { + if (N == 0) + return "{}"; + + std::string Str = "{ "; + for (size_t Idx = 0; Idx < N; ++Idx) { + Str += PrintValueRuntime(*Obj + Idx); + if (Idx < N - 1) + Str += ", "; + } + return Str + " }"; +} + +template inline std::string PrintValueRuntime(const char (*Obj)[N]) { + const auto *Str = reinterpret_cast(Obj); + return PrintValueRuntime(&Str); +} + +// std::vector +inline std::string PrintValueRuntime(const std::vector *Val) { + // Try our best to fix std::vector without too much of templated code. + std::vector<__repl_runtime_detail::__StdVectorBool> ValFixed(Val->begin(), + Val->end()); + return PrintValueRuntime(&ValFixed); +} + +// tuple +template +inline std::string PrintValueRuntime(const std::tuple *Val) { + using T = std::tuple; + return __repl_runtime_detail::TuplePairPrintValue(Val); +} + +// pair +template +inline std::string PrintValueRuntime(const std::pair *Val) { + using T = std::pair; + return __repl_runtime_detail::TuplePairPrintValue(Val); +} + +// unique_ptr +template +inline std::string PrintValueRuntime(const std::unique_ptr *Val) { + auto Ptr = Val->get(); + return "std::unique_ptr -> " + PrintValueRuntime((const void **)&Ptr); +} + +// shared_ptr +template +inline std::string PrintValueRuntime(const std::shared_ptr *Val) { + auto Ptr = Val->get(); + return "std::shared_ptr -> " + PrintValueRuntime((const void **)&Ptr); +} + +// weak_ptr +template +inline std::string PrintValueRuntime(const std::weak_ptr *Val) { + auto Ptr = Val->lock().get(); + return "std::weak_ptr -> " + PrintValueRuntime((const void **)&Ptr); +} + +// string +template +inline std::string PrintValueRuntime(const std::basic_string *Val) { + const char *Chars = Val->c_str(); + return PrintValueRuntime((const char **)&Chars); +} +#endif Index: clang/lib/Interpreter/CMakeLists.txt =================================================================== --- clang/lib/Interpreter/CMakeLists.txt +++ clang/lib/Interpreter/CMakeLists.txt @@ -18,6 +18,7 @@ Interpreter.cpp InterpreterUtils.cpp Value.cpp + ValuePrinter.cpp DEPENDS intrinsics_gen Index: clang/lib/Interpreter/DeviceOffload.h =================================================================== --- clang/lib/Interpreter/DeviceOffload.h +++ clang/lib/Interpreter/DeviceOffload.h @@ -17,7 +17,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/VirtualFileSystem.h" -namespace clang { +namespace clang::caas { class IncrementalCUDADeviceParser : public IncrementalParser { public: @@ -46,6 +46,6 @@ llvm::IntrusiveRefCntPtr VFS; }; -} // namespace clang +} // namespace clang::caas #endif // LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H Index: clang/lib/Interpreter/DeviceOffload.cpp =================================================================== --- clang/lib/Interpreter/DeviceOffload.cpp +++ clang/lib/Interpreter/DeviceOffload.cpp @@ -20,7 +20,7 @@ #include "llvm/MC/TargetRegistry.h" #include "llvm/Target/TargetMachine.h" -namespace clang { +namespace clang::caas { IncrementalCUDADeviceParser::IncrementalCUDADeviceParser( Interpreter &Interp, std::unique_ptr Instance, @@ -173,4 +173,4 @@ IncrementalCUDADeviceParser::~IncrementalCUDADeviceParser() {} -} // namespace clang +} // namespace clang::caas Index: clang/lib/Interpreter/IncrementalExecutor.h =================================================================== --- clang/lib/Interpreter/IncrementalExecutor.h +++ clang/lib/Interpreter/IncrementalExecutor.h @@ -30,9 +30,11 @@ namespace clang { -struct PartialTranslationUnit; class TargetInfo; +namespace caas { +struct PartialTranslationUnit; + class IncrementalExecutor { using CtorDtorIterator = llvm::orc::CtorDtorIterator; std::unique_ptr Jit; @@ -48,6 +50,7 @@ const clang::TargetInfo &TI); ~IncrementalExecutor(); + llvm::Error addModule(std::unique_ptr &M); llvm::Error addModule(PartialTranslationUnit &PTU); llvm::Error removeModule(PartialTranslationUnit &PTU); llvm::Error runCtors() const; @@ -57,7 +60,7 @@ llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; } }; - +} // namespace caas } // end namespace clang #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALEXECUTOR_H Index: clang/lib/Interpreter/IncrementalExecutor.cpp =================================================================== --- clang/lib/Interpreter/IncrementalExecutor.cpp +++ clang/lib/Interpreter/IncrementalExecutor.cpp @@ -33,7 +33,7 @@ << (void *)&llvm_orc_registerJITLoaderGDBAllocAction; } -namespace clang { +namespace clang::caas { IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::Error &Err, @@ -59,6 +59,10 @@ IncrementalExecutor::~IncrementalExecutor() {} +llvm::Error IncrementalExecutor::addModule(std::unique_ptr &M) { + return Jit->addIRModule({std::move(M), TSCtx}); +} + llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit &PTU) { llvm::orc::ResourceTrackerSP RT = Jit->getMainJITDylib().createResourceTracker(); @@ -100,4 +104,4 @@ return Sym; } -} // end namespace clang +} // namespace clang::caas Index: clang/lib/Interpreter/IncrementalParser.h =================================================================== --- clang/lib/Interpreter/IncrementalParser.h +++ clang/lib/Interpreter/IncrementalParser.h @@ -30,9 +30,11 @@ class ASTConsumer; class CodeGenerator; class CompilerInstance; +class Parser; + +namespace caas { class IncrementalAction; class Interpreter; -class Parser; /// Provides support for incremental compilation. Keeps track of the state /// changes between the subsequent incremental input. /// @@ -86,6 +88,7 @@ private: llvm::Expected ParseOrWrapTopLevelDecl(); }; +} // namespace caas } // end namespace clang #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H Index: clang/lib/Interpreter/IncrementalParser.cpp =================================================================== --- clang/lib/Interpreter/IncrementalParser.cpp +++ clang/lib/Interpreter/IncrementalParser.cpp @@ -28,7 +28,7 @@ #include -namespace clang { +namespace clang::caas { class IncrementalASTConsumer final : public ASTConsumer { Interpreter &Interp; @@ -399,4 +399,4 @@ return CG->GetMangledName(GD); } -} // end namespace clang +} // namespace clang::caas Index: clang/lib/Interpreter/Interpreter.cpp =================================================================== --- clang/lib/Interpreter/Interpreter.cpp +++ clang/lib/Interpreter/Interpreter.cpp @@ -44,7 +44,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" using namespace clang; - +using namespace clang::caas; // FIXME: Figure out how to unify with namespace init_convenience from // tools/clang-import-test/clang-import-test.cpp namespace { @@ -250,7 +250,10 @@ // can't find the precise resource directory in unittests so we have to hard // code them. const char *const Runtimes = R"( - void* operator new(__SIZE_TYPE__, void* __p) noexcept; + inline void* + __attribute__ ((__visibility__("hidden"))) + __attribute__ ((internal_linkage)) + operator new(__SIZE_TYPE__, void *__p) noexcept; void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); @@ -267,6 +270,7 @@ void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); } + #define __CLANG_REPL__ 1 )"; llvm::Expected> @@ -371,6 +375,22 @@ return Err; } +llvm::Error Interpreter::ExecuteModule(std::unique_ptr &M) { + if (!IncrExecutor) { + auto Err = CreateExecutor(); + if (Err) + return Err; + } + // FIXME: Add a callback to retain the llvm::Module once the JIT is done. + if (auto Err = IncrExecutor->addModule(M)) + return Err; + + if (auto Err = IncrExecutor->runCtors()) + return Err; + + return llvm::Error::success(); +} + llvm::Error Interpreter::Execute(PartialTranslationUnit &T) { assert(T.TheModule); if (!IncrExecutor) { @@ -494,6 +514,10 @@ return AddrOrErr; } +std::unique_ptr Interpreter::GenModule() { + return IncrParser->GenModule(); +} + static constexpr llvm::StringRef MagicRuntimeInterface[] = { "__clang_Interpreter_SetValueNoAlloc", "__clang_Interpreter_SetValueWithAlloc", @@ -534,15 +558,15 @@ class RuntimeInterfaceBuilder : public TypeVisitor { - clang::Interpreter &Interp; + clang::caas::Interpreter &Interp; ASTContext &Ctx; Sema &S; Expr *E; llvm::SmallVector Args; public: - RuntimeInterfaceBuilder(clang::Interpreter &In, ASTContext &C, Sema &SemaRef, - Expr *VE, ArrayRef FixedArgs) + RuntimeInterfaceBuilder(clang::caas::Interpreter &In, ASTContext &C, + Sema &SemaRef, Expr *VE, ArrayRef FixedArgs) : Interp(In), Ctx(C), S(SemaRef), E(VE) { // The Interpreter* parameter and the out parameter `OutVal`. for (Expr *E : FixedArgs) Index: clang/lib/Interpreter/InterpreterUtils.h =================================================================== --- clang/lib/Interpreter/InterpreterUtils.h +++ clang/lib/Interpreter/InterpreterUtils.h @@ -33,7 +33,7 @@ #include "llvm/Support/Errc.h" #include "llvm/TargetParser/Host.h" -namespace clang { +namespace clang::caas { IntegerLiteral *IntegerLiteralExpr(ASTContext &C, uint64_t Val); Expr *CStyleCastPtrExpr(Sema &S, QualType Ty, Expr *E); @@ -48,7 +48,25 @@ NamedDecl *LookupNamed(Sema &S, llvm::StringRef Name, const DeclContext *Within); +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const NamespaceDecl *Namesp); + +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const TypedefNameDecl *TD, + bool FullyQualify); + +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const TagDecl *TD, + bool FullyQualify); + +QualType GetFullyQualifiedType(QualType QT, const ASTContext &Ctx); + std::string GetFullTypeName(ASTContext &Ctx, QualType QT); -} // namespace clang + +class Value; + +std::string ReplPrintTypeImpl(const Value &); +std::string ReplPrintDataImpl(const Value &); +} // namespace clang::caas #endif Index: clang/lib/Interpreter/InterpreterUtils.cpp =================================================================== --- clang/lib/Interpreter/InterpreterUtils.cpp +++ clang/lib/Interpreter/InterpreterUtils.cpp @@ -12,7 +12,7 @@ #include "InterpreterUtils.h" -namespace clang { +namespace clang::caas { IntegerLiteral *IntegerLiteralExpr(ASTContext &C, uint64_t Val) { return IntegerLiteral::Create(C, llvm::APSInt::getUnsigned(Val), @@ -81,7 +81,7 @@ else { const DeclContext *PrimaryWithin = nullptr; if (const auto *TD = dyn_cast(Within)) - PrimaryWithin = llvm::dyn_cast_or_null(TD->getDefinition()); + PrimaryWithin = dyn_cast_if_present(TD->getDefinition()); else PrimaryWithin = Within->getPrimaryContext(); @@ -97,15 +97,404 @@ R.resolveKind(); if (R.isSingleResult()) - return llvm::dyn_cast(R.getFoundDecl()); + return dyn_cast(R.getFoundDecl()); return nullptr; } +static NestedNameSpecifier *CreateOuterNNS(const ASTContext &Ctx, const Decl *D, + bool FullyQualify) { + const DeclContext *DC = D->getDeclContext(); + if (const auto *NS = dyn_cast(DC)) { + while (NS && NS->isInline()) { + // Ignore inline namespace; + NS = dyn_cast_if_present(NS->getDeclContext()); + } + if (NS && NS->getDeclName()) + return CreateNestedNameSpecifier(Ctx, NS); + return nullptr; // no starting '::', no anonymous + } + if (const auto *TD = dyn_cast(DC)) + return CreateNestedNameSpecifier(Ctx, TD, FullyQualify); + if (const auto *TDD = dyn_cast(DC)) + return CreateNestedNameSpecifier(Ctx, TDD, FullyQualify); + return nullptr; // no starting '::' +} + +static NestedNameSpecifier * +CreateNestedNameSpecifierForScopeOf(const ASTContext &Ctx, const Decl *D, + bool FullyQualified) { + // Create a nested name specifier for the declaring context of the type. + + assert(D); + + const auto *Outer = dyn_cast_if_present(D->getDeclContext()); + const auto *OuterNs = dyn_cast_if_present(D->getDeclContext()); + if (Outer && !(OuterNs && OuterNs->isAnonymousNamespace())) { + + if (const auto *CXXD = dyn_cast(D->getDeclContext())) { + + if (ClassTemplateDecl *CTD = CXXD->getDescribedClassTemplate()) { + // We are in the case of a type(def) that was declared in a + // class template but is *not* type dependent. In clang, it gets + // attached to the class template declaration rather than any + // specific class template instantiation. This result in 'odd' + // fully qualified typename: + // vector<_Tp,_Alloc>::size_type + // Make the situation is 'useable' but looking a bit odd by + // picking a random instance as the declaring context. + // FIXME: We should not use the iterators here to check if we are in + // a template specialization. clTempl != cxxdecl already tell us that + // is the case. It seems that we rely on a side-effect from triggering + // deserializations to support 'some' use-case. See ROOT-9709. + if (CTD->spec_begin() != CTD->spec_end()) { + D = *(CTD->spec_begin()); + Outer = dyn_cast(D); + OuterNs = dyn_cast(D); + } + } + } + + if (OuterNs) + return CreateNestedNameSpecifier(Ctx, OuterNs); + + if (const auto *TD = dyn_cast(Outer)) + return CreateNestedNameSpecifier(Ctx, TD, FullyQualified); + } + return nullptr; +} + +static NestedNameSpecifier * +CreateNestedNameSpecifierForScopeOf(const ASTContext &Ctx, const Type *TypePtr, + bool FullyQualified) { + // Create a nested name specifier for the declaring context of the type. + + if (!TypePtr) + return nullptr; + + Decl *D = nullptr; + if (const auto *TDT = dyn_cast(TypePtr)) { + D = TDT->getDecl(); + } else { + // There are probably other cases ... + if (const auto *TT = dyn_cast_if_present(TypePtr)) + D = TT->getDecl(); + else + D = TypePtr->getAsCXXRecordDecl(); + } + + if (!D) + return nullptr; + + return CreateNestedNameSpecifierForScopeOf(Ctx, D, FullyQualified); +} + +static NestedNameSpecifier * +GetFullyQualifiedNameSpecifier(const ASTContext &Ctx, + NestedNameSpecifier *Scope) { + // Return a fully qualified version of this name specifier + if (Scope->getKind() == NestedNameSpecifier::Global) { + // Already fully qualified. + return Scope; + } + + if (const Type *Type = Scope->getAsType()) { + // Find decl context. + const TagDecl *TD = nullptr; + if (const auto *TT = dyn_cast(Type)) + TD = TT->getDecl(); + else + TD = Type->getAsCXXRecordDecl(); + + if (TD) + return CreateNestedNameSpecifier(Ctx, TD, true /*FullyQualified*/); + + if (const auto *TDD = dyn_cast(Type)) + return CreateNestedNameSpecifier(Ctx, TDD->getDecl(), + true /*FullyQualified*/); + } else if (const NamespaceDecl *NS = Scope->getAsNamespace()) + return CreateNestedNameSpecifier(Ctx, NS); + else if (const auto *Alias = Scope->getAsNamespaceAlias()) + return CreateNestedNameSpecifier(Ctx, + Alias->getNamespace()->getCanonicalDecl()); + + return Scope; +} + +static bool GetFullyQualifiedTemplateName(const ASTContext &Ctx, + TemplateName &Name) { + + bool Changed = false; + NestedNameSpecifier *NNS = nullptr; + + TemplateDecl *TD = Name.getAsTemplateDecl(); + QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName(); + + if (QTN && !QTN->hasTemplateKeyword()) { + NNS = QTN->getQualifier(); + NestedNameSpecifier *QNNS = GetFullyQualifiedNameSpecifier(Ctx, NNS); + if (QNNS != NNS) { + Changed = true; + NNS = QNNS; + } else { + NNS = nullptr; + } + } else { + NNS = CreateNestedNameSpecifierForScopeOf(Ctx, TD, true); + } + if (NNS) { + Name = Ctx.getQualifiedTemplateName(NNS, + /*TemplateKeyword=*/false, + TemplateName(TD)); + Changed = true; + } + return Changed; +} + +static bool GetFullyQualifiedTemplateArgument(const ASTContext &Ctx, + TemplateArgument &Arg) { + bool Changed = false; + + // Note: we do not handle TemplateArgument::Expression, to replace it + // we need the information for the template instance decl. + // See GetPartiallyDesugaredTypeImpl + + if (Arg.getKind() == TemplateArgument::Template) { + TemplateName Name = Arg.getAsTemplate(); + Changed = GetFullyQualifiedTemplateName(Ctx, Name); + if (Changed) { + Arg = TemplateArgument(Name); + } + } else if (Arg.getKind() == TemplateArgument::Type) { + QualType SubTy = Arg.getAsType(); + // Check if the type needs more desugaring and recurse. + QualType QTFQ = GetFullyQualifiedType(SubTy, Ctx); + if (QTFQ != SubTy) { + Arg = TemplateArgument(QTFQ); + Changed = true; + } + } else if (Arg.getKind() == TemplateArgument::Pack) { + SmallVector desArgs; + for (auto I = Arg.pack_begin(), E = Arg.pack_end(); I != E; ++I) { + TemplateArgument PackArg(*I); + Changed = GetFullyQualifiedTemplateArgument(Ctx, PackArg); + desArgs.push_back(PackArg); + } + if (Changed) { + // The allocator in ASTContext is mutable ... + // Keep the argument const to be inline will all the other interfaces + // like: NestedNameSpecifier::Create + ASTContext &MutableCtx(const_cast(Ctx)); + Arg = TemplateArgument::CreatePackCopy(MutableCtx, desArgs); + } + } + return Changed; +} + +static const Type *GetFullyQualifiedLocalType(const ASTContext &Ctx, + const Type *Typeptr) { + // We really just want to handle the template parameter if any .... + // In case of template specializations iterate over the arguments and + // fully qualify them as well. + if (const auto *TST = dyn_cast(Typeptr)) { + + bool MightHaveChanged = false; + llvm::SmallVector DesArgs; + for (auto &I : TST->template_arguments()) { + + // cheap to copy and potentially modified by + // GetFullyQualifedTemplateArgument + TemplateArgument Arg(I); + MightHaveChanged |= GetFullyQualifiedTemplateArgument(Ctx, Arg); + DesArgs.push_back(Arg); + } + + // If desugaring happened allocate new type in the AST. + if (MightHaveChanged) { + QualType QT = Ctx.getTemplateSpecializationType( + TST->getTemplateName(), DesArgs, TST->getCanonicalTypeInternal()); + return QT.getTypePtr(); + } + } else if (const auto *TSTRecord = dyn_cast(Typeptr)) { + // We are asked to fully qualify and we have a Record Type, + // which can point to a template instantiation with no sugar in any of + // its template argument, however we still need to fully qualify them. + + if (const auto *TSTdecl = + dyn_cast(TSTRecord->getDecl())) { + const TemplateArgumentList &TemplateArgs = TSTdecl->getTemplateArgs(); + + bool MightHaveChanged = false; + llvm::SmallVector DesArgs; + for (unsigned int I = 0, E = TemplateArgs.size(); I != E; ++I) { + + // cheap to copy and potentially modified by + // GetFullyQualifedTemplateArgument + TemplateArgument Arg(TemplateArgs[I]); + MightHaveChanged |= GetFullyQualifiedTemplateArgument(Ctx, Arg); + DesArgs.push_back(Arg); + } + + // If desugaring happened allocate new type in the AST. + if (MightHaveChanged) { + TemplateName TN(TSTdecl->getSpecializedTemplate()); + QualType QT = Ctx.getTemplateSpecializationType( + TN, DesArgs, TSTRecord->getCanonicalTypeInternal()); + return QT.getTypePtr(); + } + } + } + return Typeptr; +} + +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const NamespaceDecl *NSD) { + while (NSD && NSD->isInline()) { + // Ignore inline namespace; + NSD = dyn_cast_if_present(NSD->getDeclContext()); + } + if (!NSD) + return nullptr; + + bool FullyQualified = true; // doesn't matter, DeclContexts are namespaces + return NestedNameSpecifier::Create( + Ctx, CreateOuterNNS(Ctx, NSD, FullyQualified), NSD); +} + +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const TypedefNameDecl *TD, + bool FullyQualify) { + return NestedNameSpecifier::Create(Ctx, CreateOuterNNS(Ctx, TD, FullyQualify), + /*Template=*/true, TD->getTypeForDecl()); +} + +NestedNameSpecifier *CreateNestedNameSpecifier(const ASTContext &Ctx, + const TagDecl *TD, + bool FullyQualify) { + const Type *Ty = Ctx.getTypeDeclType(TD).getTypePtr(); + if (FullyQualify) + Ty = GetFullyQualifiedLocalType(Ctx, Ty); + return NestedNameSpecifier::Create(Ctx, CreateOuterNNS(Ctx, TD, FullyQualify), + /*Template=*/false, Ty); +} + +QualType GetFullyQualifiedType(QualType QT, const ASTContext &Ctx) { + // Return the fully qualified type, if we need to recurse through any + // template parameter, this needs to be merged somehow with + // GetPartialDesugaredType. + + // In case of myType* we need to strip the pointer first, fully qualifiy + // and attach the pointer once again. + if (isa(QT.getTypePtr())) { + // Get the qualifiers. + Qualifiers Quals = QT.getQualifiers(); + QT = GetFullyQualifiedType(QT->getPointeeType(), Ctx); + QT = Ctx.getPointerType(QT); + // Add back the qualifiers. + QT = Ctx.getQualifiedType(QT, Quals); + return QT; + } + + // In case of myType& we need to strip the pointer first, fully qualifiy + // and attach the pointer once again. + if (isa(QT.getTypePtr())) { + // Get the qualifiers. + bool IsLValueRefTy = isa(QT.getTypePtr()); + Qualifiers Quals = QT.getQualifiers(); + QT = GetFullyQualifiedType(QT->getPointeeType(), Ctx); + // Add the r- or l-value reference type back to the desugared one. + if (IsLValueRefTy) + QT = Ctx.getLValueReferenceType(QT); + else + QT = Ctx.getRValueReferenceType(QT); + // Add back the qualifiers. + QT = Ctx.getQualifiedType(QT, Quals); + return QT; + } + + // Strip deduced types. + if (const auto *AutoTy = dyn_cast(QT.getTypePtr())) { + if (!AutoTy->getDeducedType().isNull()) + return GetFullyQualifiedType( + AutoTy->getDeducedType().getDesugaredType(Ctx), Ctx); + } + + // Remove the part of the type related to the type being a template + // parameter (we won't report it as part of the 'type name' and it is + // actually make the code below to be more complex (to handle those) + while (isa(QT.getTypePtr())) { + // Get the qualifiers. + Qualifiers Quals = QT.getQualifiers(); + + QT = cast(QT.getTypePtr())->desugar(); + + // Add back the qualifiers. + QT = Ctx.getQualifiedType(QT, Quals); + } + + NestedNameSpecifier *Prefix = nullptr; + Qualifiers PrefixQualifiers; + if (const auto *EType = dyn_cast(QT.getTypePtr())) { + // Intentionally, we do not care about the other compononent of + // the elaborated type (the keyword) as part of the partial + // desugaring (and/or name normalization) is to remove it. + Prefix = EType->getQualifier(); + if (Prefix) { + const NamespaceDecl *NS = Prefix->getAsNamespace(); + if (Prefix != NestedNameSpecifier::GlobalSpecifier(Ctx) && + !(NS && NS->isAnonymousNamespace())) { + PrefixQualifiers = QT.getLocalQualifiers(); + Prefix = GetFullyQualifiedNameSpecifier(Ctx, Prefix); + QT = QualType(EType->getNamedType().getTypePtr(), 0); + } else { + Prefix = nullptr; + } + } + } else { + + // Create a nested name specifier if needed (i.e. if the decl context + // is not the global scope. + Prefix = CreateNestedNameSpecifierForScopeOf(Ctx, QT.getTypePtr(), + true /*FullyQualified*/); + + // move the qualifiers on the outer type (avoid 'std::const string'!) + if (Prefix) { + PrefixQualifiers = QT.getLocalQualifiers(); + QT = QualType(QT.getTypePtr(), 0); + } + } + + // In case of template specializations iterate over the arguments and + // fully qualify them as well. + if (isa(QT.getTypePtr())) { + + Qualifiers Qualifiers = QT.getLocalQualifiers(); + const Type *TypePtr = GetFullyQualifiedLocalType(Ctx, QT.getTypePtr()); + QT = Ctx.getQualifiedType(TypePtr, Qualifiers); + + } else if (isa(QT.getTypePtr())) { + // We are asked to fully qualify and we have a Record Type, + // which can point to a template instantiation with no sugar in any of + // its template argument, however we still need to fully qualify them. + + Qualifiers Qualifiers = QT.getLocalQualifiers(); + const Type *TypePtr = GetFullyQualifiedLocalType(Ctx, QT.getTypePtr()); + QT = Ctx.getQualifiedType(TypePtr, Qualifiers); + } + if (Prefix) { + // We intentionally always use ETK_None, we never want + // the keyword (humm ... what about anonymous types?) + QT = Ctx.getElaboratedType(ETK_None, Prefix, QT); + QT = Ctx.getQualifiedType(QT, PrefixQualifiers); + } + return QT; +} + std::string GetFullTypeName(ASTContext &Ctx, QualType QT) { + QualType FQT = GetFullyQualifiedType(QT, Ctx); PrintingPolicy Policy(Ctx.getPrintingPolicy()); Policy.SuppressScope = false; Policy.AnonymousTagLocations = false; - return QT.getAsString(Policy); + return FQT.getAsString(Policy); } -} // namespace clang +} // namespace clang::caas Index: clang/lib/Interpreter/Value.cpp =================================================================== --- clang/lib/Interpreter/Value.cpp +++ clang/lib/Interpreter/Value.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Interpreter/Value.h" +#include "InterpreterUtils.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Type.h" #include "clang/Interpreter/Interpreter.h" @@ -23,6 +24,7 @@ #include using namespace clang; +using namespace clang::caas; namespace { @@ -230,6 +232,11 @@ return Data.m_Ptr; } +void **Value::getPtrAddress() const { + assert(ValueKind == K_PtrOrObj); + return &const_cast(this)->Data.m_Ptr; +} + QualType Value::getType() const { return QualType::getFromOpaquePtr(OpaqueType); } @@ -255,12 +262,30 @@ void Value::dump() const { print(llvm::outs()); } void Value::printType(llvm::raw_ostream &Out) const { - Out << "Not implement yet.\n"; + Out << ReplPrintTypeImpl(*this); } + void Value::printData(llvm::raw_ostream &Out) const { - Out << "Not implement yet.\n"; + Out << ReplPrintDataImpl(*this); } +// FIXME: We do not support the multiple inheritance case where one of the base +// classes has a pretty-printer and the other does not. void Value::print(llvm::raw_ostream &Out) const { assert(OpaqueType != nullptr && "Can't print default Value"); - Out << "Not implement yet.\n"; + + // Don't even try to print a void or an invalid type, it doesn't make sense. + if (getType()->isVoidType() || !isValid()) + return; + + // We need to get all the results together then print it, since `printType` is + // much faster than `printData`. + std::string Str; + llvm::raw_string_ostream SS(Str); + + SS << "("; + printType(SS); + SS << ") "; + printData(SS); + SS << "\n"; + Out << Str; } Index: clang/test/Interpreter/pretty-print.cpp =================================================================== --- /dev/null +++ clang/test/Interpreter/pretty-print.cpp @@ -0,0 +1,206 @@ +// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \ +// RUN: 'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s +// UNSUPPORTED: system-aix +// CHECK-DRIVER: i = 10 +// RUN: cat %s | clang-repl -Xcc -std=c++11 -Xcc -fno-delayed-template-parsing | FileCheck %s +extern "C" int printf(const char*,...); + +char c = 'a'; +c +// CHECK: (char) 'a' + +struct NonPOD { \ + static int sI; \ + int I; \ + NonPOD(): I(sI++) {} \ +}; +const char* PrintValueRuntime(const NonPOD* type) { \ + switch (type->I) { \ + default: return "out-of-bounds"; \ + case 0: return "0"; case 1: return "1"; case 2: return "2"; \ + case 3: return "3"; case 4: return "4"; case 5: return "5"; \ + } \ +} + +int NonPOD::sI = 0; + +NonPOD non_pod_arr[2][3]; +// Check array order after the value printing transformation. Also make sure we +// can handle the forward declaration of operator new with placement. +non_pod_arr +// CHECK-NEXT: (NonPOD[2][3]) { { 0, 1, 2 }, { 3, 4, 5 } } + +const char* c_str = "Goodbye, world!"; +c_str +// CHECK-NEXT: (const char *) "Goodbye, world!" + +const char* c_null_str = 0; +c_null_str +// CHECK-NEXT: (const char *) nullptr + +"Hello, world" +// CHECK-NEXT: (const char[13]) "Hello, world" + +int x = 42; +x +// CHECK-NEXT: (int) 42 + +&x +// CHECK-NEXT: (int *) @0x{{[0-9a-f]+}} + +x - 2 +// CHECK-NEXT: (int) 40 + +float f = 4.2f; +f +// CHECK-NEXT: (float) 4.20000f + +double d = 4.21; +d +// CHECK-NEXT: (double) 4.21000000000 + +struct S1{}; +S1 s1; +s1 +// CHECK-NEXT: (S1 &) @0x{{[0-9a-f]+}} + +S1{} +// CHECK-NEXT: (S1) @0x{{[0-9a-f]+}} + +struct S2 {int d;} E = {22}; +E +// CHECK-NEXT: (struct S2 &) @0x{{[0-9a-f]+}} +E.d +// CHECK-NEXT: (int) 22 + +struct S3 { int* p; S3() { p = new int(42); } ~S3() { delete p; } }; +S3{} +// CHECK-NEXT: (S3) @0x{{[0-9a-f]+}} +S3 s3; +s3 +// CHECK-NEXT: (S3 &) @0x{{[0-9a-f]+}} + +struct S4 { ~S4() { printf("~S4()\n"); }}; +S4{} +// CHECK-NEXT: (S4) @0x{{[0-9a-f]+}} + +enum Enum{ e1 = -12, e2, e3=33, e4, e5 = 33}; +e2 +// CHECK-NEXT: (Enum) (e2) : int -11 +::e1 +// CHECK-NEXT: (Enum) (e1) : int -12 + +enum class Color { Black = 0, Red, Green }; +Color::Black +// CHECK-NEXT: (Color) (Color::Black) : int 0 + +// Arrays. + +int arr[3] = {1,2,3}; +arr +// CHECK-NEXT: (int[3]) { 1, 2, 3 } + + +// Lambdas. + +auto Lambda1 = []{}; +Lambda1 +// CHECK-NEXT: ((lambda) &) @0x{{[0-9a-f]+}} +[]{} +// CHECK-NEXT: ((lambda at input_line_{{[0-9]+}}:1:1)) @0x{{[0-9a-f]+}} + +template struct F{ enum {RET=F::RET*n} ; }; +template<> struct F<0> { enum {RET = 1}; }; +F<7>::RET +// CHECK-NEXT: (F<7>::(unnamed enum at input_line_{{[0-9]+}}:1:27)) (F<7>::RET) : unsigned int 5040 + +int foo() { return 42; } +foo() +// CHECK-NEXT: (int) 42 + +void bar() {} +bar() + +struct S5 { int foo() { return 42; }}; +&S5::foo +// CHECK-NEXT: (int (S5::*)()) Function @0x{{[0-9a-f]+}} + +#include + +auto p1 = std::make_shared(42); +p1 +// CHECK-NEXT: (std::shared_ptr &) std::shared_ptr -> @0x{{[0-9a-f]+}} + +std::unique_ptr p2(new int(42)); +p2 +// CHECK-NEXT: (std::unique_ptr &) std::unique_ptr -> @0x{{[0-9a-f]+}} + +#include +std::array a{1, 2, 3}; +a +// CHECK-NEXT: (std::array &) { 1, 2, 3 } + +#include +std::vector v1 = {7, 5, 16, 8}; +v1 +// CHECK-NEXT: (std::vector &) { 7, 5, 16, 8 } + +std::vector v = {true, false, true}; +v +// CHECK-NEXT: (std::vector &) { true, false, true } + +#include +std::deque dq = {7, 5, 16, 8}; +dq +// CHECK-NEXT: (std::deque &) { 7, 5, 16, 8 } + +#include +std::forward_list fl {3,4,5,6}; +fl +// CHECK-NEXT: (std::forward_list &) { 3, 4, 5, 6 } + +#include +std::set z1 = {2,4,6,8}; +z1 +// CHECK-NEXT: (std::set &) { 2, 4, 6, 8 } + +#include +std::unordered_set z2 = {8,2,4,6}; +z2 +// CHECK-NEXT: (std::unordered_set &) { [[Num:[0-9]+]], [[Num:[0-9]+]], [[Num:[0-9]+]], [[Num:[0-9]+]] } + +std::multiset e {3,2,1,2,4,7,3}; +e +// CHECK-NEXT: (std::multiset &) { 1, 2, 2, 3, 3, 4, 7 } + +#include +std::string std_str = "Hello, world!"; +std_str +// CHECK-NEXT: (std::string &) "Hello, world!" + +#include +std::pair pr(42,'a'); +pr +// CHECK-NEXT: (std::pair &) { 42, 'a' } + +#include +std::tuple tu(42,3.14,'a'); +tu +// CHECK-NEXT: (std::tuple &) { 42, 3.14000000000, 'a' } + +#include +std::map m1{{"CPU", 10}, {"GPU", 15}, {"RAM", 20}}; +m1 +// CHECK-NEXT: (std::map &) { "CPU" => 10, "GPU" => 15, "RAM" => 20 } + +#include +std::unordered_map m2 = { {1,2}, {3,4}}; +m2 +// CHECK-NEXT: (std::unordered_map &) { [[Num:[0-9]+]] => [[Num:[0-9]+]], [[Num:[0-9]+]] => [[Num:[0-9]+]] } + +struct MyType {}; +std::string PrintValueRuntime(const MyType*) { return "My pretty printer!"; } +MyType{} +// CHECK-NEXT: (MyType) My pretty printer! +%quit + Index: clang/test/Modules/pr60085.cppm =================================================================== --- clang/test/Modules/pr60085.cppm +++ clang/test/Modules/pr60085.cppm @@ -32,28 +32,16 @@ export template struct integer { - using type = int; - - static constexpr auto value() { - return 0; - } - - friend constexpr void f(integer const x) { - x.value(); - } -}; - -export constexpr void ddd(auto const value) { - f(value); -} + using type = int; + static constexpr auto value() { + return 0; + } -template -constexpr auto dd = T(); +}; -export template -constexpr auto d() { - dd; +export constexpr void ddd(auto const v) { + v.value(); } //--- c.cppm @@ -61,38 +49,20 @@ import d; -template -auto cc = T(); - -auto c() { - cc>; - integer().value(); -} +int use = integer().value(); //--- b.cppm export module b; import d; -auto b() { - integer::type; -} +using use = integer::type; //--- a.cppm export module a; -import b; -import c; import d; -constexpr void aa() { - d>(); - ddd(integer()); +export void a() { + ddd(integer()); } - -export extern "C" void a() { - aa(); -} - -// Checks that we emit the IR successfully. -// CHECK: define{{.*}}@a( Index: clang/tools/clang-repl/CMakeLists.txt =================================================================== --- clang/tools/clang-repl/CMakeLists.txt +++ clang/tools/clang-repl/CMakeLists.txt @@ -11,6 +11,65 @@ ClangRepl.cpp ) +if(MSVC) + set_target_properties(clang-repl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1) + + # RTTI/C++ symbols + set(clang_repl_exports ${clang_repl_exports} ??_7type_info@@6B@ + ?__type_info_root_node@@3U__type_info_node@@A + ?nothrow@std@@3Unothrow_t@1@B + ) + + # Compiler added symbols for static variables. NOT for VStudio < 2015 + set(clang_repl_exports ${clang_repl_exports} _Init_thread_abort _Init_thread_epoch + _Init_thread_footer _Init_thread_header _tls_index + ) + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # new/delete variants needed when linking to static msvc runtime (esp. Debug) + set(clang_repl_exports ${clang_repl_exports} + ??2@YAPEAX_K@Z + ??3@YAXPEAX@Z + ??_U@YAPEAX_K@Z + ??_V@YAXPEAX@Z + ??3@YAXPEAX_K@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@PEBX@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@P6AAEAV01@AEAV01@@Z@Z + ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@D@Z + ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z + ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z + ) + else() + set(clang_repl_exports ${clang_repl_exports} + ??2@YAPAXI@Z + ??3@YAXPAX@Z + ??3@YAXPAXI@Z + ??_U@YAPAXI@Z + ??_V@YAXPAX@Z + ??_V@YAXPAXI@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@M@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z + ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@D@Z + ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z + ?_Facet_Register@std@@YAXPAV_Facet_base@1@@Z + ) + endif() + + # List to '/EXPORT:sym0 /EXPORT:sym1 /EXPORT:sym2 ...' + foreach(sym ${clang_repl_exports}) + set(clang_repl_link_str "${clang_repl_link_str} /EXPORT:${sym}") + endforeach(sym ${clang_repl_exports}) + + set_property(TARGET clang-repl APPEND_STRING PROPERTY LINK_FLAGS ${clang_repl_link_str}) + +endif(MSVC) + clang_target_link_libraries(clang-repl PRIVATE clangAST clangBasic Index: clang/tools/clang-repl/ClangRepl.cpp =================================================================== --- clang/tools/clang-repl/ClangRepl.cpp +++ clang/tools/clang-repl/ClangRepl.cpp @@ -97,7 +97,7 @@ return 0; } - clang::IncrementalCompilerBuilder CB; + clang::caas::IncrementalCompilerBuilder CB; CB.SetCompilerArgs(ClangArgv); std::unique_ptr DeviceCI; @@ -132,10 +132,10 @@ if (CudaEnabled) DeviceCI->LoadRequestedPlugins(); - std::unique_ptr Interp; + std::unique_ptr Interp; if (CudaEnabled) { - Interp = ExitOnErr( - clang::Interpreter::createWithCUDA(std::move(CI), std::move(DeviceCI))); + Interp = ExitOnErr(clang::caas::Interpreter::createWithCUDA( + std::move(CI), std::move(DeviceCI))); if (CudaPath.empty()) { ExitOnErr(Interp->LoadDynamicLibrary("libcudart.so")); @@ -144,7 +144,7 @@ ExitOnErr(Interp->LoadDynamicLibrary(CudaRuntimeLibPath.c_str())); } } else - Interp = ExitOnErr(clang::Interpreter::create(std::move(CI))); + Interp = ExitOnErr(clang::caas::Interpreter::create(std::move(CI))); for (const std::string &input : OptInputs) { if (auto Err = Interp->ParseAndExecute(input)) Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp =================================================================== --- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp +++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp @@ -30,6 +30,7 @@ #include "gtest/gtest.h" using namespace clang; +using namespace clang::caas; namespace { using Args = std::vector; @@ -38,12 +39,12 @@ DiagnosticConsumer *Client = nullptr) { Args ClangArgs = {"-Xclang", "-emit-llvm-only"}; ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end()); - auto CB = clang::IncrementalCompilerBuilder(); + auto CB = clang::caas::IncrementalCompilerBuilder(); CB.SetCompilerArgs(ClangArgs); auto CI = cantFail(CB.CreateCpp()); if (Client) CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false); - return cantFail(clang::Interpreter::create(std::move(CI))); + return cantFail(clang::caas::Interpreter::create(std::move(CI))); } TEST(InterpreterTest, CatchException) { Index: clang/unittests/Interpreter/IncrementalProcessingTest.cpp =================================================================== --- clang/unittests/Interpreter/IncrementalProcessingTest.cpp +++ clang/unittests/Interpreter/IncrementalProcessingTest.cpp @@ -27,6 +27,7 @@ using namespace llvm; using namespace clang; +using namespace clang::caas; namespace { @@ -52,12 +53,12 @@ TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) { std::vector ClangArgv = {"-Xclang", "-emit-llvm-only"}; - auto CB = clang::IncrementalCompilerBuilder(); + auto CB = clang::caas::IncrementalCompilerBuilder(); CB.SetCompilerArgs(ClangArgv); auto CI = cantFail(CB.CreateCpp()); auto Interp = llvm::cantFail(Interpreter::create(std::move(CI))); - std::array PTUs; + std::array PTUs; PTUs[0] = &llvm::cantFail(Interp->Parse(TestProgram1)); ASSERT_TRUE(PTUs[0]->TheModule); Index: clang/unittests/Interpreter/InterpreterTest.cpp =================================================================== --- clang/unittests/Interpreter/InterpreterTest.cpp +++ clang/unittests/Interpreter/InterpreterTest.cpp @@ -29,6 +29,7 @@ #include "gtest/gtest.h" using namespace clang; +using namespace caas; #if defined(_AIX) #define CLANG_INTERPRETER_NO_SUPPORT_EXEC @@ -46,12 +47,12 @@ DiagnosticConsumer *Client = nullptr) { Args ClangArgs = {"-Xclang", "-emit-llvm-only"}; ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end()); - auto CB = clang::IncrementalCompilerBuilder(); + auto CB = clang::caas::IncrementalCompilerBuilder(); CB.SetCompilerArgs(ClangArgs); auto CI = cantFail(CB.CreateCpp()); if (Client) CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false); - return cantFail(clang::Interpreter::create(std::move(CI))); + return cantFail(clang::caas::Interpreter::create(std::move(CI))); } static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {