<div dir="ltr">Good call, fixed in r264562.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 27, 2016 at 12:29 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, Mar 26, 2016 at 9:46 PM, David Majnemer via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: majnemer<br>
> Date: Sat Mar 26 23:46:07 2016<br>
> New Revision: 264529<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264529&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=264529&view=rev</a><br>
> Log:<br>
> Improve the representation of CXXUuidofExpr<br>
><br>
> Keep a pointer to the UuidAttr that the CXXUuidofExpr corresponds to.<br>
> This makes translating from __uuidof to the underlying constant a lot<br>
> more straightforward.<br>
><br>
> Modified:<br>
> cfe/trunk/include/clang/AST/ExprCXX.h<br>
> cfe/trunk/lib/AST/ExprCXX.cpp<br>
> cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
> cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/AST/ExprCXX.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=264529&r1=264528&r2=264529&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=264529&r1=264528&r2=264529&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/AST/ExprCXX.h (original)<br>
> +++ cfe/trunk/include/clang/AST/ExprCXX.h Sat Mar 26 23:46:07 2016<br>
> @@ -778,22 +778,23 @@ public:<br>
> class CXXUuidofExpr : public Expr {<br>
> private:<br>
> llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;<br>
> + const UuidAttr *UA;<br>
> SourceRange Range;<br>
<br>
</div></div>Looks like the serialization / deserialization code for this new<br>
member is missing? Does this correctly round-trip through AST files?<br>
<div class="HOEnZb"><div class="h5"><br>
> public:<br>
> - CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)<br>
> - : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,<br>
> - false, Operand->getType()->isDependentType(),<br>
> - Operand->getType()->isInstantiationDependentType(),<br>
> - Operand->getType()->containsUnexpandedParameterPack()),<br>
> - Operand(Operand), Range(R) { }<br>
> -<br>
> - CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)<br>
> - : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,<br>
> - false, Operand->isTypeDependent(),<br>
> - Operand->isInstantiationDependent(),<br>
> - Operand->containsUnexpandedParameterPack()),<br>
> - Operand(Operand), Range(R) { }<br>
> + CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, const UuidAttr *UA,<br>
> + SourceRange R)<br>
> + : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,<br>
> + Operand->getType()->isDependentType(),<br>
> + Operand->getType()->isInstantiationDependentType(),<br>
> + Operand->getType()->containsUnexpandedParameterPack()),<br>
> + Operand(Operand), UA(UA), Range(R) {}<br>
> +<br>
> + CXXUuidofExpr(QualType Ty, Expr *Operand, const UuidAttr *UA, SourceRange R)<br>
> + : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,<br>
> + Operand->isTypeDependent(), Operand->isInstantiationDependent(),<br>
> + Operand->containsUnexpandedParameterPack()),<br>
> + Operand(Operand), UA(UA), Range(R) {}<br>
><br>
> CXXUuidofExpr(EmptyShell Empty, bool isExpr)<br>
> : Expr(CXXUuidofExprClass, Empty) {<br>
> @@ -830,7 +831,7 @@ public:<br>
> Operand = E;<br>
> }<br>
><br>
> - StringRef getUuidAsStringRef(ASTContext &Context) const;<br>
> + StringRef getUuidAsStringRef() const;<br>
><br>
> SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }<br>
> SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }<br>
> @@ -841,11 +842,6 @@ public:<br>
> return T->getStmtClass() == CXXUuidofExprClass;<br>
> }<br>
><br>
> - /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to<br>
> - /// a single GUID.<br>
> - static const UuidAttr *GetUuidAttrOfType(QualType QT,<br>
> - bool *HasMultipleGUIDsPtr = nullptr);<br>
> -<br>
> // Iterators<br>
> child_range children() {<br>
> if (isTypeOperand())<br>
><br>
> Modified: cfe/trunk/lib/AST/ExprCXX.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=264529&r1=264528&r2=264529&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=264529&r1=264528&r2=264529&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/AST/ExprCXX.cpp (original)<br>
> +++ cfe/trunk/lib/AST/ExprCXX.cpp Sat Mar 26 23:46:07 2016<br>
> @@ -54,77 +54,8 @@ QualType CXXUuidofExpr::getTypeOperand(A<br>
> Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);<br>
> }<br>
><br>
> -// static<br>
> -const UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT,<br>
> - bool *RDHasMultipleGUIDsPtr) {<br>
> - // Optionally remove one level of pointer, reference or array indirection.<br>
> - const Type *Ty = QT.getTypePtr();<br>
> - if (QT->isPointerType() || QT->isReferenceType())<br>
> - Ty = QT->getPointeeType().getTypePtr();<br>
> - else if (QT->isArrayType())<br>
> - Ty = Ty->getBaseElementTypeUnsafe();<br>
> -<br>
> - const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();<br>
> - if (!RD)<br>
> - return nullptr;<br>
> -<br>
> - if (const UuidAttr *Uuid = RD->getMostRecentDecl()->getAttr<UuidAttr>())<br>
> - return Uuid;<br>
> -<br>
> - // __uuidof can grab UUIDs from template arguments.<br>
> - if (const ClassTemplateSpecializationDecl *CTSD =<br>
> - dyn_cast<ClassTemplateSpecializationDecl>(RD)) {<br>
> - const TemplateArgumentList &TAL = CTSD->getTemplateArgs();<br>
> - const UuidAttr *UuidForRD = nullptr;<br>
> -<br>
> - for (const TemplateArgument &TA : TAL.asArray()) {<br>
> - bool SeenMultipleGUIDs = false;<br>
> -<br>
> - const UuidAttr *UuidForTA = nullptr;<br>
> - if (TA.getKind() == TemplateArgument::Type)<br>
> - UuidForTA = GetUuidAttrOfType(TA.getAsType(), &SeenMultipleGUIDs);<br>
> - else if (TA.getKind() == TemplateArgument::Declaration)<br>
> - UuidForTA =<br>
> - GetUuidAttrOfType(TA.getAsDecl()->getType(), &SeenMultipleGUIDs);<br>
> -<br>
> - // If the template argument has a UUID, there are three cases:<br>
> - // - This is the first UUID seen for this RecordDecl.<br>
> - // - This is a different UUID than previously seen for this RecordDecl.<br>
> - // - This is the same UUID than previously seen for this RecordDecl.<br>
> - if (UuidForTA) {<br>
> - if (!UuidForRD)<br>
> - UuidForRD = UuidForTA;<br>
> - else if (UuidForRD != UuidForTA)<br>
> - SeenMultipleGUIDs = true;<br>
> - }<br>
> -<br>
> - // Seeing multiple UUIDs means that we couldn't find a UUID<br>
> - if (SeenMultipleGUIDs) {<br>
> - if (RDHasMultipleGUIDsPtr)<br>
> - *RDHasMultipleGUIDsPtr = true;<br>
> - return nullptr;<br>
> - }<br>
> - }<br>
> -<br>
> - return UuidForRD;<br>
> - }<br>
> -<br>
> - return nullptr;<br>
> -}<br>
> -<br>
> -StringRef CXXUuidofExpr::getUuidAsStringRef(ASTContext &Context) const {<br>
> - StringRef Uuid;<br>
> - if (isTypeOperand())<br>
> - Uuid = CXXUuidofExpr::GetUuidAttrOfType(getTypeOperand(Context))->getGuid();<br>
> - else {<br>
> - // Special case: __uuidof(0) means an all-zero GUID.<br>
> - Expr *Op = getExprOperand();<br>
> - if (!Op->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull))<br>
> - Uuid = CXXUuidofExpr::GetUuidAttrOfType(Op->getType())->getGuid();<br>
> - else<br>
> - Uuid = "00000000-0000-0000-0000-000000000000";<br>
> - }<br>
> - return Uuid;<br>
> +StringRef CXXUuidofExpr::getUuidAsStringRef() const {<br>
> + return UA ? UA->getGuid() : "00000000-0000-0000-0000-000000000000";<br>
> }<br>
><br>
> // CXXScalarValueInitExpr<br>
><br>
> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=264529&r1=264528&r2=264529&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=264529&r1=264528&r2=264529&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)<br>
> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Sat Mar 26 23:46:07 2016<br>
> @@ -1186,7 +1186,7 @@ void MicrosoftCXXNameMangler::mangleExpr<br>
><br>
> // This CXXUuidofExpr is mangled as-if it were actually a VarDecl from<br>
> // const __s_GUID _GUID_{lower case UUID with underscores}<br>
> - StringRef Uuid = UE->getUuidAsStringRef(Context.getASTContext());<br>
> + StringRef Uuid = UE->getUuidAsStringRef();<br>
> std::string Name = "_GUID_" + Uuid.lower();<br>
> std::replace(Name.begin(), Name.end(), '-', '_');<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=264529&r1=264528&r2=264529&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=264529&r1=264528&r2=264529&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Mar 26 23:46:07 2016<br>
> @@ -1454,7 +1454,7 @@ ConstantAddress CodeGenModule::GetAddrOf<br>
> const CXXUuidofExpr* E) {<br>
> // Sema has verified that IIDSource has a __declspec(uuid()), and that its<br>
> // well-formed.<br>
> - StringRef Uuid = E->getUuidAsStringRef(Context);<br>
> + StringRef Uuid = E->getUuidAsStringRef();<br>
> std::string Name = "_GUID_" + Uuid.lower();<br>
> std::replace(Name.begin(), Name.end(), '-', '_');<br>
><br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=264529&r1=264528&r2=264529&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=264529&r1=264528&r2=264529&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Mar 26 23:46:07 2016<br>
> @@ -508,23 +508,60 @@ Sema::ActOnCXXTypeid(SourceLocation OpLo<br>
> return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc);<br>
> }<br>
><br>
> +/// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to<br>
> +/// a single GUID.<br>
> +static void<br>
> +getUuidAttrOfType(Sema &SemaRef, QualType QT,<br>
> + llvm::SmallSetVector<const UuidAttr *, 1> &UuidAttrs) {<br>
> + // Optionally remove one level of pointer, reference or array indirection.<br>
> + const Type *Ty = QT.getTypePtr();<br>
> + if (QT->isPointerType() || QT->isReferenceType())<br>
> + Ty = QT->getPointeeType().getTypePtr();<br>
> + else if (QT->isArrayType())<br>
> + Ty = Ty->getBaseElementTypeUnsafe();<br>
> +<br>
> + const auto *RD = Ty->getAsCXXRecordDecl();<br>
> + if (!RD)<br>
> + return;<br>
> +<br>
> + if (const auto *Uuid = RD->getMostRecentDecl()->getAttr<UuidAttr>()) {<br>
> + UuidAttrs.insert(Uuid);<br>
> + return;<br>
> + }<br>
> +<br>
> + // __uuidof can grab UUIDs from template arguments.<br>
> + if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {<br>
> + const TemplateArgumentList &TAL = CTSD->getTemplateArgs();<br>
> + for (const TemplateArgument &TA : TAL.asArray()) {<br>
> + const UuidAttr *UuidForTA = nullptr;<br>
> + if (TA.getKind() == TemplateArgument::Type)<br>
> + getUuidAttrOfType(SemaRef, TA.getAsType(), UuidAttrs);<br>
> + else if (TA.getKind() == TemplateArgument::Declaration)<br>
> + getUuidAttrOfType(SemaRef, TA.getAsDecl()->getType(), UuidAttrs);<br>
> +<br>
> + if (UuidForTA)<br>
> + UuidAttrs.insert(UuidForTA);<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> /// \brief Build a Microsoft __uuidof expression with a type operand.<br>
> ExprResult Sema::BuildCXXUuidof(QualType TypeInfoType,<br>
> SourceLocation TypeidLoc,<br>
> TypeSourceInfo *Operand,<br>
> SourceLocation RParenLoc) {<br>
> + const UuidAttr *UA = nullptr;<br>
> if (!Operand->getType()->isDependentType()) {<br>
> - bool HasMultipleGUIDs = false;<br>
> - if (!CXXUuidofExpr::GetUuidAttrOfType(Operand->getType(),<br>
> - &HasMultipleGUIDs)) {<br>
> - if (HasMultipleGUIDs)<br>
> - return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));<br>
> - else<br>
> - return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));<br>
> - }<br>
> + llvm::SmallSetVector<const UuidAttr *, 1> UuidAttrs;<br>
> + getUuidAttrOfType(*this, Operand->getType(), UuidAttrs);<br>
> + if (UuidAttrs.empty())<br>
> + return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));<br>
> + if (UuidAttrs.size() > 1)<br>
> + return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));<br>
> + UA = UuidAttrs.back();<br>
> }<br>
><br>
> - return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), Operand,<br>
> + return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), Operand, UA,<br>
> SourceRange(TypeidLoc, RParenLoc));<br>
> }<br>
><br>
> @@ -533,18 +570,20 @@ ExprResult Sema::BuildCXXUuidof(QualType<br>
> SourceLocation TypeidLoc,<br>
> Expr *E,<br>
> SourceLocation RParenLoc) {<br>
> + const UuidAttr *UA = nullptr;<br>
> if (!E->getType()->isDependentType()) {<br>
> - bool HasMultipleGUIDs = false;<br>
> - if (!CXXUuidofExpr::GetUuidAttrOfType(E->getType(), &HasMultipleGUIDs) &&<br>
> - !E->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) {<br>
> - if (HasMultipleGUIDs)<br>
> - return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));<br>
> - else<br>
> + if (!E->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) {<br>
> + llvm::SmallSetVector<const UuidAttr *, 1> UuidAttrs;<br>
> + getUuidAttrOfType(*this, E->getType(), UuidAttrs);<br>
> + if (UuidAttrs.empty())<br>
> return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));<br>
> + if (UuidAttrs.size() > 1)<br>
> + return ExprError(Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));<br>
> + UA = UuidAttrs.back();<br>
> }<br>
> }<br>
><br>
> - return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), E,<br>
> + return new (Context) CXXUuidofExpr(TypeInfoType.withConst(), E, UA,<br>
> SourceRange(TypeidLoc, RParenLoc));<br>
> }<br>
><br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>