[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-09-19 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous created this revision.
nomanous added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nomanous requested review of this revision.

The multi-character character constants should be implementation-defined 
according to the C standard but actually were made to be extension, which would 
cause errors when using clang with option "-pedantic-errors". This patch  fixes 
it and it is for bug #46797 on the Bugzilla system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
  clang/test/FixIt/format.m
  clang/test/Lexer/multi-character-character-constant.c
  clang/test/Preprocessor/expr_multichar.c

Index: clang/test/Preprocessor/expr_multichar.c
===
--- clang/test/Preprocessor/expr_multichar.c
+++ clang/test/Preprocessor/expr_multichar.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 < %s -E -verify -triple i686-pc-linux-gnu
-// expected-no-diagnostics
+// Expect the warning of the four-character character constant after changing it from extension to implementation-defined
 
-#if (('1234' >> 24) != '1')
+#if (('1234' >> 24) != '1') // expected-warning {{multi-character character constant}}
 #error Bad multichar constant calculation!
 #endif
Index: clang/test/Lexer/multi-character-character-constant.c
===
--- /dev/null
+++ clang/test/Lexer/multi-character-character-constant.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -161,14 +161,17 @@
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
 
 
-  NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 
-  NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
+  NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%d"
 
-  NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 }
 
 void multichar_constants_false_negative() {
@@ -177,8 +180,9 @@
   // type-checker expects %c to correspond to an integer argument, because
   // many C library functions like fgetc() actually return an int (using -1
   // as a sentinel).
-  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}}
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 }
 
 
Index: clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
===
--- clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
+++ clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
+// Expect the warning of the four-character character constant after changing it from extension to implementation-defined
 
 // Check types of char literals
 extern char a;
 extern __typeof('a') a;
 extern int b;
-extern __typeof('asdf') b;
+extern __typeof('asdf') b; // expected-warning {{multi-character character constant}}
 extern wchar_t c;
 extern __typeof(L'a') c;
 #if __cplusplus >= 201103L
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/c

