<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 27, 2014 at 8:22 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Wow, this is showing me how many of the analyzer checks aren't handling namespaces <i>within</i> std.</div>
</div></blockquote><div><br></div><div>I think they might all be correct: the last two walk up to the outermost namespace before checking whether it's 'std'. The first of the three is looking for exactly 'std::string'.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="HOEnZb"><font color="#888888"><div>Jordan</div></font></span><div>
<div class="h5"><br><div><div>On May 27, 2014, at 19:16 , Richard Trieu <<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>> wrote:</div><br><blockquote type="cite">Author: rtrieu<br>Date: Tue May 27 21:16:01 2014<br>
New Revision: 209708<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=209708&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=209708&view=rev</a><br>Log:<br>Move the logic for testing for namespace std into one location.  This check can<br>
be performed by using Decl::isInStdNamespace or DeclContext::isStdNamespace<br><br>Modified:<br>    cfe/trunk/include/clang/AST/DeclBase.h<br>    cfe/trunk/lib/AST/Decl.cpp<br>    cfe/trunk/lib/AST/DeclBase.cpp<br>    cfe/trunk/lib/Analysis/Consumed.cpp<br>
    cfe/trunk/lib/Sema/SemaExceptionSpec.cpp<br>    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>    cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp<br>    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp<br><br>Modified: cfe/trunk/include/clang/AST/DeclBase.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/include/clang/AST/DeclBase.h (original)<br>+++ cfe/trunk/include/clang/AST/DeclBase.h Tue May 27 21:16:01 2014<br>@@ -397,6 +397,8 @@ public:<br>
<br>   bool isInAnonymousNamespace() const;<br><br>+  bool isInStdNamespace() const;<br>+<br>   ASTContext &getASTContext() const LLVM_READONLY;<br><br>   void setAccess(AccessSpecifier AS) {<br>@@ -1156,6 +1158,8 @@ public:<br>
     return DeclKind == Decl::Namespace;<br>   }<br><br>+  bool isStdNamespace() const;<br>+<br>   bool isInlineNamespace() const;<br><br>   /// \brief Determines whether this context is dependent on a<br><br>Modified: cfe/trunk/lib/AST/Decl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/AST/Decl.cpp (original)<br>+++ cfe/trunk/lib/AST/Decl.cpp Tue May 27 21:16:01 2014<br>@@ -2328,12 +2328,6 @@ bool FunctionDecl::isReservedGlobalPlace<br>
   return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy);<br> }<br><br>-static bool isNamespaceStd(const DeclContext *DC) {<br>-  const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC->getRedeclContext());<br>
-  return ND && isNamed(ND, "std") &&<br>-         ND->getParent()->getRedeclContext()->isTranslationUnit();<br>-}<br>-<br> bool FunctionDecl::isReplaceableGlobalAllocationFunction() const {<br>
   if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)<br>     return false;<br>@@ -2371,9 +2365,8 @@ bool FunctionDecl::isReplaceableGlobalAl<br>   Ty = Ty->getPointeeType();<br>   if (Ty.getCVRQualifiers() != Qualifiers::Const)<br>
     return false;<br>-  // FIXME: Recognise nothrow_t in an inline namespace inside std?<br>   const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();<br>-  return RD && isNamed(RD, "nothrow_t") && isNamespaceStd(RD->getDeclContext());<br>
+  return RD && isNamed(RD, "nothrow_t") && RD->isInStdNamespace();<br> }<br><br> FunctionDecl *<br><br>Modified: cfe/trunk/lib/AST/DeclBase.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/AST/DeclBase.cpp (original)<br>+++ cfe/trunk/lib/AST/DeclBase.cpp Tue May 27 21:16:01 2014<br>@@ -251,6 +251,10 @@ bool Decl::isInAnonymousNamespace() cons<br>
   return false;<br> }<br><br>+bool Decl::isInStdNamespace() const {<br>+  return getDeclContext()->isStdNamespace();<br>+}<br>+<br> TranslationUnitDecl *Decl::getTranslationUnitDecl() {<br>   if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this))<br>
     return TUD;<br>@@ -795,6 +799,22 @@ bool DeclContext::isInlineNamespace() co<br>          cast<NamespaceDecl>(this)->isInline();<br> }<br><br>+bool DeclContext::isStdNamespace() const {<br>+  if (!isNamespace())<br>
+    return false;<br>+<br>+  const NamespaceDecl *ND = cast<NamespaceDecl>(this);<br>+  if (ND->isInline()) {<br>+    return ND->getParent()->isStdNamespace();<br>+  }<br>+<br>+  if (!getParent()->getRedeclContext()->isTranslationUnit())<br>
+    return false;<br>+<br>+  const IdentifierInfo *II = ND->getIdentifier();<br>+  return II && II->isStr("std");<br>+}<br>+<br> bool DeclContext::isDependentContext() const {<br>   if (isFileContext())<br>
     return false;<br><br>Modified: cfe/trunk/lib/Analysis/Consumed.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/Analysis/Consumed.cpp (original)<br>+++ cfe/trunk/lib/Analysis/Consumed.cpp Tue May 27 21:16:01 2014<br>@@ -739,16 +739,6 @@ void ConsumedStmtVisitor::VisitBinaryOpe<br>
   }<br> }<br><br>-static bool isStdNamespace(const DeclContext *DC) {<br>-  if (!DC->isNamespace()) return false;<br>-  while (DC->getParent()->isNamespace())<br>-    DC = DC->getParent();<br>-  const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);<br>
