Skip to content

Enfore #must_tail can only be used at toplevel procedure scopes - #7129

Draft
FourteenBrush wants to merge 1 commit into
odin-lang:masterfrom
FourteenBrush:patch-7
Draft

Enfore #must_tail can only be used at toplevel procedure scopes#7129
FourteenBrush wants to merge 1 commit into
odin-lang:masterfrom
FourteenBrush:patch-7

Conversation

@FourteenBrush

Copy link
Copy Markdown
Contributor

Fixes #6640 (llvm codegen failure when using #must_tail on non toplevel proc scopes)

Tested this fix with the following code:

package main

main :: proc() {
	// some comment
	s()
	#must_tail s()
	
	call :: proc() {
		{
			s()
			#must_tail p() // error
		}
		
		#must_tail s()
		
		p :: proc() {
			
			{}
			{
				
				#must_tail s() // error
			}
		}
		for _ in 1..<3 {
			#must_tail s() // error
		}
	}
}

s :: proc() {}

Which now results in the following errors:

/home/cluster2/Projects/odin/OdinDebug/main.odin(11:15) Error: '#must_tail' can only be used at a top level procedure scope
	#must_tail p()
	           ^~^

/home/cluster2/Projects/odin/OdinDebug/main.odin(21:16) Error: '#must_tail' can only be used at a top level procedure scope
	#must_tail s()
	           ^~^

/home/cluster2/Projects/odin/OdinDebug/main.odin(25:15) Error: '#must_tail' can only be used at a top level procedure scope
	#must_tail s()

--
I intended to fix #6529 as well, but I'm not sure what the desired behavior should be of using deferred statements in combination with a #must_tail, simply disallowing it?

@antisaling

Copy link
Copy Markdown
Contributor

WRT #6529 I do agree that it should emit an error in the checker like: defer cannot be used in the same scope as #must_tail (as an error on the defer call) itself. if you still think this is up to interpretation maybe ping ginger on discord or leave it for another PR

@FourteenBrush
FourteenBrush marked this pull request as draft August 12, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLVM: #must_tail in loop body causes musttail call must precede a ret with an optional bitcast #must_tail with defer causes llvm error

2 participants