Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "FindBadConstructsConsumer.h" | 5 #include "FindBadConstructsConsumer.h" |
| 6 | 6 |
| 7 #include "clang/Frontend/CompilerInstance.h" | 7 #include "clang/Frontend/CompilerInstance.h" |
| 8 #include "clang/AST/Attr.h" | 8 #include "clang/AST/Attr.h" |
| 9 #include "clang/Lex/Lexer.h" | 9 #include "clang/Lex/Lexer.h" |
| 10 #include "clang/Sema/Sema.h" | 10 #include "clang/Sema/Sema.h" |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 if (!record_decl->hasDefinition() || record_decl->hasTrivialDestructor()) | 643 if (!record_decl->hasDefinition() || record_decl->hasTrivialDestructor()) |
| 644 (*trivial_member)++; | 644 (*trivial_member)++; |
| 645 else | 645 else |
| 646 (*non_trivial_member)++; | 646 (*non_trivial_member)++; |
| 647 break; | 647 break; |
| 648 } | 648 } |
| 649 case Type::TemplateSpecialization: { | 649 case Type::TemplateSpecialization: { |
| 650 TemplateName name = | 650 TemplateName name = |
| 651 dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); | 651 dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); |
| 652 bool whitelisted_template = false; | 652 bool whitelisted_template = false; |
| 653 bool trivial_template = false; | |
| 653 | 654 |
| 654 // HACK: I'm at a loss about how to get the syntax checker to get | 655 // HACK: I'm at a loss about how to get the syntax checker to get |
| 655 // whether a template is externed or not. For the first pass here, | 656 // whether a template is externed or not. For the first pass here, |
| 656 // just do simple string comparisons. | 657 // just do simple string comparisons. |
| 657 // | 658 // |
| 658 // The check for "atomic_int" is a quick hack; The real fix will be to | 659 // The check for "atomic_int" is a quick hack; The real fix will be to |
| 659 // check the class after template instantiation. TODO(dcheng): Do the real | 660 // check the class after template instantiation. TODO(dcheng): Do the real |
| 660 // fix. https://bugs.chromium.org/p/chromium/issues/detail?id=663463 | 661 // fix. https://bugs.chromium.org/p/chromium/issues/detail?id=663463 |
| 661 if (TemplateDecl* decl = name.getAsTemplateDecl()) { | 662 if (TemplateDecl* decl = name.getAsTemplateDecl()) { |
| 662 std::string base_name = decl->getNameAsString(); | 663 std::string base_name = decl->getNameAsString(); |
| 663 if (base_name == "basic_string" || base_name == "atomic_int") | 664 if (base_name == "basic_string") |
| 664 whitelisted_template = true; | 665 whitelisted_template = true; |
| 666 else if (base_name == "__atomic_int" || base_name == "atomic_int" || | |
| 667 base_name == "__atomic_base") { | |
|
dcheng
2016/11/09 06:33:45
I'm wondering if we should just intercept this in
hans
2016/11/09 16:48:00
(Actually, the standard says atomic_int is either
palmer
2016/11/10 00:25:22
Done (and that resulted in a smaller diff, which i
| |
| 668 trivial_template = true; | |
| 669 } | |
| 665 } | 670 } |
| 666 | 671 |
| 667 if (whitelisted_template) | 672 if (trivial_template) |
| 673 (*trivial_member)++; | |
| 674 else if (whitelisted_template) | |
| 668 (*non_trivial_member)++; | 675 (*non_trivial_member)++; |
| 669 else | 676 else |
| 670 (*templated_non_trivial_member)++; | 677 (*templated_non_trivial_member)++; |
| 671 break; | 678 break; |
| 672 } | 679 } |
| 673 case Type::Elaborated: { | 680 case Type::Elaborated: { |
| 674 CountType(dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(), | 681 CountType(dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(), |
| 675 trivial_member, | 682 trivial_member, |
| 676 non_trivial_member, | 683 non_trivial_member, |
| 677 templated_non_trivial_member); | 684 templated_non_trivial_member); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 } | 1025 } |
| 1019 } else if (non_reference_type->isPointerType()) { | 1026 } else if (non_reference_type->isPointerType()) { |
| 1020 non_reference_type = non_reference_type->getPointeeType(); | 1027 non_reference_type = non_reference_type->getPointeeType(); |
| 1021 continue; | 1028 continue; |
| 1022 } | 1029 } |
| 1023 break; | 1030 break; |
| 1024 } | 1031 } |
| 1025 } | 1032 } |
| 1026 | 1033 |
| 1027 } // namespace chrome_checker | 1034 } // namespace chrome_checker |
| OLD | NEW |