[clang] 6b50e87 - [clang] Fix label (de-)serialization in ASM statements.

Viktoriia Bakalova via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 08:54:05 PDT 2023


Author: Viktoriia Bakalova
Date: 2023-05-22T15:53:45Z
New Revision: 6b50e87f21e131fb75d234acaa69b2386e3b6006

URL: https://github.com/llvm/llvm-project/commit/6b50e87f21e131fb75d234acaa69b2386e3b6006
DIFF: https://github.com/llvm/llvm-project/commit/6b50e87f21e131fb75d234acaa69b2386e3b6006.diff

LOG: [clang] Fix label (de-)serialization in ASM statements.

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

Added: 
    clang/test/PCH/asm-label.cpp

Modified: 
    clang/lib/Serialization/ASTReaderStmt.cpp
    clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index a96b1a2fa4f31..c3ccb6744ff61 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -400,8 +400,10 @@ void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
     Clobbers.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
 
   // Labels
-  for (unsigned I = 0, N = NumLabels; I != N; ++I)
+  for (unsigned I = 0, N = NumLabels; I != N; ++I) {
+    Names.push_back(Record.readIdentifier());
     Exprs.push_back(Record.readSubStmt());
+  }
 
   S->setOutputsAndInputsAndClobbers(Record.getContext(),
                                     Names.data(), Constraints.data(),

diff  --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 363f7569acd3e..9739d0b37fba1 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -317,7 +317,10 @@ void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
     Record.AddStmt(S->getClobberStringLiteral(I));
 
   // Labels
-  for (auto *E : S->labels()) Record.AddStmt(E);
+  for (unsigned I = 0, N = S->getNumLabels(); I != N; ++I) {
+    Record.AddIdentifierRef(S->getLabelIdentifier(I));
+    Record.AddStmt(S->getLabelExpr(I));
+  }
 
   Code = serialization::STMT_GCCASM;
 }

diff  --git a/clang/test/PCH/asm-label.cpp b/clang/test/PCH/asm-label.cpp
new file mode 100644
index 0000000000000..dd68c11409ff5
--- /dev/null
+++ b/clang/test/PCH/asm-label.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-pch %s -o %t
+// RUN: %clang_cc1 -include-pch %t %s -verify
+#ifndef HEADER_H
+#define HEADER_H
+template<int = 0> 
+void MyMethod() {
+  void *bar;
+  some_path:
+  asm goto
+      (
+          "mov %w[foo], %w[foo]"
+          : [foo] "=r"(bar)
+          : [foo2] "r"(bar), [foo3] "r"(bar), [foo4] "r"(bar)
+          : 
+          : some_path
+      );
+  }
+#else
+void test() {
+ MyMethod();
+// expected-no-diagnostics
+}
+#endif


        


More information about the cfe-commits mailing list