[clang] 36c2ab8 - [clang-format] do not insert spaces around inline asm symbolic names
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 05:20:00 PST 2020
Author: Krasimir Georgiev
Date: 2020-03-05T14:17:21+01:00
New Revision: 36c2ab8d04cd9ff2e50cffa1ca6b3de00e4faa81
URL: https://github.com/llvm/llvm-project/commit/36c2ab8d04cd9ff2e50cffa1ca6b3de00e4faa81
DIFF: https://github.com/llvm/llvm-project/commit/36c2ab8d04cd9ff2e50cffa1ca6b3de00e4faa81.diff
LOG: [clang-format] do not insert spaces around inline asm symbolic names
Summary:
Fixes https://bugs.llvm.org/show_bug.cgi?id=45108.
The `[` in such cases was mis-annotated as an `TT_ArrayInitializerLSquare`.
Reviewers: hans
Reviewed By: hans
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75675
Added:
Modified:
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d0d08e470e6c..072e1ad565c2 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -54,6 +54,7 @@ namespace format {
TYPE(InheritanceComma) \
TYPE(InlineASMBrace) \
TYPE(InlineASMColon) \
+ TYPE(InlineASMSymbolicNameLSquare) \
TYPE(JavaAnnotation) \
TYPE(JsComputedPropertyName) \
TYPE(JsExponentiation) \
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index e491de85babd..2673dacfff13 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -499,6 +499,8 @@ class AnnotatingParser {
} else if (Left->is(TT_Unknown)) {
if (StartsObjCMethodExpr) {
Left->Type = TT_ObjCMethodExpr;
+ } else if (InsideInlineASM) {
+ Left->Type = TT_InlineASMSymbolicNameLSquare;
} else if (IsCpp11AttributeSpecifier) {
Left->Type = TT_AttributeSquare;
} else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f00c980cb715..cb052ecaf111 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15127,6 +15127,30 @@ TEST_F(FormatTest, GuessLanguageWithCaret) {
guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
}
+TEST_F(FormatTest, FormatsInlineAsmSymbolicNames) {
+ // ASM symbolic names are identifiers that must be surrounded by [] without
+ // space in between:
+ // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#InputOperands
+
+ // Example from https://bugs.llvm.org/show_bug.cgi?id=45108.
+ verifyFormat(R"(//
+asm volatile("mrs %x[result], FPCR" : [result] "=r"(result));
+)");
+
+ // A list of several ASM symbolic names.
+ verifyFormat(R"(asm("mov %[e], %[d]" : [d] "=rm"(d), [e] "rm"(*e));)");
+
+ // ASM symbolic names in inline ASM with inputs and outputs.
+ verifyFormat(R"(//
+asm("cmoveq %1, %2, %[result]"
+ : [result] "=r"(result)
+ : "r"(test), "r"(new), "[result]"(old));
+)");
+
+ // ASM symbolic names in inline ASM with no outputs.
+ verifyFormat(R"(asm("mov %[e], %[d]" : : [d] "=rm"(d), [e] "rm"(*e));)");
+}
+
TEST_F(FormatTest, GuessedLanguageWithInlineAsmClobbers) {
EXPECT_EQ(FormatStyle::LK_Cpp,
guessLanguage("foo.h", "void f() {\n"
More information about the cfe-commits
mailing list