[PATCH] D80944: Add begin source location for the attributed statement created from PragmaLoopHint decorated loop
Yuanfang Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 5 16:48:33 PDT 2020
ychen updated this revision to Diff 268958.
ychen added a comment.
- Address feedback
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80944/new/
https://reviews.llvm.org/D80944
Files:
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/test/AST/sourceranges.cpp
Index: clang/test/AST/sourceranges.cpp
===================================================================
--- clang/test/AST/sourceranges.cpp
+++ clang/test/AST/sourceranges.cpp
@@ -108,6 +108,33 @@
}
}
+// CHECK: NamespaceDecl {{.*}} attributed_stmt
+namespace attributed_stmt {
+ #define DO_PRAGMA(x) _Pragma (#x)
+
+ void f() {
+ // CHECK: AttributedStmt {{.*}} <line:[[@LINE-3]]:24, line:[[@LINE+2]]:33>
+ DO_PRAGMA (unroll(2))
+ for (int i = 0; i < 10; ++i);
+
+ // CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+3]]:33>
+ // CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:13, col:22>
+ #pragma unroll(2)
+ for (int i = 0; i < 10; ++i);
+
+ // CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+5]]:33>
+ // CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:19, col:41>
+ #pragma clang loop vectorize(enable)
+ // CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:19, col:42>
+ #pragma clang loop interleave(enable)
+ for (int i = 0; i < 10; ++i);
+
+ // CHECK: AttributedStmt {{.*}} <line:[[@LINE+1]]:5, line:[[@LINE+2]]:33>
+ _Pragma("unroll(2)")
+ for (int i = 0; i < 10; ++i);
+ }
+}
+
#if __cplusplus >= 201703L
// CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
std::map<int, int> construct_with_init_list() {
Index: clang/lib/Parse/ParseStmt.cpp
===================================================================
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2163,6 +2163,8 @@
// Create temporary attribute list.
ParsedAttributesWithRange TempAttrs(AttrFactory);
+ SourceLocation StartLoc = Tok.getLocation();
+
// Get loop hints and consume annotated token.
while (Tok.is(tok::annot_pragma_loop_hint)) {
LoopHint Hint;
@@ -2183,6 +2185,9 @@
Stmts, StmtCtx, TrailingElseLoc, Attrs);
Attrs.takeAllFrom(TempAttrs);
+
+ assert(!Attrs.Range.getBegin().isValid());
+ Attrs.Range.setBegin(StartLoc);
return S;
}
Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -2938,7 +2938,7 @@
Token LoopHintTok;
LoopHintTok.startToken();
LoopHintTok.setKind(tok::annot_pragma_loop_hint);
- LoopHintTok.setLocation(PragmaName.getLocation());
+ LoopHintTok.setLocation(Introducer.Loc);
LoopHintTok.setAnnotationEndLoc(PragmaName.getLocation());
LoopHintTok.setAnnotationValue(static_cast<void *>(Info));
TokenList.push_back(LoopHintTok);
@@ -3025,7 +3025,7 @@
auto TokenArray = std::make_unique<Token[]>(1);
TokenArray[0].startToken();
TokenArray[0].setKind(tok::annot_pragma_loop_hint);
- TokenArray[0].setLocation(PragmaName.getLocation());
+ TokenArray[0].setLocation(Introducer.Loc);
TokenArray[0].setAnnotationEndLoc(PragmaName.getLocation());
TokenArray[0].setAnnotationValue(static_cast<void *>(Info));
PP.EnterTokenStream(std::move(TokenArray), 1,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80944.268958.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200605/4acb8c45/attachment.bin>
More information about the cfe-commits
mailing list