[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-09-27 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-04 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @chandlerc @majnemer @lvoufo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-06 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D90448#2376710 , @dblaikie wrote:

> How's this compare to the similar checks for variable templates? Is there 
> some code/checking we could share here?

The code of checks for variable templates is just before the additional code. 
But the conditions of if statement and the format of diagnostics are different, 
so it may be better to do the check for static member instantiation separately. 
And I have reused the type comparing function (with an argument different).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303709.
nomanous added a comment.

In this update I delete some extra test code, move several comments and split 
the new type comparing code into a new function to make sure that the commonly 
used old type comparing function not affected by it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,7 +2343,21 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
-  bool hasSameType(const Type *T1, const Type *T2) const {
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  // lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  // the compiler automatically adds Objective C lifetime qualifiers for
+  // static data members. Sometimes, this will make two types not equal while
+  // they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+}
+
+bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
 


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match e

[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303712.
nomanous added a comment.

Some format fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,7 +2343,21 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
-  bool hasSameType(const Type *T1, const Type *T2) const {
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  /// lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  /// the compiler automatically adds Objective C lifetime qualifiers for
+  /// static data members. Sometimes, this will make two types not equal while
+  /// they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+}
+
+bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
 


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: c

[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303749.
nomanous added a comment.

Some more format fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  << Prev;
+  return true;
+}
+
 // FIXME: Create an ExplicitInstantiation node?
 return (Decl*) nullptr;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5056,6 +5056,8 @@
   "of %select{explicit instantiation|explicit specialization|"
   "partial specialization|redeclaration}0 of %1 does not match"
   " expected type %3">;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,6 +2343,20 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  /// lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  /// the compiler automatically adds Objective C lifetime qualifiers for
+  /// static data members. Sometimes, this will make two types not equal while
+  /// they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+  }
+
   bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_

[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-15 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @chandlerc @majnemer @aaron.ballman @dblaikie


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-01 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D87962#2298021 , @aaron.ballman 
wrote:

> Multichar literals are implementation-defined in C and conditionally 
> supported with implementation-defined semantics in C++. I agree that it may 
> make sense to warn about their use for portability reasons, but I'm not 
> certain whether it makes sense to promote their use to be always-on 
> diagnostics. I'm curious to know if this change causes any issues with system 
> headers (which may or may not still define four char codes) or popular 
> libraries.
>
> I was curious as to why this was an extension in the first place and found 
> the original commits 
> (https://github.com/llvm/llvm-project/commit/74c95e20af4838152a63010292d1063835176711
>  and 
> https://github.com/llvm/llvm-project/commit/8577f62622d50183c7413d7507ec783d3c1486fc)
>  but there's no justification as to why this was picked as an extension.

Or should we change the four character case to "Remark" so it wouldn't be 
warned even with the "-pandemic" option? There seems no other choice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-01 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 295559.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
  clang/test/FixIt/format.m
  clang/test/Lexer/char-literal.cpp
  clang/test/Lexer/constants.c
  clang/test/Lexer/multi-character-character-constant.c
  clang/test/Preprocessor/expr_multichar.c

Index: clang/test/Preprocessor/expr_multichar.c
===
--- clang/test/Preprocessor/expr_multichar.c
+++ clang/test/Preprocessor/expr_multichar.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 < %s -E -verify -triple i686-pc-linux-gnu
-// Expect the warning of the four-character character constant after changing it from extension to implementation-defined
+// expected-no-diagnostics
 
-#if (('1234' >> 24) != '1') // expected-warning {{multi-character character constant}}
+#if (('1234' >> 24) != '1')
 #error Bad multichar constant calculation!
 #endif
Index: clang/test/Lexer/multi-character-character-constant.c
===
--- clang/test/Lexer/multi-character-character-constant.c
+++ clang/test/Lexer/multi-character-character-constant.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
 
 int x = 'ab'; // expected-warning {{multi-character character constant}}
-int y = 'abcd'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // no warning.
 
 int main() {
return 0;
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -26,7 +26,7 @@
   '\\
 t',
   '??!',  // expected-warning {{trigraph converted to '|' character}}
-  'abcd'  // expected-warning {{multi-character character constant}}
+  'abcd'
 };
 
 //  PR4499
@@ -36,15 +36,16 @@
 int m3 = '\\\
 ';
 
+// The four-character character constants wouldn't cause warning anymore after we change it to "Remark"
 
 #pragma clang diagnostic ignored "-Wmultichar"
 
 int d = 'df'; // no warning.
-int e = 'abcd';  // still warn: expected-warning {{multi-character character constant}}
+int e = 'abcd';
 
-#pragma clang diagnostic ignored "-Wfour-char-constants"
+// #pragma clang diagnostic ignored "-Wfour-char-constants"
 
-int f = 'abcd';  // ignored.
+int f = 'abcd';
 
 // rdar://problem/6974641
 float t0[] = {
Index: clang/test/Lexer/char-literal.cpp
===
--- clang/test/Lexer/char-literal.cpp
+++ clang/test/Lexer/char-literal.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -Wfour-char-constants -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -Wfour-char-constants -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s
 
 #ifndef __cplusplus
 typedef __WCHAR_TYPE__ wchar_t;
@@ -9,7 +9,7 @@
 
 int a = 'ab'; // expected-warning {{multi-character character constant}}
 int b = '\xFF\xFF'; // expected-warning {{multi-character character constant}}
-int c = 'APPS'; // expected-warning {{multi-character character constant}}
+int c = 'APPS';
 
 char d = '鈱?; // expected-error {{character too large for enclosing character literal type}}
 char e = '\u2318'; // expected-error {{character too large for enclosing character literal type}}
Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -162,16 +162,13 @@
 
 
   NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} \
-  // expected-warning {{multi-character character constant}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
 
   NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}} \
-  // expected-warning {{multi-character character constant}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%d"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
 
   NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}} \
-  // expected-warning {{multi-character character constant}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
 }
 
 void multichar_constants_false_negative() {
@@ -181,8 +178,7 @@
   // many C library functions like fgetc() actually return an int (using -1
   // as a sentinel).
   NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}}

[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-02 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 295766.
nomanous added a comment.

I change the four-char constants back to "Warning" in this revision, but set it 
to be ignored by default.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/test/FixIt/format.m
  clang/test/Lexer/constants.c
  clang/test/Lexer/multi-char-constants.c


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants 
-pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic 
-ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
@@ -26,7 +26,7 @@
   '\\
 t',
   '??!',  // expected-warning {{trigraph converted to '|' character}}
-  'abcd'  // expected-warning {{multi-character character constant}}
+  'abcd' // expected-warning {{multi-character character constant}}
 };
 
 //  PR4499
@@ -36,15 +36,14 @@
 int m3 = '\\\
 ';
 
-
 #pragma clang diagnostic ignored "-Wmultichar"
 
 int d = 'df'; // no warning.
-int e = 'abcd';  // still warn: expected-warning {{multi-character character 
constant}}
+int e = 'abcd'; // still warn: expected-warning {{multi-character character 
constant}}
 
 #pragma clang diagnostic ignored "-Wfour-char-constants"
 
-int f = 'abcd';  // ignored.
+int f = 'abcd'; // ignored.
 
 // rdar://problem/6974641
 float t0[] = {
Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -177,7 +177,7 @@
   // type-checker expects %c to correspond to an integer argument, because
   // many C library functions like fgetc() actually return an int (using -1
   // as a sentinel).
-  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but 
the argument has type 'int'}}
+  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but 
the argument has type 'int'}} \
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
 }
 
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,10 +104,10 @@
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def ext_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
-def ext_four_char_character_literal : Extension<
-  "multi-character character constant">, InGroup;
+def ext_four_char_character_literal : Warning<
+  "multi-character character constant">, InGroup, 
DefaultIgnore;
 
 
 // Unicode and UCNs


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic -ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
@@ -26,7 +26,7 @@
   '\\
 t',
   '??!',  // expected-warning {{trigraph converted to '|' character}}
-  'abcd'  // expected-warning {{multi-character character constant}}
+  'abcd' // expected-warning {{multi-character character constant}}
 };
 
 //  PR4499
@@ -36,15 +36,14 @@
 int m3 = '\\\
 ';
 
-
 #pragma clang diagnostic ignored "-Wmultichar"
 
 int d = 'df'; // no warning.
-int e = 'abcd';  // still warn: expected-warning {{multi-character character constant}}
+int e = 'abcd'; // still warn: expected-warning {{multi-character character constant}}
 
 #pragma clang diagnostic ignored "-Wfour-char-constants"
 
