alexfh wrote:

> > @alexfh I don't have the resources to look into this issue. Please revert 
> > if you need to.
> 
> This has been in trunk for a long time, a revert here would be HIGHLY 
> unfortunate. I would vastly prefer someone spend time trying to figure out 
> why we are confused with the variable init here instead.

It would be really unfortunate indeed, if we have to revert this. But that's a 
clearly incorrect codegen, so the only alternative is to get a fix.

I looked a bit into this and came up with a slightly more compact test case: 
https://gcc.godbolt.org/z/Pcj8954Ye
```
struct Node {
  long val;
};
void Push(Node *);
template <bool>
void BatchPull() {
    Push(new Node(0));
}
void TestBody() {
    (void)BatchPull<true>; 
}
```
Similarly to 
https://github.com/llvm/llvm-project/pull/138518#issuecomment-2930816205, AST 
dump already shows the problem (https://godbolt.org/z/PYeG1v5Yz) - 
`ImplicitCastExpr` to `long` is dropped from the template instantiation:
```
|-FunctionTemplateDecl <line:5:1, line:8:1> line:6:6 BatchPull
| |-NonTypeTemplateParmDecl <line:5:11> col:15 'bool' depth 0 index 0
| |-FunctionDecl <line:6:1, line:8:1> line:6:6 BatchPull 'void ()'
| | `-CompoundStmt <col:18, line:8:1>
| |   `-CallExpr <line:7:5, col:21> 'void'
| |     |-ImplicitCastExpr <col:5> 'void (*)(Node *)' <FunctionToPointerDecay>
| |     | `-DeclRefExpr <col:5> 'void (Node *)' lvalue Function 0x389dae98 
'Push' 'void (Node *)'
| |     `-CXXNewExpr <col:10, col:20> 'Node *' Function 0x389db540 'operator 
new' 'void *(unsigned long)'
| |       `-CXXParenListInitExpr <col:18, col:20> 'Node'
| |         `-ImplicitCastExpr <col:19> 'long' <IntegralCast>
| |           `-IntegerLiteral <col:19> 'int' 0
| `-FunctionDecl <line:6:1, line:8:1> line:6:6 used BatchPull 'void ()' 
implicit_instantiation
|   |-TemplateArgument integral 'true'
|   `-CompoundStmt <col:18, line:8:1>
|     `-CallExpr <line:7:5, col:21> 'void'
|       |-ImplicitCastExpr <col:5> 'void (*)(Node *)' <FunctionToPointerDecay>
|       | `-DeclRefExpr <col:5> 'void (Node *)' lvalue Function 0x389dae98 
'Push' 'void (Node *)'
|       `-CXXNewExpr <col:10, col:20> 'Node *' Function 0x389db540 'operator 
new' 'void *(unsigned long)'
|         `-CXXParenListInitExpr <col:18, col:20> 'Node'
|           `-IntegerLiteral <col:19> 'int' 0
```

I'm trying to figure out how this commit affects the relevant template 
instantiation logic, but no ideas so far.

https://github.com/llvm/llvm-project/pull/138518
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to