[PATCH] D75675: [clang-format] do not insert spaces around inline asm symbolic names
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 05:29:34 PST 2020
krasimir updated this revision to Diff 248449.
krasimir added a comment.
Merging commits into 1 patch
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75675/new/
https://reviews.llvm.org/D75675
Files:
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15127,6 +15127,30 @@
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"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -499,6 +499,8 @@
} 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 &&
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -54,6 +54,7 @@
TYPE(InheritanceComma) \
TYPE(InlineASMBrace) \
TYPE(InlineASMColon) \
+ TYPE(InlineASMSymbolicNameLSquare) \
TYPE(JavaAnnotation) \
TYPE(JsComputedPropertyName) \
TYPE(JsExponentiation) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75675.248449.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200305/2a94706c/attachment.bin>
More information about the cfe-commits
mailing list