-int f = 'abcd';  // ignored.
+int f = 'abcd'; // ignored.
 
 // rdar://problem/6974641
 float t0[] = {
Index

[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-02 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 295771.
nomanous added a comment.

I restore some needless modification in the previous patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/test/Lexer/constants.c
  clang/test/Lexer/multi-char-constants.c


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants 
-pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic 
-ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,10 +104,10 @@
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def ext_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
-def ext_four_char_character_literal : Extension<
-  "multi-character character constant">, InGroup;
+def ext_four_char_character_literal : Warning<
+  "multi-character character constant">, InGroup, 
DefaultIgnore;
 
 
 // Unicode and UCNs


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic -ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,10 +104,10 @@
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def ext_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
-def ext_four_char_character_literal : Extension<
-  "multi-character character constant">, InGroup;
+def ext_four_char_character_literal : Warning<
+  "multi-character character constant">, InGroup, DefaultIgnore;
 
 
 // Unicode and UCNs
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-05 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 296118.
nomanous added a comment.

In this revision I delete the useless main function in the new test case and 
rename ext_multichar_character_literal & ext_four_char_character_literal to 
warn_multichar_character_literal & warn_four_char_character_literal.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/constants.c
  clang/test/Lexer/multi-char-constants.c


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants 
-pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic 
-ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -1373,9 +1373,9 @@
 if (isWide())
   PP.Diag(Loc, diag::warn_extraneous_char_constant);
 else if (isAscii() && NumCharsSoFar == 4)
-  PP.Diag(Loc, diag::ext_four_char_character_literal);
+  PP.Diag(Loc, diag::warn_four_char_character_literal);
 else if (isAscii())
-  PP.Diag(Loc, diag::ext_multichar_character_literal);
+  PP.Diag(Loc, diag::warn_multichar_character_literal);
 else
   PP.Diag(Loc, diag::err_multichar_utf_character_literal);
 IsMultiChar = true;
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,10 +104,10 @@
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def warn_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
-def ext_four_char_character_literal : Extension<
-  "multi-character character constant">, InGroup;
+def warn_four_char_character_literal : Warning<
+  "multi-character character constant">, InGroup, 
DefaultIgnore;
 
 
 // Unicode and UCNs


Index: clang/test/Lexer/multi-char-constants.c
===
--- /dev/null
+++ clang/test/Lexer/multi-char-constants.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
Index: clang/test/Lexer/constants.c
===
--- clang/test/Lexer/constants.c
+++ clang/test/Lexer/constants.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wfour-char-constants -pedantic -ftrigraphs %s
 
 int x = 00080;  // expected-error {{invalid digit}}
 
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -1373,9 +1373,9 @@
 if (isWide())
   PP.Diag(Loc, diag::warn_extraneous_char_constant);
 else if (isAscii() && NumCharsSoFar == 4)
-  PP.Diag(Loc, diag::ext_four_char_character_literal);
+  PP.Diag(Loc, diag::warn_four_char_character_literal);
 else if (isAscii())
-  PP.Diag(Loc, diag::ext_multichar_character_literal);
+  PP.Diag(Loc, diag::warn_multichar_character_literal);
 else
   PP.Diag(Loc, diag::err_multichar_utf_character_literal);
 IsMultiChar = true;
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,10 +104,10 @@
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def warn_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
-def ext_four_char_character_literal : Extension<
-  "multi-character character constant">, InGroup;
+def warn_four_char_character_literal : Warning<
+  "multi-character character c

[PATCH] D87962: [clang] Change the multi-character character constants from extension to implementation-defined.

2020-10-05 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D87962#2312617 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to commit on your behalf?

Yes I need!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87962/new/

https://reviews.llvm.org/D87962

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-24 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-10-30 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous created this revision.
nomanous added reviewers: rsmith, chandlerc, Eugene.Zelenko, majnemer, lvoufo.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nomanous requested review of this revision.

Add type check for explicit instantiation of template classes' static data 
members. This is a buf fix for #38205.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp

Index: clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+template
+class A
+{
+ static T a; //expected-note {{in instantiation of static data member 'A::a' requested here}}
+};
+
+template
+T A::a;
+
+class B
+{ };
+
+template T c; //expected-note {{variable template 'c' declared here}}
+
+template int c; //expected-error {{type 'int' of explicit instantiation of 'c' does not match expected type 'B'}}
+
+template int A::a; //expected-error {{type 'int' of explicit instantiation of 'A::a' does not match expected type 'B'}}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -9977,6 +9977,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -9998,6 +,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10090,6 +10093,22 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case. Objective C lifetime qualifiers will be
+// automatically added by compiler with option -fobjc-arc so it should be
+// ignored when comparing types.
+if (IsStaticDataMemberInstantiation && TSK==TSK_ExplicitInstantiationDefinition
+&& Prev && !Context.hasSameType(Prev->getType(), R, true)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+<< Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2337,8 +2337,19 @@
   CanQualType getCanonicalParamType(QualType T) const;
 
   /// Determine whether the given types \p T1 and \p T2 are equivalent.
-  bool hasSameType(QualType T1, QualType T2) const {
-return getCanonicalType(T1) == getCanonicalType(T2);
+  /// The lifetime qualifier of Objective C can be chosen to be ignored because
+  /// sometimes we don't want to take this into consideration.
+  bool hasSameType(QualType T1, QualType T2, bool IgnoreObjCLifetimeQual = false) const {
+if (!IgnoreObjCLifetimeQual) {
+  return getCanonicalType(T1) == getCanonicalType(T2);
+}
+else {
+  SplitQualType ST1 = getCanonicalType(T1).split();
+  SplitQualType ST2 = getCanonicalType(T2).split();
+  ST1.Quals.removeObjCLifetime();
+  ST2.Quals.removeObjCLifetime();
+  return ST1 == ST2;
+}
   }
   bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-10-30 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 301872.
nomanous added a comment.

Change some format.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp

Index: clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+template
+class A
+{
+ static T a; //expected-note {{in instantiation of static data member 'A::a' requested here}}
+};
+
+template
+T A::a;
+
+class B
+{ };
+
+template T c; //expected-note {{variable template 'c' declared here}}
+
+template int c; //expected-error {{type 'int' of explicit instantiation of 'c' does not match expected type 'B'}}
+
+template int A::a; //expected-error {{type 'int' of explicit instantiation of 'A::a' does not match expected type 'B'}}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -9977,6 +9977,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -9998,6 +,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10090,6 +10093,23 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case. Objective C lifetime qualifiers will be
+// automatically added by compiler with option -fobjc-arc so it should be
+// ignored when comparing types.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameType(Prev->getType(), R, true)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2337,8 +2337,19 @@
   CanQualType getCanonicalParamType(QualType T) const;
 
   /// Determine whether the given types \p T1 and \p T2 are equivalent.
-  bool hasSameType(QualType T1, QualType T2) const {
-return getCanonicalType(T1) == getCanonicalType(T2);
+  /// The lifetime qualifier of Objective C can be chosen to be ignored because
+  /// sometimes we don't want to take this into consideration.
+  bool hasSameType(QualType T1, QualType T2,
+   bool IgnoreObjCLifetimeQual = false) const {
+if (!IgnoreObjCLifetimeQual) {
+  return getCanonicalType(T1) == getCanonicalType(T2);
+} else {
+  SplitQualType ST1 = getCanonicalType(T1).split();
+  SplitQualType ST2 = getCanonicalType(T2).split();
+  ST1.Quals.removeObjCLifetime();
+  ST2.Quals.removeObjCLifetime();
+  return ST1 == ST2;
+}
   }
   bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-10-30 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Does anyone know why Harbormaster doesn't rebuild this revision after I update 
it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-26 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous marked an inline comment as done.
nomanous added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:10111-10124
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {

rsmith wrote:
> Can we combine this with the previous `if`? This is really checking the same 
> thing that the `hasSameType` check above checked.
It seems difficult to combine this with the previous one.

  # The two `if` blocks are small and both only contain two statements, but the 
two statements contained by the posterior one are all different from statements 
contained by the previous one (they use different diagnostics);
  # The conditions are different. The previous one uses `PrevTemplate` to make 
sure that it's in a variable template declaration and the posterior one uses 
`IsStaticDataMemberInstantiation` to make sure that it's in a static data 
member instantiation of a template class.

So, if we want to combine the two blocks, we must write two sub-`if`-blocks in 
the combined block, which, I think, has no advantage over the current code (if 
not more confusing).









Comment at: clang/lib/Sema/SemaTemplate.cpp:10117
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),

rsmith wrote:
> Please can you point us at an example that needs this "ignore lifetime" 
> nuance? We should check with Apple folks what they want to happen here, and 
> we should presumably have the same rule for all explicit instantiations of 
> templated variables -- both in the static data member case here and the 
> variable template case a few lines above.
> 
> My expectation is that we want one of these two rules:
> 1) the declared lifetime should match exactly between the declaration and the 
> explicit instantiation, or
> 2) there cannot be a declared lifetime on the explicit instantiation, and a 
> lifetime on the template declaration is ignored by the check
> (or a combination of these rules where we accept either option). I don't 
> think that matches what you're doing here -- in particular, I think a wrong 
> declared lifetime on the explicit instantiation should result in an error.
I'll do some test and give you a code snippet to trigger the lifetime mismatch 
when lifetime specifiers are not ignored. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-28 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:10117
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),

nomanous wrote:
> rsmith wrote:
> > Please can you point us at an example that needs this "ignore lifetime" 
> > nuance? We should check with Apple folks what they want to happen here, and 
> > we should presumably have the same rule for all explicit instantiations of 
> > templated variables -- both in the static data member case here and the 
> > variable template case a few lines above.
> > 
> > My expectation is that we want one of these two rules:
> > 1) the declared lifetime should match exactly between the declaration and 
> > the explicit instantiation, or
> > 2) there cannot be a declared lifetime on the explicit instantiation, and a 
> > lifetime on the template declaration is ignored by the check
> > (or a combination of these rules where we accept either option). I don't 
> > think that matches what you're doing here -- in particular, I think a wrong 
> > declared lifetime on the explicit instantiation should result in an error.
> I'll do some test and give you a code snippet to trigger the lifetime 
> mismatch when lifetime specifiers are not ignored. 
With lifetime specifiers not ignored, use command

