bruno created this revision. bruno added reviewers: rsmith, arphaman. Herald added subscribers: cfe-commits, ributzka, dexonsmith, jkorous. Herald added a project: clang.
Otherwise the definition (first found) for ObjCInterfaceDecl's might precede the module one, which will eventually lead to crash, since diagnoseMissingImport needs one coming from a module. This behavior changed after Richard's r342018, which started to look into the definition of ObjCInterfaceDecls. rdar://problem/49237144 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D66982 Files: clang/lib/Sema/SemaLookup.cpp clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h clang/test/Modules/interface-diagnose-missing-import.m Index: clang/test/Modules/interface-diagnose-missing-import.m =================================================================== --- /dev/null +++ clang/test/Modules/interface-diagnose-missing-import.m @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify +@interface Buggy +@end + +@import Foo.Bar; + +@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}} +@end + +// expected-note@Foo/RandoPriv.h:3{{previous definition is here}} Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h @@ -0,0 +1,4 @@ +@interface NSObject +@end +@interface Buggy : NSObject +@end Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap +framework module Foo { + umbrella header "Foo.h" + export * + module * { export * } +} Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h @@ -0,0 +1,2 @@ +#import <Foo/RandoPriv.h> +#import <Foo/Bar.h> Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h @@ -0,0 +1 @@ +// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h Index: clang/lib/Sema/SemaLookup.cpp =================================================================== --- clang/lib/Sema/SemaLookup.cpp +++ clang/lib/Sema/SemaLookup.cpp @@ -5256,8 +5256,11 @@ return FD->getDefinition(); if (TagDecl *TD = dyn_cast<TagDecl>(D)) return TD->getDefinition(); + // The first definition for this ObjCInterfaceDecl might be in the TU + // and not associated with any module. Use the one we know to be complete + // and have just seen in a module. if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) - return ID->getDefinition(); + return ID; if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) return PD->getDefinition(); if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
Index: clang/test/Modules/interface-diagnose-missing-import.m =================================================================== --- /dev/null +++ clang/test/Modules/interface-diagnose-missing-import.m @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify +@interface Buggy +@end + +@import Foo.Bar; + +@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}} +@end + +// expected-note@Foo/RandoPriv.h:3{{previous definition is here}} Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h @@ -0,0 +1,4 @@ +@interface NSObject +@end +@interface Buggy : NSObject +@end Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap +framework module Foo { + umbrella header "Foo.h" + export * + module * { export * } +} Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h @@ -0,0 +1,2 @@ +#import <Foo/RandoPriv.h> +#import <Foo/Bar.h> Index: clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h @@ -0,0 +1 @@ +// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h Index: clang/lib/Sema/SemaLookup.cpp =================================================================== --- clang/lib/Sema/SemaLookup.cpp +++ clang/lib/Sema/SemaLookup.cpp @@ -5256,8 +5256,11 @@ return FD->getDefinition(); if (TagDecl *TD = dyn_cast<TagDecl>(D)) return TD->getDefinition(); + // The first definition for this ObjCInterfaceDecl might be in the TU + // and not associated with any module. Use the one we know to be complete + // and have just seen in a module. if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) - return ID->getDefinition(); + return ID; if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) return PD->getDefinition(); if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits