[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: Re: [PATCH] Fix crash parsing pragma after a case or a default
From: Olivier Goffart <ogoffart () kde ! org>
Date: 2013-09-20 11:40:54
Message-ID: 2013586.aND4j8Uck3 () gargamel
[Download RAW message or body]
I made the loop at a lower level.
Notice that the diagnostic is slightly different when there is a #pragma after
a case: and no statements. But I think it does not matter.
On Wednesday 18 September 2013 14:40:40 Richard Smith wrote:
> I think the loop should be at a lower level. This also crashes today (while
> diagnosing an empty loop body):
>
> int f() {
> if (false)
> #pragma weak f
> return 0;
> return 1;
> }
>
> ... and if we didn't have that diagnostic, we'd generate wrong code instead.
> On Wed, Sep 18, 2013 at 1:09 AM, Olivier Goffart <ogoffart@kde.org> wrote:
> > On Monday 16 September 2013 11:43:00 Richard Smith wrote:
> > > I don't particularly like adding a NullStmt here -- there was no null
> > > statement in the source code, so this is not a faithful AST
> >
> > representation
> >
> > > of the source.
> > >
> > > This approach seems like it will also accept this:
> > >
> > > switch (t) {
> > >
> > > case 1:
> > > #pragma weak t
> > > }
> > >
> > > We should probably reject this, because there is no statement after the
> > > case label. (That said, GCC accepts the above code, and fully treats
> >
> > these
> >
> > > pragmas as being statement-like entities, so your patch would be
> > > bug-compatible with them.)
> > >
> > > Does the same issue exist for goto labels?
> >
> > The problem was the same for goto.
> >
> > I attached a new patch that reject invalid code.
> >
> > --
> > Olivier
["0001-Fix-crash-when-there-is-a-pragma-right-after-a-case-.patch" (0001-Fix-crash-when-there-is-a-pragma-right-after-a-case-.patch)]
From 5c6251c86556eff971c885832b3a67624bcf90ae Mon Sep 17 00:00:00 2001
From: Olivier Goffart <ogoffart@woboq.com>
Date: Thu, 25 Jul 2013 14:43:11 +0200
Subject: [PATCH] Fix crash when there is a pragma right after a case
statement
---
include/clang/Parse/Parser.h | 8 ++++++--
test/CodeGen/pragma-weak.c | 22 ++++++++++++++++++++++
test/Parser/pragma-weak.c | 27 +++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 9855546..363ff4f 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -1470,8 +1470,12 @@ private:
typedef SmallVector<ParsedType, 12> TypeVector;
StmtResult ParseStatement(SourceLocation *TrailingElseLoc = 0) {
- StmtVector Stmts;
- return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc);
+ StmtResult Res;
+ do {
+ StmtVector Stmts;
+ Res = ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc);
+ } while(!Res.isInvalid() && !Res.get());
+ return Res;
}
StmtResult ParseStatementOrDeclaration(StmtVector &Stmts,
bool OnlyStatement,
diff --git a/test/CodeGen/pragma-weak.c b/test/CodeGen/pragma-weak.c
index 9bfb9ea..78486ff 100644
--- a/test/CodeGen/pragma-weak.c
+++ b/test/CodeGen/pragma-weak.c
@@ -165,6 +165,28 @@ void PR14046f() {
}
// CHECK: declare extern_weak i32 @PR14046e()
+// Parse #pragma weak after a label or case statement
+extern int PR16705a(void);
+extern int PR16705b(void);
+extern int PR16705c(void);
+int PR16705f(int a) {
+ switch(a) {
+ case 1:
+#pragma weak PR16705a
+ PR16705a();
+ default:
+#pragma weak PR16705b
+ PR16705b();
+ }
+label:
+ #pragma weak PR16705c
+ PR16705c();
+}
+
+// CHECK: declare extern_weak i32 @PR16705a()
+// CHECK: declare extern_weak i32 @PR16705b()
+// CHECK: declare extern_weak i32 @PR16705c()
+
///////////// TODO: stuff that still doesn't work
diff --git a/test/Parser/pragma-weak.c b/test/Parser/pragma-weak.c
index 7e5740b..fd47dd8 100644
--- a/test/Parser/pragma-weak.c
+++ b/test/Parser/pragma-weak.c
@@ -15,3 +15,30 @@ extern int z;
extern int a;
/* expected-warning {{extra tokens at end of '#pragma weak'}}*/ #pragma weak a b
/* expected-warning {{extra tokens at end of '#pragma weak'}}*/ #pragma weak a = x c
+
+
+void pragma_is_not_a_statement(int x)
+{
+ int t;
+
+ {
+ if (x)
+#pragma weak t
+ else // expected-error {{expected expression}}
+#pragma weak t
+ }
+
+ switch (x) {
+ case 1:
+#pragma weak t
+ } // expected-error {{expected statement}}
+ switch(x) {
+ default:
+#pragma weak t
+ } // expected-error {{expected statement}}
+
+label:
+#pragma weak t
+} // expected-error {{expected statement}}
+
+
--
1.7.12.1
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic