]> granicus.if.org Git - clang/commitdiff
Eliminate an embarrassing performance regression in C/ObjC, where we
authorDouglas Gregor <dgregor@apple.com>
Mon, 11 Jan 2010 23:29:10 +0000 (23:29 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 11 Jan 2010 23:29:10 +0000 (23:29 +0000)
were performing name lookup for template names in C/ObjC and always
finding nothing. Turn off such lookup unless we're in C++ mode, along
with the check that determines whether the given identifier is a
"current class name", and assert that we don't make this mistake
again.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplate.cpp

index 3efa6f0180c3182bde36b1c09cfaa8fa3975749b..dc6f7cf458653c0eff5ad615ddc5f9298e1cee9d 100644 (file)
@@ -1153,6 +1153,13 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
     IdentifierInfo *Id = Tok.getIdentifierInfo();
     SourceLocation IdLoc = ConsumeToken();
 
+    if (!getLang().CPlusPlus) {
+      // If we're not in C++, only identifiers matter. Record the
+      // identifier and return.
+      Result.setIdentifier(Id, IdLoc);
+      return false;
+    }
+
     if (AllowConstructorName && 
         Actions.isCurrentClassName(*Id, CurScope, &SS)) {
       // We have parsed a constructor name.
@@ -1207,7 +1214,8 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
     return false;
   }
   
-  if ((AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) {
+  if (getLang().CPlusPlus && 
+      (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) {
     // C++ [expr.unary.op]p10:
     //   There is an ambiguity in the unary-expression ~X(), where X is a 
     //   class-name. The ambiguity is resolved in favor of treating ~ as a 
index fd2abf88cdc6f53ffa441cedde8b8e10ae1b6d61..e10013e3a540b6584366fbc7a2ab1dc4fddb4cc4 100644 (file)
@@ -424,6 +424,8 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
 /// the innermost class.
 bool Sema::isCurrentClassName(const IdentifierInfo &II, Scope *,
                               const CXXScopeSpec *SS) {
+  assert(getLangOptions().CPlusPlus && "No class names in C!");
+
   CXXRecordDecl *CurDecl;
   if (SS && SS->isSet() && !SS->isInvalid()) {
     DeclContext *DC = computeDeclContext(*SS, true);
index 5ca8bfde80fe905125fc9abc54f9cfd42dba0342..c4da5a7f09ebc0c2dbad8305688ff330ba55f9a8 100644 (file)
@@ -80,6 +80,8 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
                                       TypeTy *ObjectTypePtr,
                                       bool EnteringContext,
                                       TemplateTy &TemplateResult) {
+  assert(getLangOptions().CPlusPlus && "No template names in C!");
+
   DeclarationName TName;
   
   switch (Name.getKind()) {