r347870 - inhereit LLVM_ENABLE_LIBXML2

2018-11-29 Thread David Callahan via cfe-commits
Author: david2050
Date: Thu Nov 29 06:57:14 2018
New Revision: 347870

URL: http://llvm.org/viewvc/llvm-project?rev=347870&view=rev
Log:
inhereit LLVM_ENABLE_LIBXML2

Summary: When building in an LLVM context, we should respect its 
LLVM_ENABLE_LIBXML2 option.

Reviewers: vitalybuka, mspertus, modocache

Reviewed By: modocache

Subscribers: mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D53212

Modified:
cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=347870&r1=347869&r2=347870&view=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Thu Nov 29 06:57:14 2018
@@ -103,6 +103,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
   option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
 "Set to ON to force using an old, unsupported host toolchain." OFF)
   option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
+  option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
 
   include(AddLLVM)
   include(TableGen)
@@ -198,13 +199,15 @@ endif()
 # we can include cmake files from this directory.
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
-# Don't look for libxml if we're using MSan, since uninstrumented third party
-# code may call MSan interceptors like strlen, leading to false positives.
-if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
-  set (LIBXML2_FOUND 0)
-  find_package(LibXml2 2.5.3 QUIET)
-  if (LIBXML2_FOUND)
-set(CLANG_HAVE_LIBXML 1)
+if(LLVM_ENABLE_LIBXML2)
+  # Don't look for libxml if we're using MSan, since uninstrumented third party
+  # code may call MSan interceptors like strlen, leading to false positives.
+  if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
+set (LIBXML2_FOUND 0)
+find_package(LibXml2 2.5.3 QUIET)
+if (LIBXML2_FOUND)
+  set(CLANG_HAVE_LIBXML 1)
+endif()
   endif()
 endif()
 


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


r293004 - Use filename in linemarker when compiling preprocessed source

2017-01-24 Thread David Callahan via cfe-commits
Author: david2050
Date: Tue Jan 24 19:55:28 2017
New Revision: 293004

URL: http://llvm.org/viewvc/llvm-project?rev=293004&view=rev
Log:
Use filename in linemarker when compiling preprocessed source

Summary:
Clang appears to always use name as specified on the command
line, whereas gcc uses the name as specified in the linemarker at the
first line when compiling a preprocessed source. This results mismatch
between two compilers in FILE symbol table entry. This patch makes clang
to resemble gcc's behavior in finding the original source file name and
use it as an input file name.

Even with this patch, values of FILE symbol table entry may still be
different because clang uses dirname+basename for the entry whlie gcc
uses basename only. I'll write a patch for that once this patch is
committed.

Reviewers: dblaikie, inglorion

Reviewed By: inglorion

Subscribers: inglorion, aprantl, bruno

Differential Revision: https://reviews.llvm.org/D28796

Added:
cfe/trunk/test/Frontend/preprocessed-input.c
Modified:
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/Frontend/FrontendAction.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=293004&r1=293003&r2=293004&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Tue Jan 24 19:55:28 2017
@@ -81,7 +81,7 @@ enum InputKind {
   IK_LLVM_IR
 };
 
-  
+
 /// \brief An input file for the front end.
 class FrontendInputFile {
   /// \brief The file name, or "-" to read from standard input.
@@ -109,6 +109,13 @@ public:
   bool isEmpty() const { return File.empty() && Buffer == nullptr; }
   bool isFile() const { return !isBuffer(); }
   bool isBuffer() const { return Buffer != nullptr; }
+  bool isPreprocessed() const {
+return Kind == IK_PreprocessedC ||
+   Kind == IK_PreprocessedCXX ||
+   Kind == IK_PreprocessedObjC ||
+   Kind == IK_PreprocessedObjCXX ||
+   Kind == IK_PreprocessedCuda;
+  }
 
   StringRef getFile() const {
 assert(isFile());

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=293004&r1=293003&r2=293004&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Tue Jan 24 19:55:28 2017
@@ -19,6 +19,7 @@
 #include "clang/Frontend/MultiplexConsumer.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Parse/ParseAST.h"
@@ -187,6 +188,42 @@ FrontendAction::CreateWrappedASTConsumer
   return llvm::make_unique(std::move(Consumers));
 }
 
+// For preprocessed files, if the first line is the linemarker and specifies
+// the original source file name, use that name as the input file name.
+static bool ReadOriginalFileName(CompilerInstance &CI, std::string &InputFile)
+{
+  bool Invalid = false;
+  auto &SourceMgr = CI.getSourceManager();
+  auto MainFileID = SourceMgr.getMainFileID();
+  const auto *MainFileBuf = SourceMgr.getBuffer(MainFileID, &Invalid);
+  if (Invalid)
+return false;
+
+  std::unique_ptr RawLexer(
+  new Lexer(MainFileID, MainFileBuf, SourceMgr, CI.getLangOpts()));
+
+  // If the first line has the syntax of
+  //
+  // # NUM "FILENAME"
+  //
+  // we use FILENAME as the input file name.
+  Token T;
+  if (RawLexer->LexFromRawLexer(T) || T.getKind() != tok::hash)
+return false;
+  if (RawLexer->LexFromRawLexer(T) || T.isAtStartOfLine() ||
+  T.getKind() != tok::numeric_constant)
+return false;
+  RawLexer->LexFromRawLexer(T);
+  if (T.isAtStartOfLine() || T.getKind() != tok::string_literal)
+return false;
+
+  StringLiteralParser Literal(T, CI.getPreprocessor());
+  if (Literal.hadError)
+return false;
+  InputFile = Literal.GetString().str();
+  return true;
+}
+
 bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
  const FrontendInputFile &Input) {
   assert(!Instance && "Already processing a source file!");
@@ -335,6 +372,13 @@ bool FrontendAction::BeginSourceFile(Com
 if (!isModelParsingAction())
   CI.createASTContext();
 
+// For preprocessed files, check if the first line specifies the original
+// source file name with a linemarker.
+std::string OrigFile;
+if (Input.isPreprocessed())
+  if (ReadOriginalFileName(CI, OrigFile))
+InputFile = OrigFile;
+
 std::unique_ptr Consumer =
 CreateWrappedASTConsumer(CI, InputFile);
 if (!Consumer)
@@ -421,9 +465,9 @@ bool FrontendAction::BeginSourceFile(Com
 
   // If ther