Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters of function declarations not included in decls_begin/decls_end #7814

Open
llvmbot opened this issue Jun 21, 2010 · 1 comment
Open
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Member

llvmbot commented Jun 21, 2010

Bugzilla Link 7442
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

For the following code:

int foo(int bar);

int foo(int bar) {
return bar;
}

The first declaration of foo does not include 'int bar' in its decls_begin/decls_end, while the second does. Here the analysis, from a test program I wrote using RecursiveASTVisitor:

[ FunctionDecl ] sample.cc:17:5: int foo(int bar)
[ FunctionProtoType ] (sample.cc:17:5): int (identifier)(int)

Visiting result type
[ BuiltinType ] (sample.cc:17:5): int identifier

Visiting parameters
[@@@ HERE IS THE BUG -- there's nothing here @@@]
Done
[ FunctionDecl ] sample.cc:19:5: int foo(int bar) {
return bar;
}

[ FunctionProtoType ] (sample.cc:19:5): int (identifier)(int)

Visiting result type
[ BuiltinType ] (sample.cc:19:5): int identifier

Visiting parameters
[ ParmVarDecl ] sample.cc:19:13: int bar
[ BuiltinType ] (sample.cc:19:13): int identifier

Visiting function body
[ CompoundStmt ] (CompoundStmt 0x12f1f80 <sample.cc:19:18, line:21:1>
(ReturnStmt 0x12f1f58 <line:20:3, col:10>
(DeclRefExpr 0x12f1f28 col:10 'int' ParmVar='bar' 0x12f1e30)))

[ ReturnStmt ] (ReturnStmt 0x12f1f58 <sample.cc:20:3, col:10>
(DeclRefExpr 0x12f1f28 col:10 'int' ParmVar='bar' 0x12f1e30))

[ DeclRefExpr ] (DeclRefExpr 0x12f1f28 sample.cc:20:10 'int' ParmVar='bar' 0x
12f1e30)

The "visiting parameters" code just iterates over decls_begin/end.

dgregor analyzed the solution as follows:

it makes sense to have ParmVarDecls show up in the lexical scope of function declarations. we'd probably have to do that in Sema::ActOnFunctionDeclarator rather than Sema::ActOnStartOfFunctionDef

craig

@llvmbot
Copy link
Member Author

llvmbot commented Oct 28, 2010

I've worked around this problem, now that FunctionDecl exposes the FunctionProtoTypeLoc (which does have parameters always) rather than just FunctionProtoType. So this may or may not still be a bug, but it's fine to lower the priority very low, since there's a straightforward workaround.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

1 participant