forked from OSchip/llvm-project
				
			Walk the decls looking for the last one that has an attribute. We do have to walk
them, otherwise we cannot produce an error for both struct HIDDEN test4; // canonical struct test4; struct DEFAULT test4; and struct test5; // canonical struct HIDDEN test5; struct DEFAULT test5; llvm-svn: 156016
This commit is contained in:
		
							parent
							
								
									c2d64c428a
								
							
						
					
					
						commit
						cd997e02b2
					
				| 
						 | 
					@ -1757,13 +1757,16 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Decl *PrevDecl;
 | 
					  // Find the last Decl that has an attribute.
 | 
				
			||||||
  if (isa<FunctionDecl>(D))
 | 
					  VisibilityAttr *PrevAttr;
 | 
				
			||||||
    PrevDecl = D->getMostRecentDecl()->getPreviousDecl();
 | 
					  assert(D->redecls_begin() == D);
 | 
				
			||||||
  else
 | 
					  for (Decl::redecl_iterator I = D->redecls_begin(), E = D->redecls_end();
 | 
				
			||||||
    PrevDecl = D->getCanonicalDecl();
 | 
					       I != E; ++I) {
 | 
				
			||||||
 | 
					    PrevAttr = I->getAttr<VisibilityAttr>() ;
 | 
				
			||||||
 | 
					    if (PrevAttr)
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  VisibilityAttr *PrevAttr = PrevDecl ? PrevDecl->getAttr<VisibilityAttr>() : 0;
 | 
					 | 
				
			||||||
  if (PrevAttr) {
 | 
					  if (PrevAttr) {
 | 
				
			||||||
    VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
 | 
					    VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
 | 
				
			||||||
    if (PrevVisibility != type) {
 | 
					    if (PrevVisibility != type) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,3 +10,7 @@ void test3() __attribute__((visibility("protected"))); // expected-warning {{tar
 | 
				
			||||||
struct __attribute__((visibility("hidden"))) test4; // expected-note {{previous attribute is here}}
 | 
					struct __attribute__((visibility("hidden"))) test4; // expected-note {{previous attribute is here}}
 | 
				
			||||||
struct test4;
 | 
					struct test4;
 | 
				
			||||||
struct __attribute__((visibility("default"))) test4; // expected-error {{visibility does not match previous declaration}}
 | 
					struct __attribute__((visibility("default"))) test4; // expected-error {{visibility does not match previous declaration}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct test5;
 | 
				
			||||||
 | 
					struct __attribute__((visibility("hidden"))) test5; // expected-note {{previous attribute is here}}
 | 
				
			||||||
 | 
					struct __attribute__((visibility("default"))) test5; // expected-error {{visibility does not match previous declaration}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue