summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/scope-check.c
Commit message (Collapse)AuthorAgeFilesLines
* Revert "clang support gnu asm goto."Erich Keane2019-05-301-16/+0
| | | | | | | | | | | This reverts commit 954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a. Reverting due to test failures as requested by Jennifer Yu. Conflicts: clang/test/CodeGen/asm-goto.c llvm-svn: 362106
* clang support gnu asm goto.Jennifer Yu2019-05-301-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Syntax: asm [volatile] goto ( AssemblerTemplate : : InputOperands : Clobbers : GotoLabels) https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html New llvm IR is "callbr" for inline asm goto instead "call" for inline asm For: asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop); IR: callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1 to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3 asm.fallthrough: Compiler need to generate: 1> a dummy constarint 'X' for each label. 2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number". Diagnostic 1> duplicate asm operand name are used in output, input and label. 2> goto out of scope. llvm-svn: 362045
* Reword switch/goto diagnostics "protected scope" diagnostics. Making up a termRichard Smith2014-09-061-18/+18
| | | | | | | | "protected scope" is very unhelpful here and actively confuses users. Instead, simply state the nature of the problem in the diagnostic: we cannot jump from here to there. The notes explain nicely why not. llvm-svn: 217293
* fix rdar://9024687, a crash on invalid that we used to silently ignore.Chris Lattner2011-02-181-0/+3
| | | | llvm-svn: 125962
* Implement an indirect-goto optimization for goto *&&lbl and respect thisJohn McCall2010-10-281-1/+31
| | | | | | | | | | | | | | in the scope checker. With that done, turn an indirect goto into a protected scope into a hard error; otherwise IR generation has to start worrying about declarations not dominating their scopes, as exemplified in PR8473. If this really affects anyone, I can probably adjust this to only hard-error on possible indirect gotos into VLA scopes rather than arbitrary scopes. But we'll see how people cope with the aggressive change on the marginal feature. llvm-svn: 117539
* Labels (and case statement) don't create independent scope parents for theJohn McCall2010-08-021-16/+16
| | | | | | | | purposes of the jump checker. Also extend Ted's iteration fix to labels. Fixes PR7789. llvm-svn: 110082
* Correct spelling of expected error message. Apparently I forgot to re-runJohn McCall2010-05-121-1/+1
| | | | | | the test suite after modifying this diagnostic. llvm-svn: 103537
* When checking scopes for indirect goto, be more permissive (but still safe)John McCall2010-05-121-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | about the permitted scopes. Specifically: 1) Permit labels and gotos to appear after a prologue of variable initializations. 2) Permit indirect gotos to jump out of scopes that don't require cleanup. 3) Diagnose possible attempts to indirect-jump out of scopes that do require cleanup. This requires a substantial reinvention of the algorithm for checking indirect goto. The current algorithm is Omega(M*N), with M = the number of unique scopes being jumped from and N = the number of unique scopes being jumped to, with an additional factor that is probably (worst-case) linear in the depth of scopes. Thus the entire thing is likely cubic given some truly bizarre ill-formed code; on well-formed code the additional factor collapses to an amortized constant (when amortized over the entire function) and so the algorithm is quadratic. Even this requires every label to appear in its own scope, which would be very unusual for indirect-goto code (and extremely unlikely for well-formed code); it is far more likely that all labels will be in the same scope and so the algorithm becomes linear. For such a marginal feature, I am fairly happy with this result. (this is using JumpDiagnostic's definition of scope, where successive variables in a block appear in their own scope) llvm-svn: 103536
* Emit warning on indirect goto that potentially violates Chris Lattner2010-03-051-1/+1
| | | | | | scope instead of error, PR6517 llvm-svn: 97826
* address PR6502 by downgrading the scope checker's addressChris Lattner2010-03-051-1/+1
| | | | | | of label error to a warning controllable with a -W flag. llvm-svn: 97815
* Insulate these from changes to the default for -Wunreachable-code.Mike Stump2010-01-231-1/+1
| | | | llvm-svn: 94326
* Implement goto inside of blocks.Mike Stump2010-01-191-6/+5
| | | | llvm-svn: 93945
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* run the jump checker on blocks, even though they don't have gotos,Chris Lattner2009-04-191-1/+14
| | | | | | they do allow switches. llvm-svn: 69510
* add a new Sema::CurFunctionNeedsScopeChecking bool that is used to avoid Chris Lattner2009-04-191-9/+2
| | | | | | | calling into the jump checker when a function or method is known to contain no VLAs or @try blocks. llvm-svn: 69509
* apparently gotos aren't allowed at all in blocks. Stub out a testcase for ↵Chris Lattner2009-04-191-0/+24
| | | | | | when/if they are. llvm-svn: 69507
* more testcases of variably modified types.Chris Lattner2009-04-191-1/+15
| | | | llvm-svn: 69506
* second half of indirect jump checking: make sure that any Chris Lattner2009-04-191-3/+6
| | | | | | address taken labels are in function scope llvm-svn: 69499
* First half of jump scope checking for indirect goto.Chris Lattner2009-04-191-0/+26
| | | | llvm-svn: 69498
* add some testcases that we do not correctly handle.Chris Lattner2009-04-181-2/+19
| | | | llvm-svn: 69492
* reimplement DeclStmt handling so that we correctly handle intermixed Chris Lattner2009-04-181-0/+29
| | | | | | VLA's and statement expressions. llvm-svn: 69491
* rearrange.Chris Lattner2009-04-181-6/+10
| | | | llvm-svn: 69490
* add testcases for some more scary/horrible things that work.Chris Lattner2009-04-181-2/+15
| | | | llvm-svn: 69488
* unconditionally check for goto correctness. This is because switchChris Lattner2009-04-181-1/+0
| | | | | | | | | statements don't end up in the LabelMap so we don't have a quick way to filter them. We could add state to Sema (a "has vla" and "has jump" bit) to try to filter this out, but that would be sort of gross and I'm not convinced it is the best way. Thoughts welcome. llvm-svn: 69476
* Improve switch diagnostic to emit the "jump" message on theChris Lattner2009-04-181-3/+3
| | | | | | | | | | | | | | | specific bad case instead of on the switch. Putting it on the switch means you don't know what case is the problem. For example: scope-check.c:54:3: error: illegal switch case into protected scope case 2: ^ scope-check.c:53:9: note: jump bypasses initialization of variable length array int a[x]; ^ llvm-svn: 69462
* first step to getting switches giving "jump into vla scope" errors.Chris Lattner2009-04-181-0/+11
| | | | llvm-svn: 69461
* improve wording of scope violation error messages.Chris Lattner2009-04-181-16/+5
| | | | llvm-svn: 69456
* rewrite the goto scope checking code to be more efficient, simpler,Chris Lattner2009-04-181-8/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | produce better diagnostics, and be more correct in ObjC cases (fixing rdar://6803963). An example is that we now diagnose: int test1(int x) { goto L; int a[x]; int b[x]; L: return sizeof a; } with: scope-check.c:15:3: error: illegal goto into protected scope goto L; ^ scope-check.c:17:7: note: scope created by variable length array int b[x]; ^ scope-check.c:16:7: note: scope created by variable length array int a[x]; ^ instead of just saying "invalid jump". An ObjC example is: void test1() { goto L; @try { L: ; } @finally { } } t.m:6:3: error: illegal goto into protected scope goto L; ^ t.m:7:3: note: scope created by @try block @try { ^ There are a whole ton of fixme's for stuff to do, but I believe that this is a monotonic improvement over what we had. llvm-svn: 69437
* add another testcaseChris Lattner2009-04-181-7/+19
| | | | llvm-svn: 69432
* Revert previous patch (will commit a fix soon).Steve Naroff2009-04-151-0/+8
| | | | llvm-svn: 69178
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Check a few more kinds of declarations that make a scope.Eli Friedman2009-02-281-0/+16
| | | | llvm-svn: 65680
* Start of checking for gotos which jump to an illegal destination. Eli Friedman2009-02-281-0/+8
As far as I know, this catches all cases of jumping into the scope of a variable with a variably modified type (excluding statement expressions) in C. This is missing some stuff we probably want to check (other kinds of variably modified declarations, statement expressions, indirect gotos/addresses of labels in a scope, ObjC @try/@finally, cleanup attribute), the diagnostics aren't very good, and it's not particularly efficient, but it's a decent start. This patch is a slightly modified version of the patch I attached to PR3259, and it fixes that bug. I was sort of planning on improving it, but I think it's okay as-is, especially since it looks like CodeGen doesn't have any use for this sort of data structure. The only significant change I can think of from the version I attached to PR3259 is that this version skips running the checking code when a function doesn't contain any labels. This patch doesn't cover case statements, which also need similar checking; I'm not sure how we should deal with that. Extending the goto checking to also check case statements wouldn't be too hard; it's just a matter of keeping track of the scope of the closest switch and checking that the scope of every case is the same as the scope of the switch. That said, it would likely be a performance hit to run this check on every function (it's an extra pass over the entire function), so we probably want some other solution. llvm-svn: 65678
OpenPOWER on IntegriCloud