<div dir="ltr">Thanks for the report, and sorry for the breakage.<div><br></div><div>Here's the fix: <a href="https://reviews.llvm.org/D43590">https://reviews.llvm.org/D43590</a></div><div><br></div><div>Ben</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 21, 2018 at 1:47 PM <<a href="mailto:douglas.yung@sony.com">douglas.yung@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ben,<br>
<br>
Your change is causing a test failure on one of the bots, can you take a look?<br>
<br>
<a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/25515" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/25515</a><br>
<br>
FAIL: Clang Tools :: clang-apply-replacements/format.cpp (12526 of 38114)<br>
******************** TEST 'Clang Tools :: clang-apply-replacements/format.cpp' FAILED ********************<br>
Script:<br>
--<br>
mkdir -p /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format<br>
grep -Ev "// *[A-Z-]+:" /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/yes.cpp > /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/yes.cpp<br>
grep -Ev "// *[A-Z-]+:" /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/no.cpp > /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/no.cpp<br>
sed "s#\$(path)#/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format#" /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/yes.yaml > /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/yes.yaml<br>
sed "s#\$(path)#/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format#" /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/no.yaml > /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/no.yaml<br>
clang-apply-replacements -format /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format<br>
FileCheck --strict-whitespace -input-file=/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/yes.cpp /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/yes.cpp<br>
FileCheck --strict-whitespace -input-file=/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format/no.cpp /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/tools/extra/test/clang-apply-replacements/Inputs/format/no.cpp<br>
--<br>
Exit Code: 134<br>
<br>
Command Output (stderr):<br>
--<br>
clang-apply-replacements: /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/lib/Basic/SourceManager.cpp:393: const clang::SrcMgr::ContentCache *clang::SourceManager::getOrCreateContentCache(const clang::FileEntry *, bool): Assertion `FileEnt && "Didn't specify a file entry to use?"' failed.<br>
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/format.cpp.script: line 8: 49680 Aborted (core dumped) clang-apply-replacements -format /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/format<br>
<br>
--<br>
<br>
********************<br>
<br>
Douglas Yung<br>
<br>
<br>
> -----Original Message-----<br>
> From: cfe-commits [mailto:<a href="mailto:cfe-commits-bounces@lists.llvm.org" target="_blank">cfe-commits-bounces@lists.llvm.org</a>] On Behalf Of Ben<br>
> Hamilton via cfe-commits<br>
> Sent: Wednesday, February 21, 2018 7:55<br>
> To: <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
> Subject: r325691 - [clang-format] New API guessLanguage()<br>
><br>
> Author: benhamilton<br>
> Date: Wed Feb 21 07:54:31 2018<br>
> New Revision: 325691<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=325691&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=325691&view=rev</a><br>
> Log:<br>
> [clang-format] New API guessLanguage()<br>
><br>
> Summary:<br>
> For clients which don't have a filesystem, calling getStyle() doesn't make<br>
> much sense (there's no .clang-format files to search for).<br>
><br>
> In this diff, I hoist out the language-guessing logic from getStyle() and move<br>
> it into a new API guessLanguage().<br>
><br>
> I also added support for guessing the language of files which have no<br>
> extension (they could be C++ or ObjC).<br>
><br>
> Test Plan: New tests added. Ran tests with:<br>
> % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests<br>
><br>
> Reviewers: jolesiak, krasimir<br>
><br>
> Reviewed By: jolesiak, krasimir<br>
><br>
> Subscribers: klimek, cfe-commits, sammccall<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D43522" rel="noreferrer" target="_blank">https://reviews.llvm.org/D43522</a><br>
><br>
> Modified:<br>
> cfe/trunk/include/clang/Format/Format.h<br>
> cfe/trunk/lib/Format/Format.cpp<br>
> cfe/trunk/unittests/Format/FormatTest.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Format/Format.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/include/clang/Format/Format.h?rev=325691&r1=325690&r2=325691<br>
> &view=diff<br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Format/Format.h (original)<br>
> +++ cfe/trunk/include/clang/Format/Format.h Wed Feb 21 07:54:31 2018<br>
> @@ -1981,6 +1981,10 @@ llvm::Expected<FormatStyle> getStyle(Str<br>
> StringRef Code = "",<br>
> vfs::FileSystem *FS = nullptr);<br>
><br>
> +// \brief Guesses the language from the ``FileName`` and ``Code`` to be<br>
> formatted.<br>
> +// Defaults to FormatStyle::LK_Cpp.<br>
> +FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef<br>
> +Code);<br>
> +<br>
> // \brief Returns a string representation of ``Language``.<br>
> inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {<br>
> switch (Language) {<br>
><br>
> Modified: cfe/trunk/lib/Format/Format.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/lib/Format/Format.cpp?rev=325691&r1=325690&r2=325691&view=di<br>
> ff<br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Format/Format.cpp (original)<br>
> +++ cfe/trunk/lib/Format/Format.cpp Wed Feb 21 07:54:31 2018<br>
> @@ -2294,6 +2294,25 @@ static FormatStyle::LanguageKind getLang<br>
> return FormatStyle::LK_Cpp;<br>
> }<br>
><br>
> +FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef<br>
> +Code) {<br>
> + FormatStyle::LanguageKind result = getLanguageByFileName(FileName);<br>
> + if (result == FormatStyle::LK_Cpp) {<br>
> + auto extension = llvm::sys::path::extension(FileName);<br>
> + // If there's no file extension (or it's .h), we need to check the<br>
> contents<br>
> + // of the code to see if it contains Objective-C.<br>
> + if (extension.empty() || extension == ".h") {<br>
> + std::unique_ptr<Environment> Env =<br>
> + Environment::CreateVirtualEnvironment(Code, FileName,<br>
> /*Ranges=*/{});<br>
> + ObjCHeaderStyleGuesser Guesser(*Env, getLLVMStyle());<br>
> + Guesser.process();<br>
> + if (Guesser.isObjC()) {<br>
> + result = FormatStyle::LK_ObjC;<br>
> + }<br>
> + }<br>
> + }<br>
> + return result;<br>
> +}<br>
> +<br>
> llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,<br>
> StringRef FallbackStyleName,<br>
> StringRef Code, vfs::FileSystem *FS) {<br>
> @@ -2301,17 +2320,7 @@ llvm::Expected<FormatStyle> getStyle(Str<br>
> FS = vfs::getRealFileSystem().get();<br>
> }<br>
> FormatStyle Style = getLLVMStyle();<br>
> - Style.Language = getLanguageByFileName(FileName);<br>
> -<br>
> - if (Style.Language == FormatStyle::LK_Cpp && FileName.endswith(".h")) {<br>
> - std::unique_ptr<Environment> Env =<br>
> - Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{});<br>
> - ObjCHeaderStyleGuesser Guesser(*Env, Style);<br>
> - Guesser.process();<br>
> - if (Guesser.isObjC()) {<br>
> - Style.Language = FormatStyle::LK_ObjC;<br>
> - }<br>
> - }<br>
> + Style.Language = guessLanguage(FileName, Code);<br>
><br>
> FormatStyle FallbackStyle = getNoStyle();<br>
> if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle))<br>
><br>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=325691&r1=325690&r2=3256<br>
> 91&view=diff<br>
> ==============================================================================<br>
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb 21 07:54:31 2018<br>
> @@ -11952,6 +11952,34 @@ TEST_F(FormatTest, StructuredBindings) {<br>
> verifyFormat("auto const &[ a, b ] = f();", Spaces); }<br>
><br>
> +struct GuessLanguageTestCase {<br>
> + const char *const FileName;<br>
> + const char *const Code;<br>
> + const FormatStyle::LanguageKind ExpectedResult; };<br>
> +<br>
> +class GuessLanguageTest<br>
> + : public FormatTest,<br>
> + public ::testing::WithParamInterface<GuessLanguageTestCase> {};<br>
> +<br>
> +TEST_P(GuessLanguageTest, FileAndCode) {<br>
> + auto TestCase = GetParam();<br>
> + EXPECT_EQ(TestCase.ExpectedResult,<br>
> + guessLanguage(TestCase.FileName, TestCase.Code)); }<br>
> +<br>
> +static const GuessLanguageTestCase TestCases[] = {<br>
> + {"foo.cc", "", FormatStyle::LK_Cpp},<br>
> + {"foo.m", "", FormatStyle::LK_ObjC},<br>
> + {"<a href="http://foo.mm" rel="noreferrer" target="_blank">foo.mm</a>", "", FormatStyle::LK_ObjC},<br>
> + {"foo.h", "", FormatStyle::LK_Cpp},<br>
> + {"foo.h", "@interface Foo\n@end\n", FormatStyle::LK_ObjC},<br>
> + {"foo", "", FormatStyle::LK_Cpp},<br>
> + {"foo", "@interface Foo\n@end\n", FormatStyle::LK_ObjC}, };<br>
> +INSTANTIATE_TEST_CASE_P(ValidLanguages, GuessLanguageTest,<br>
> + ::testing::ValuesIn(TestCases));<br>
> +<br>
> } // end namespace<br>
> } // end namespace format<br>
> } // end namespace clang<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>