-<br>-  return ND && ND->getName() == "std" &&<br>-         ND->getDeclContext()->isTranslationUnit();<br>-}<br>-<br> void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) {<br>   const FunctionDecl *FunDecl = Call->getDirectCallee();<br>
   if (!FunDecl)<br>@@ -756,9 +746,8 @@ void ConsumedStmtVisitor::VisitCallExpr(<br><br>   // Special case for the std::move function.<br>   // TODO: Make this more specific. (Deferred)<br>-  if (Call->getNumArgs() == 1 &&<br>
-      FunDecl->getNameAsString() == "move" &&<br>-      isStdNamespace(FunDecl->getDeclContext())) {<br>+  if (Call->getNumArgs() == 1 && FunDecl->getNameAsString() == "move" &&<br>
+      FunDecl->isInStdNamespace()) {<br>     copyInfo(Call->getArg(0), Call, CS_Consumed);<br>     return;<br>   }<br><br>Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)<br>+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Tue May 27 21:16:01 2014<br>@@ -468,15 +468,8 @@ bool Sema::CheckEquivalentExceptionSpec(<br>
         IdentifierInfo* Name = ExRecord->getIdentifier();<br>         if (Name && Name->getName() == "bad_alloc") {<br>           // It's called bad_alloc, but is it in std?<br>-          DeclContext* DC = ExRecord->getDeclContext();<br>
-          DC = DC->getEnclosingNamespaceContext();<br>-          if (NamespaceDecl* NS = dyn_cast<NamespaceDecl>(DC)) {<br>-            IdentifierInfo* NSName = NS->getIdentifier();<br>-            DC = DC->getParent();<br>
-            if (NSName && NSName->getName() == "std" &&<br>-                DC->getEnclosingNamespaceContext()->isTranslationUnit()) {<br>-              return false;<br>-            }<br>
+          if (ExRecord->isInStdNamespace()) {<br>+            return false;<br>           }<br>         }<br>       }<br><br>Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue May 27 21:16:01 2014<br>
@@ -887,11 +887,7 @@ Decl *TemplateDeclInstantiator::VisitCla<br>         if (DCParent->isNamespace() &&<br>             cast<NamespaceDecl>(DCParent)->getIdentifier() &&<br>             cast<NamespaceDecl>(DCParent)->getIdentifier()->isStr("tr1")) {<br>
-          DeclContext *DCParent2 = DCParent->getParent();<br>-          if (DCParent2->isNamespace() &&<br>-              cast<NamespaceDecl>(DCParent2)->getIdentifier() &&<br>-              cast<NamespaceDecl>(DCParent2)->getIdentifier()->isStr("std") &&<br>
-              DCParent2->getParent()->isTranslationUnit())<br>+          if (cast<Decl>(DCParent)->isInStdNamespace())<br>             Complain = false;<br>         }<br>       }<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp Tue May 27 21:16:01 2014<br>
@@ -58,7 +58,7 @@ static bool IsStdString(QualType T) {<br><br>   const TypedefNameDecl *TD = TT->getDecl();<br><br>-  if (!InNamespace(TD, "std"))<br>+  if (!TD->isInStdNamespace())<br>     return false;<br>
<br>   return TD->getName() == "string";<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue May 27 21:16:01 2014<br>
@@ -1514,7 +1514,7 @@ static bool isInStdNamespace(const Decl<br>   while (const NamespaceDecl *Parent = dyn_cast<NamespaceDecl>(ND->getParent()))<br>     ND = Parent;<br><br>-  return ND->getName() == "std";<br>
+  return ND->isStdNamespace();<br> }<br><br><br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=209708&r1=209707&r2=209708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=209708&r1=209707&r2=209708&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Tue May 27 21:16:01 2014<br>
@@ -387,14 +387,14 @@ static bool IsInStdNamespace(const Funct<br>   const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);<br>   if (!ND)<br>     return false;<br>-  <br>+<br>   while (const DeclContext *Parent = ND->getParent()) {<br>
     if (!isa<NamespaceDecl>(Parent))<br>       break;<br>     ND = cast<NamespaceDecl>(Parent);<br>   }<br><br>-  return ND->getName() == "std";<br>+  return ND->isStdNamespace();<br> }<br><br>
 // The GDM component containing the dynamic dispatch bifurcation info. When<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br></blockquote></div><br></div></div></div><br>_______________________________________________<br>

cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>