jdoerfert added a comment.

In D71241#1782460 <https://reviews.llvm.org/D71241#1782460>, @JonChesterfield 
wrote:

> > https://clang.llvm.org/docs/InternalsManual.html#the-ast-library
> > 
> >   Faithfulness¶
> >   The AST intends to provide a representation of the program that is 
> > faithful to the original source. 
>
> That's pretty convincing.


So let's actually look at the AST instead of just talking about it:

We take the asm.cpp example from @ABataev that, as I argued earlier, shows 
nicely why the alias solution does not work at all once we start thinking about 
linking things.

Now here is the code with calls to make it actually interesting:

  static void cpu() { asm("nop"); }
  
  #pragma omp declare variant(cpu) match(device = {kind(cpu)})
  static __attribute__((used)) void wrong_asm() {
    asm ("xxx");
  }
  
  void foo() {
    cpu();
    wrong_asm();
  }

In the current approach the as of foo looks like this:

  `-FunctionDecl 0x563baf0af958 <line:8:1, line:11:1> line:8:6 foo 'void ()'
    `-CompoundStmt 0x563baf0afb38 <col:12, line:11:1>
      |-CallExpr 0x563baf0afa78 <line:9:3, col:7> 'void'
      | `-ImplicitCastExpr 0x563baf0afa60 <col:3> 'void (*)()' 
<FunctionToPointerDecay>
      |   `-DeclRefExpr 0x563baf0afa40 <col:3> 'void ()' lvalue Function 
0x563baf0af458 'cpu' 'void ()'
      `-CallExpr 0x563baf0afb18 <line:10:3, col:13> 'void'
        `-ImplicitCastExpr 0x563baf0afb00 <col:3> 'void (*)()' 
<FunctionToPointerDecay>
          `-DeclRefExpr 0x563baf0afae0 <col:3> 'void ()' lvalue Function 
0x563baf0af668 'wrong_asm' 'void ()'

As you might see, you don't see any hint of the declare variant stuff that will 
eventually transform the `wrong_asm` call into a `cpu` call.

In the proposed scheme, the AST looks like this:

  `-FunctionDecl 0x1e53398 <line:8:1, line:11:1> line:8:6 foo 'void ()'
    `-CompoundStmt 0x1e53580 <col:12, line:11:1>
      |-CallExpr 0x1e534b8 <line:9:3, col:7> 'void'
      | `-ImplicitCastExpr 0x1e534a0 <col:3> 'void (*)()' 
<FunctionToPointerDecay>
      |   `-DeclRefExpr 0x1e53480 <col:3> 'void ()' lvalue Function 0x1e52e98 
'cpu' 'void ()'
      `-CallExpr 0x1e53560 <line:10:3, col:13> 'void'
        `-ImplicitCastExpr 0x1e53548 <col:3> 'void (*)()' 
<FunctionToPointerDecay>
          `-DeclRefExpr 0x1e53520 <col:3> 'void ()' lvalue Function 0x1e52e98 
'cpu' 'void ()' (Function 0x1e530a8 'wrong_asm' 'void ()')

Here, both the original callee (`wrong_ast`) and the actual callee `cpu` are 
shown at the call site.

Why would we not want that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71241/new/

https://reviews.llvm.org/D71241



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to