From 5ef404f08b42c58fd8d4c93d1672ab28f61befa6 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 5 Dec 2007 18:16:33 +0000 Subject: [PATCH] Patch to prevent crash on use of objc2 syntax. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44617 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaExpr.cpp | 2 ++ include/clang/Basic/DiagnosticKinds.def | 2 ++ test/Parser/check-objc2-syntax-1.m | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100644 test/Parser/check-objc2-syntax-1.m diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index b08695ff76..ed71934621 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -106,6 +106,8 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc, } if (isa(D)) return Diag(Loc, diag::err_unexpected_typedef, II.getName()); + if (isa(D)) + return Diag(Loc, diag::err_unexpected_interface, II.getName()); assert(0 && "Invalid decl"); abort(); diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index f99239c1e0..043dcd4f34 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -392,6 +392,8 @@ DIAG(err_matching, ERROR, "to match this '%0'") /// Objective-C parser diagnostics +DIAG(err_unexpected_interface, ERROR, + "unexpected interface name '%0': expected expression") DIAG(err_objc_no_attributes_on_category, ERROR, "attributes may not be specified on a category") DIAG(err_objc_missing_end, ERROR, diff --git a/test/Parser/check-objc2-syntax-1.m b/test/Parser/check-objc2-syntax-1.m new file mode 100644 index 0000000000..b0b0e8a35e --- /dev/null +++ b/test/Parser/check-objc2-syntax-1.m @@ -0,0 +1,10 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Subclass ++ (int)magicNumber; +@end + +int main (void) { + return Subclass.magicNumber; // expected-error {{unexpected interface name 'Subclass': expected expression}} +} + -- 2.50.1