r226148 - AST: Ensure implicit records have default visibility

David Majnemer david.majnemer at gmail.com
Thu Jan 15 00:41:25 PST 2015

Author: majnemer
Date: Thu Jan 15 02:41:25 2015
New Revision: 226148

URL: http://llvm.org/viewvc/llvm-project?rev=226148&view=rev
AST: Ensure implicit records have default visibility

Types composed with certain implicit record types would have their RTTI
marked as hidden because the implicit record type didn't have any

This manifests itself as triggering false positives from tools like
clang's -fsantize=function feature.  The RTTI for a function type's
return type wouldn't match if the return type was an implicit record

Patch by Stephan Bergmann!


Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=226148&r1=226147&r2=226148&view=diff
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Jan 15 02:41:25 2015
@@ -876,6 +876,8 @@ RecordDecl *ASTContext::buildImplicitRec
     NewDecl = RecordDecl::Create(*this, TK, getTranslationUnitDecl(), Loc, Loc,
+  NewDecl->addAttr(TypeVisibilityAttr::CreateImplicit(
+      const_cast<ASTContext &>(*this), TypeVisibilityAttr::Default));
   return NewDecl;

Added: cfe/trunk/test/CodeGenCXX/implicit-record-visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/implicit-record-visibility.cpp?rev=226148&view=auto
--- cfe/trunk/test/CodeGenCXX/implicit-record-visibility.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/implicit-record-visibility.cpp Thu Jan 15 02:41:25 2015
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -I%S -fvisibility hidden -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+#include <stdarg.h>
+#include <typeinfo>
+// If struct __va_list_tag did not explicitly have default visibility, then
+// under -fvisibility hidden the type of function f, due to its va_list (aka
+// __builtin_va_list, aka __va_list_tag (*)[1]) parameter would be hidden:
+// CHECK: @_ZTSFvP13__va_list_tagE = linkonce_odr constant
+// CHECK: @_ZTIFvP13__va_list_tagE = linkonce_odr constant
+void f(va_list) { (void)typeid(f); }

More information about the cfe-commits mailing list