martong updated this revision to Diff 185926. martong marked 4 inline comments as done. martong added a comment.
- Revert comment change - Add lang_dialect_mismatch and stats for that Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D57906/new/ https://reviews.llvm.org/D57906 Files: include/clang/CrossTU/CrossTranslationUnit.h lib/CrossTU/CrossTranslationUnit.cpp Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -42,6 +42,7 @@ "requested function's body"); STATISTIC(NumTripleMismatch, "The # of triple mismatches"); STATISTIC(NumLangMismatch, "The # of language mismatches"); +STATISTIC(NumLangDialectMismatch, "The # of language dialect mismatches"); // Same as Triple's equality operator, but we check a field only if that is // known in both instances. @@ -99,6 +100,8 @@ return "Triple mismatch"; case index_error_code::lang_mismatch: return "Language mismatch"; + case index_error_code::lang_dialect_mismatch: + return "Language dialect mismatch"; } llvm_unreachable("Unrecognized index_error_code."); } @@ -228,6 +231,7 @@ const auto &LangTo = Context.getLangOpts(); const auto &LangFrom = Unit->getASTContext().getLangOpts(); + // FIXME: Currenty we do not support CTU across C++ and C and across // different dialects of C++. if (LangTo.CPlusPlus != LangFrom.CPlusPlus) { @@ -235,6 +239,28 @@ return llvm::make_error<IndexError>(index_error_code::lang_mismatch); } + // If CPP dialects are different then return with error. + // + // Consider this STL code: + // template<typename _Alloc> + // struct __alloc_traits + // #if __cplusplus >= 201103L + // : std::allocator_traits<_Alloc> + // #endif + // { // ... + // }; + // This class template would create ODR errors during merging the two units, + // since in one translation unit the class template has a base class, however + // in the other unit it has none. + if (LangTo.CPlusPlus11 != LangFrom.CPlusPlus11 || + LangTo.CPlusPlus14 != LangFrom.CPlusPlus14 || + LangTo.CPlusPlus17 != LangFrom.CPlusPlus17 || + LangTo.CPlusPlus2a != LangFrom.CPlusPlus2a) { + ++NumLangDialectMismatch; + return llvm::make_error<IndexError>( + index_error_code::lang_dialect_mismatch); + } + TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); if (const FunctionDecl *ResultDecl = findFunctionInDeclContext(TU, LookupFnName)) Index: include/clang/CrossTU/CrossTranslationUnit.h =================================================================== --- include/clang/CrossTU/CrossTranslationUnit.h +++ include/clang/CrossTU/CrossTranslationUnit.h @@ -43,7 +43,8 @@ failed_to_get_external_ast, failed_to_generate_usr, triple_mismatch, - lang_mismatch + lang_mismatch, + lang_dialect_mismatch }; class IndexError : public llvm::ErrorInfo<IndexError> {
Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -42,6 +42,7 @@ "requested function's body"); STATISTIC(NumTripleMismatch, "The # of triple mismatches"); STATISTIC(NumLangMismatch, "The # of language mismatches"); +STATISTIC(NumLangDialectMismatch, "The # of language dialect mismatches"); // Same as Triple's equality operator, but we check a field only if that is // known in both instances. @@ -99,6 +100,8 @@ return "Triple mismatch"; case index_error_code::lang_mismatch: return "Language mismatch"; + case index_error_code::lang_dialect_mismatch: + return "Language dialect mismatch"; } llvm_unreachable("Unrecognized index_error_code."); } @@ -228,6 +231,7 @@ const auto &LangTo = Context.getLangOpts(); const auto &LangFrom = Unit->getASTContext().getLangOpts(); + // FIXME: Currenty we do not support CTU across C++ and C and across // different dialects of C++. if (LangTo.CPlusPlus != LangFrom.CPlusPlus) { @@ -235,6 +239,28 @@ return llvm::make_error<IndexError>(index_error_code::lang_mismatch); } + // If CPP dialects are different then return with error. + // + // Consider this STL code: + // template<typename _Alloc> + // struct __alloc_traits + // #if __cplusplus >= 201103L + // : std::allocator_traits<_Alloc> + // #endif + // { // ... + // }; + // This class template would create ODR errors during merging the two units, + // since in one translation unit the class template has a base class, however + // in the other unit it has none. + if (LangTo.CPlusPlus11 != LangFrom.CPlusPlus11 || + LangTo.CPlusPlus14 != LangFrom.CPlusPlus14 || + LangTo.CPlusPlus17 != LangFrom.CPlusPlus17 || + LangTo.CPlusPlus2a != LangFrom.CPlusPlus2a) { + ++NumLangDialectMismatch; + return llvm::make_error<IndexError>( + index_error_code::lang_dialect_mismatch); + } + TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); if (const FunctionDecl *ResultDecl = findFunctionInDeclContext(TU, LookupFnName)) Index: include/clang/CrossTU/CrossTranslationUnit.h =================================================================== --- include/clang/CrossTU/CrossTranslationUnit.h +++ include/clang/CrossTU/CrossTranslationUnit.h @@ -43,7 +43,8 @@ failed_to_get_external_ast, failed_to_generate_usr, triple_mismatch, - lang_mismatch + lang_mismatch, + lang_dialect_mismatch }; class IndexError : public llvm::ErrorInfo<IndexError> {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits