LKML Archive on
help / color / mirror / Atom feed
From: tip-bot for Sandipan Das <>
Subject: [tip:perf/urgent] perf clang: Add support for recent clang versions
Date: Mon, 9 Apr 2018 22:30:47 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Commit-ID:  7854e499f33fd9c7e63288692ffb754d9b1d02fd
Author:     Sandipan Das <>
AuthorDate: Wed, 4 Apr 2018 23:34:18 +0530
Committer:  Arnaldo Carvalho de Melo <>
CommitDate: Mon, 9 Apr 2018 11:13:08 -0300

perf clang: Add support for recent clang versions

The clang API calls used by perf have changed in recent releases and
builds succeed with libclang-3.9 only. This introduces compatibility
with libclang-4.0 and above.

Without this patch, we will see the following compilation errors with

 util/c++/clang.cpp: In function ‘clang::CompilerInvocation* perf::createCompilerInvocation(llvm::opt::ArgStringList, llvm::StringRef&, clang::DiagnosticsEngine&)’:
 util/c++/clang.cpp:62:33: error: ‘IK_C’ was not declared in this scope
   Opts.Inputs.emplace_back(Path, IK_C);
 util/c++/clang.cpp: In function ‘std::unique_ptr<llvm::Module> perf::getModuleFromSource(llvm::opt::ArgStringList, llvm::StringRef, llvm::IntrusiveRefCntPtr<clang::vfs::FileSystem>)’:
 util/c++/clang.cpp:75:26: error: no matching function for call to ‘clang::CompilerInstance::setInvocation(clang::CompilerInvocation*)’
 In file included from util/c++/clang.cpp:14:0:
 /usr/include/clang/Frontend/CompilerInstance.h:231:8: note: candidate: void clang::CompilerInstance::setInvocation(std::shared_ptr<clang::CompilerInvocation>)
    void setInvocation(std::shared_ptr<CompilerInvocation> Value);

Committer testing:

Tested on Fedora 27 after installing the clang-devel and llvm-devel
packages, versions:

  # rpm -qa | egrep llvm\|clang

Make sure you don't have some older version lying around in /usr/local,
etc, then:

  $ make LIBCLANGLLVM=1 -C tools/perf install-bin

And in the end perf will be linked agains these libraries:

  # ldd ~/bin/perf | egrep -i llvm\|clang => /lib64/ (0x00007f8bb2eb4000) => /lib64/ (0x00007f8bb29e3000) => /lib64/ (0x00007f8bb23f7000) => /lib64/ (0x00007f8bb2060000) => /lib64/ (0x00007f8bb1d06000) => /lib64/ (0x00007f8bb1a3e000) => /lib64/ (0x00007f8bb17d4000) => /lib64/ (0x00007f8bb15c5000) => /lib64/ (0x00007f8bb0cc9000) => /lib64/ (0x00007f8bb0a23000) => /lib64/ (0x00007f8bb0725000) => /lib64/ (0x00007f8bb039a000) => /lib64/ (0x00007f8bace98000) => /lib64/../lib64/ (0x00007f8bab735000) => /lib64/../lib64/ (0x00007f8bab4b2000) => /lib64/../lib64/ (0x00007f8bab2a1000) => /lib64/../lib64/ (0x00007f8bab08e000)

Signed-off-by: Sandipan Das <>
Tested-by: Arnaldo Carvalho de Melo <>
Cc: Jiri Olsa <>
Cc: Naveen N. Rao <>
Fixes: 00b86691c77c ("perf clang: Add builtin clang support ant test case")
Signed-off-by: Arnaldo Carvalho de Melo <>
 tools/perf/util/c++/clang.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index 1bfc946e37dc..bf31ceab33bd 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -9,6 +9,7 @@
  * Copyright (C) 2016 Huawei Inc.
+#include "clang/Basic/Version.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -58,7 +59,8 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
 	FrontendOptions& Opts = CI->getFrontendOpts();
-	Opts.Inputs.emplace_back(Path, IK_C);
+	Opts.Inputs.emplace_back(Path,
+			FrontendOptions::getInputKindForExtension("c"));
 	return CI;
@@ -71,10 +73,17 @@ getModuleFromSource(llvm::opt::ArgStringList CFlags,
 	IntrusiveRefCntPtr<CompilerInvocation> CI =
 		createCompilerInvocation(std::move(CFlags), Path,
+	std::shared_ptr<CompilerInvocation> CI(
+		createCompilerInvocation(std::move(CFlags), Path,
+					 Clang.getDiagnostics()));
+	Clang.setInvocation(CI);
 	std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx));
 	if (!Clang.ExecuteAction(*Act))

  reply	other threads:[~2018-04-10  5:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-04 18:04 [PATCH 1/3] perf tools: Fix perf builds with clang support Sandipan Das
2018-04-04 18:04 ` [PATCH 2/3] perf clang: Add support for recent clang versions Sandipan Das
2018-04-10  5:30   ` tip-bot for Sandipan Das [this message]
2018-04-04 18:04 ` [PATCH 3/3] perf tests clang: Fix function name for clang IR test Sandipan Das
2018-04-10  5:31   ` [tip:perf/urgent] " tip-bot for Sandipan Das
2018-04-10  5:30 ` [tip:perf/urgent] perf tools: Fix perf builds with clang support tip-bot for Sandipan Das

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).