[PATCH] D57906: [CTU] Do not allow different CPP dialects in CTU

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 7 09:52:30 PST 2019


martong created this revision.
martong added reviewers: xazax.hun, a_sidorin, r.stahl.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a project: clang.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D57906

Files:
  lib/CrossTU/CrossTranslationUnit.cpp


Index: lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- lib/CrossTU/CrossTranslationUnit.cpp
+++ lib/CrossTU/CrossTranslationUnit.cpp
@@ -228,13 +228,34 @@
 
   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++.
+
+  // We do not support CTU across languages (C vs C++).
   if (LangTo.CPlusPlus != LangFrom.CPlusPlus) {
     ++NumLangMismatch;
     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) {
+    ++NumLangMismatch;
+    return llvm::make_error<IndexError>(index_error_code::lang_mismatch);
+  }
+
   TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
   if (const FunctionDecl *ResultDecl =
           findFunctionInDeclContext(TU, LookupFnName))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57906.185802.patch
Type: text/x-patch
Size: 1622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/0d40c772/attachment-0001.bin>


More information about the cfe-commits mailing list