[cfe-dev] ifStmt::getThen() returns ifStmt again?

Ulrich Thomas Gabor via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 28 00:57:14 PDT 2019


Hi

> Am 27.03.2019 um 23:54 schrieb Ulrich Thomas Gabor via cfe-dev <cfe-dev at lists.llvm.org>:
> 
> Hi
> 
>> On 27/03/2019 19:10, Ulrich Thomas Gabor via cfe-dev wrote:
>>> Hi
>>> 
>>> I recently started to test the current master
>>> https://github.com/llvm/llvm-project/commit/e04483ee35ba28c089cbbcec97a96b67ce0a035e
>>> 
>>> and found that ifStmt::getThen() now returns the ifStmt itself like in
>>> the
>>> following code where both dump calls give the same output:
>>> 
>>> stmt.dump(dbgs());
>>> const IfStmt ifS = cast<IfStmt>(stmt);
>>> auto x = ifS.getThen();
>>> x->dump(dbgs());
>>> 
>>> The AST was generated for a simple program:
>>> 
>>> int main(int argc, char ** argv) {
>>> 	int a = 0;
>>> 	if (true) {
>>> 		a = 10;
>>> 	}
>>> 	return a;
>>> }
>>> 
>>> 
>>> This was not the case for LLVM 8, previously the a=10 stmt was returned.
>>> Should it be that way or am I doing something wrong?
>>> 
>>> Best
>>> Ulrich
>>> 
>> 
>> I cannot reproduce this with a recent clang (and if IfStmt::getThen
>> returned the
>> IfStmt itself, clang would be hopelessly broken). If you look at the
>> implementation of
>> IfStmt::getThen in AST/Stmt.h you can see that it returns the then
>> statement, which
>> is stored as a trailing object.
> 
> Thank you for checking.
> 
> I casted wrong...
> 
>  const IfStmt ifS = cast<IfStmt>(stmt);
> 
> should be
> 
>  const IfStmt &ifS = cast<IfStmt>(stmt);
> 
> Working now! Thanks!

Thought about it again and was wondering, should copying not create either a fully-functional object or be disallowed, i.e. have a deleted copy constructor?

Best
Ulrich


> 
> 
> Best
> Ulrich
> 
> 
>> Best,
>> Bruno
>> 
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>>> 
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>> 
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
--
Ulrich Thomas Gabor, M.Sc.
Technische Universität Dortmund
Informatik, Lehrstuhl 12
Otto-Hahn-Str. 16, E09
44227 Dortmund, Germany

Phone:  +49 231 / 755-6263
Fax:    +49 231 / 755-6116
http://ess.cs.tu-dortmund.de/~ug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190328/736704ee/attachment.html>


More information about the cfe-dev mailing list