<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/128713>128713</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Parsing of cutom pragma is out of order.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          preoteasa
      </td>
    </tr>
</table>

<pre>
    The interaction between parsing custom pragmas PragmaHandler::HandlePragma
and ASTConsumer::HandleTopLevelDecl is wrong.

For example parsing the following file:

```
void fnA() { }

#pragma enable_annotate

void fn1() { }
void fn2() { }
```

results in calling PragmaHandler::HandlePragma before calling ASTConsumer::HandleTopLevelDecl for 
declaration fnA.

This problem can be reproduced when using the example plugin AnnotateFunctions.so

`CLANG_DIR/bin/clang -fplugin=CLANG_DIR/lib/AnnotateFunctions.so  -emit-llvm -S annotate.c -o annotate.S`

for the file annotate.c which has the content given above. The result of this call results in adding an annotation attribute to fnA instead of generating an error because pragma enable_annotate is after the 
first declaration.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlN2q4zYQx59GvhliFDmJkwtfeDe4LSxl6cn9MpbHtoosGX0k7dsX2T45KXugBYMQ86GZ33886L0aDFHFjl_Y8ZphDKN11ezIBkKPWWu7v6vbSKBMIIcyKGugpfAgMjCj88oMIKMPdoLZ4TChh-_L-SuaTpNjRc2Ker2sBsZrNB3Ub7ev1vg4_dvnZudvdCd9JalBeXg4a4ac8ZrxurEO6C-cZk3Pt8NI0Fut7SPdeqUpZVvc2YlvH6_vVnXQm5qJMxMXYOUXYOV18xPFWjqQwVbTDzTGBgy0mrfQ_U-hm0H8nPPlYcZrRz7q4EEZkKh1qvM_EEFLvXX0dP8_rHrrgPG6I6nR4aJTb-qN3G1UHmZnW00TSEwSgqPZ2S5K6uAxkoH45PlkrOOgDNQbjiaaRX-fe_sk_PVb_fsvP66__cFE0yrDRCM1mgF2_RrNiuuri1YtE81nGQF2NKmw0_o-we4N3kXIJezsx-3tiTU1vKivNL16P0YlRxjRL1ZpTSATYFB3MoCtvVMOaaBXVcD2EBKchBpelMKuSzjQvKdOQDEEp9oYCIJNdEEZHwi7lGUgQ4n7GkTOWQctSYye4PPxSuONfaC1jdSRcj7Ai4J51lVFdykumFG1Lw_8cOElP2djddifkGN5PpR9eSGSfF_KsufdqexRdlRmqhJcHLkQx31RnEWZn_lRnE_HQlxO_HCRyA6cJlQ6T8Bz64ZMeR-p2otzuS8yjS1pv-wFIQw9YLEyIdKacFUK2rVx8OzAtfLBf6QJKmiqvm__p-1Bxo_tkHq2ccFuXUcuz6LT1RjC7NNki4aJZlBhjG0u7ZQGRt_fj93s7J8kAxPNUoxnotmqvVfinwAAAP__DfOXuw">