```
clang -cc1  -fobjc-arc -fblocks -fsyntax-only snippet.mm
```

to compile the obj-c++ file `snippet.mm` whose contents are as follows:

```
typedef void (^fptr)();
template struct StaticMembers {
  static fptr f;
};

template
fptr StaticMembers::f = [] {};

template fptr StaticMembers::f;
```

The compiler will give a type mismatch error, saying that `f`'s definition in 
the template class  has a type `'__strong fptr' (aka 'void (^__strong)()')` 
while its explicit instantiation has a type `'fptr' (aka 'void (^)()')`, though 
they should essentially have the same type.

This problem only happens in explicit instantiation of a static member of block 
type and doesn't affect static members of other types.

@rsmith 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-02-11 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @haowei @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-02-18 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @haowei @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-02-24 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @haowei @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-03-03 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-03-18 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-15 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D90448#2500829 , @lebedev.ri wrote:

> Tests missing

I mistakenly missed that file in the last commit. I'll add it soon.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-17 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D90448#2504022 , @condy wrote:

> The tests failed though

Which? Do you mean the unit test? It seems to be irrelevant with this revision. 
This revision doesn't change the code covered by that test. The failure should 
be caused by other commit on the trunk.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-18 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 317299.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp

Index: clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-explicit-instant-type-mismatch.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+template
+class A
+{
+ static T a; //expected-note {{in instantiation of static data member 'A::a' requested here}}
+};
+
+template
+T A::a;
+
+class B
+{ };
+
+template int A::a; //expected-error {{type 'int' of explicit instantiation of 'A::a' does not match expected type 'B'}}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -9992,6 +9992,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10013,6 +10014,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10105,6 +10108,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  << Prev;
+  return true;
+}
+
 // FIXME: Create an ExplicitInstantiation node?
 return (Decl*) nullptr;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5122,6 +5122,8 @@
   "of %select{explicit instantiation|explicit specialization|"
   "partial specialization|redeclaration}0 of %1 does not match"
   " expected type %3">;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2355,6 +2355,20 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  /// lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  /// the compiler automatically adds Objective C lifetime qualifiers for
+  /// static data members. Sometimes, this will make two types not equal while
+  /// they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+  }
+
   bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-18 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous marked 3 inline comments as done.
nomanous added a comment.

Ping @rsmith @dblaikie @MaskRay @haowei @Xiangling_L @lebedev.ri


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits