From cfe-users at lists.llvm.org Tue Dec 3 10:32:55 2019 From: cfe-users at lists.llvm.org (Robert Ankeney via cfe-users) Date: Tue, 3 Dec 2019 10:32:55 -0800 Subject: [cfe-users] DeclRefExpr question Message-ID: Let's assume I have a DeclRefExpr that is referenceing some variable that is declared as "static const int var;". How can I determine the variable is static? There is no isStaticLocal() or getStorageClass() call as there would be for the VarDecl. Is there something within the QualType that gets me that info? Many thanks, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Tue Dec 3 10:43:04 2019 From: cfe-users at lists.llvm.org (David Blaikie via cfe-users) Date: Tue, 3 Dec 2019 13:43:04 -0500 Subject: [cfe-users] DeclRefExpr question In-Reply-To: References: Message-ID: I'd guess you'd call "getDecl" to get the decl the DeclRefExpr is referencing, then dyn_cast that (the decl is a ValueDecl*) to VarDecl to see if it's a variable that's being referenced (could be a function, etc, etc) then do whatever you want to do with that VarDecl. On Tue, Dec 3, 2019 at 1:33 PM Robert Ankeney via cfe-users < cfe-users at lists.llvm.org> wrote: > Let's assume I have a DeclRefExpr that is referenceing some variable that > is declared as "static const int var;". How can I determine the variable is > static? There is no isStaticLocal() or getStorageClass() call as there > would be for the VarDecl. Is there something within the QualType that gets > me that info? > > Many thanks, > Robert > > _______________________________________________ > cfe-users mailing list > cfe-users at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Tue Dec 3 11:11:17 2019 From: cfe-users at lists.llvm.org (Robert Ankeney via cfe-users) Date: Tue, 3 Dec 2019 11:11:17 -0800 Subject: [cfe-users] DeclRefExpr question In-Reply-To: References: Message-ID: Worked great! Many thanks! Robert On Tue, Dec 3, 2019 at 10:43 AM David Blaikie wrote: > I'd guess you'd call "getDecl" to get the decl the DeclRefExpr is > referencing, then dyn_cast that (the decl is a ValueDecl*) to VarDecl to > see if it's a variable that's being referenced (could be a function, etc, > etc) then do whatever you want to do with that VarDecl. > > On Tue, Dec 3, 2019 at 1:33 PM Robert Ankeney via cfe-users < > cfe-users at lists.llvm.org> wrote: > >> Let's assume I have a DeclRefExpr that is referenceing some variable that >> is declared as "static const int var;". How can I determine the variable is >> static? There is no isStaticLocal() or getStorageClass() call as there >> would be for the VarDecl. Is there something within the QualType that gets >> me that info? >> >> Many thanks, >> Robert >> >> _______________________________________________ >> cfe-users mailing list >> cfe-users at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Tue Dec 10 22:45:08 2019 From: cfe-users at lists.llvm.org (henry ding via cfe-users) Date: Wed, 11 Dec 2019 14:45:08 +0800 Subject: [cfe-users] got wrong parameter type using clang Message-ID: simple test.cpp: void test(std::string xx,string bb,int aa){} clang usage: int getFuncInfo(Rewriter* TheRewrite,clang::ASTContext *Context, const FunctionDecl *func,FuncNode &node){ clang::LangOptions LangOpts; LangOpts.CPlusPlus = true; Policy.FullyQualifiedName = 1; ............................................................. . .......................................................... for(unsigned int i=0; igetNumParams(); i++) { string t = QualType::getAsString(func->getParamDecl(i)->getType().split(),Policy); string n = func->getParamDecl(i)->getName();//func->parameters()[i]->getQualifiedNameAsString() cout << t + "#" + n << endl; } } But,i got: int#xx //should string#xx int#bb //should string#bb int#aa Has anyone encountered this situation ? From cfe-users at lists.llvm.org Wed Dec 11 10:13:14 2019 From: cfe-users at lists.llvm.org (Richard Smith via cfe-users) Date: Wed, 11 Dec 2019 10:13:14 -0800 Subject: [cfe-users] got wrong parameter type using clang In-Reply-To: References: Message-ID: On Tue, 10 Dec 2019, 22:45 henry ding via cfe-users, < cfe-users at lists.llvm.org> wrote: > simple test.cpp: > void test(std::string xx,string bb,int aa){} > > clang usage: > int getFuncInfo(Rewriter* TheRewrite,clang::ASTContext *Context, const > FunctionDecl *func,FuncNode &node){ > clang::LangOptions LangOpts; > LangOpts.CPlusPlus = true; > Policy.FullyQualifiedName = 1; > ............................................................. > . .......................................................... > for(unsigned int i=0; igetNumParams(); i++) > { > string t = > QualType::getAsString(func->getParamDecl(i)->getType().split(),Policy); > string n = > > func->getParamDecl(i)->getName();//func->parameters()[i]->getQualifiedNameAsString() > cout << t + "#" + n << endl; > } > } > > But,i got: > int#xx //should string#xx > int#bb //should string#bb > int#aa > > Has anyone encountered this situation ? The bug is probably somewhere else. Make sure the proper language options are set up before parsing the source file, and that you're printing out any diagnostics. My guess would be that the source is failing to compile (wrong options, or can't find some standard header, or something), and the diagnostics are being discarded, and clang is replacing the parameter type with 'int' in error recovery. _______________________________________________ > cfe-users mailing list > cfe-users at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Thu Dec 12 20:18:04 2019 From: cfe-users at lists.llvm.org (henry ding via cfe-users) Date: Fri, 13 Dec 2019 12:18:04 +0800 Subject: [cfe-users] got wrong parameter type using clang In-Reply-To: References: Message-ID: l found there were a typedecl which typedef string as int, this may be the reason std::string|int|/usr/include/c++/4.8.5/bits/stringfwd.h 2019-12-12 2:13 GMT+08:00, Richard Smith : > On Tue, 10 Dec 2019, 22:45 henry ding via cfe-users, < > cfe-users at lists.llvm.org> wrote: > >> simple test.cpp: >> void test(std::string xx,string bb,int aa){} >> >> clang usage: >> int getFuncInfo(Rewriter* TheRewrite,clang::ASTContext *Context, const >> FunctionDecl *func,FuncNode &node){ >> clang::LangOptions LangOpts; >> LangOpts.CPlusPlus = true; >> Policy.FullyQualifiedName = 1; >> ............................................................. >> . .......................................................... >> for(unsigned int i=0; igetNumParams(); i++) >> { >> string t = >> QualType::getAsString(func->getParamDecl(i)->getType().split(),Policy); >> string n = >> >> func->getParamDecl(i)->getName();//func->parameters()[i]->getQualifiedNameAsString() >> cout << t + "#" + n << endl; >> } >> } >> >> But,i got: >> int#xx //should string#xx >> int#bb //should string#bb >> int#aa >> >> Has anyone encountered this situation ? > > > The bug is probably somewhere else. Make sure the proper language options > are set up before parsing the source file, and that you're printing out any > diagnostics. My guess would be that the source is failing to compile (wrong > options, or can't find some standard header, or something), and the > diagnostics are being discarded, and clang is replacing the parameter type > with 'int' in error recovery. > > _______________________________________________ >> cfe-users mailing list >> cfe-users at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users >> > From cfe-users at lists.llvm.org Sat Dec 14 09:55:04 2019 From: cfe-users at lists.llvm.org (Xuanyi Zhou via cfe-users) Date: Sat, 14 Dec 2019 12:55:04 -0500 Subject: [cfe-users] Checking if a class can be copy constructed Message-ID: <5df5222b.1c69fb81.dfbaa.79ab@mx.google.com> An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Sat Dec 14 16:31:26 2019 From: cfe-users at lists.llvm.org (Luke Zhou via cfe-users) Date: Sat, 14 Dec 2019 19:31:26 -0500 Subject: [cfe-users] Checking if a class can be copy constructed Message-ID: Hello again! It seems that the system failed to extract text from my previous post. This is my first time using a mailing list, so please excuse me for my mistakes. Here are the original contents of that post: Hello, > > I’ve been trying to do some code generation using clang (not libclang), > and want to find out if a class can be copy constructed. > > I’ve tried testing if the copy constructor is deleted, but this does not > work well with templates. For example, I have a class that contains a > std::vector, whose copy constructor will apparently fail > to instantiate, but doesn’t cause the copy constructors of std::vector or > my class to be marked as deleted. Also, isInvalidDecl() returns false, > which (I think) means that the compiler didn’t even attempt to instantiate > the constructor as it has never been used. > > I believe that my best bet is to try to manually check if the constructor > can instantiate. I’ve looked at clang::Sema, but was overwhelmed by the > large amount of functions. I also noticed that a lot of these functions > seem to have side effects, which is undesired since I do not want this > check to cause other parts of the code to not compile. > > Am I on the right path? If so, which functions in clang::Sema should I > use, and how? If not, is there a better way? > > Thank you very much. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Wed Dec 11 12:47:28 2019 From: cfe-users at lists.llvm.org (Luke Zhou via cfe-users) Date: Wed, 11 Dec 2019 15:47:28 -0500 Subject: [cfe-users] Checking if a class can be copy constructed Message-ID: Hello, I’ve been trying to do some code generation using clang (not libclang), and want to find out if a class can be copy constructed. I’ve tried testing if the copy constructor is deleted, but this does not work well with templates. For example, I have a class that contains a std::vector, whose copy constructor will apparently fail to instantiate, but doesn’t cause the copy constructors of std::vector or my class to be marked as deleted. Also, isInvalidDecl() returns false, which (I think) means that the compiler didn’t even attempt to instantiate the constructor as it has never been used. I believe that my best bet is to try to manually check if the constructor can instantiate. I’ve looked at clang::Sema, but was overwhelmed by the large amount of functions. I also noticed that a lot of these functions seem to have side effects, which is undesired since I do not want this check to cause other parts of the code to not compile. Am I on the right path? If so, which functions in clang::Sema should I use, and how? If not, is there a better way? Thank you very much. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Sun Dec 8 08:35:50 2019 From: cfe-users at lists.llvm.org (Victor via cfe-users) Date: Sun, 8 Dec 2019 21:35:50 +0500 Subject: [cfe-users] Clang and CDO, CDQ x64 instructions Message-ID: Hello Clang users and developers! I have problem compiling some generated assembly code with clang: mc.s:35739:2: error: invalid instruction mnemonic 'cdo' Does Clang support x64 CDO and CDQ instructions? The code is generated by MLRISC library. A bit older versions used CQTO/CLTD and that worked. Invocation options: clang -g -O2 -D_GNU_SOURCE -pedantic -m64 -Wno-unused-command-line-argument mc.s clang --version: clang version 9.0.1-+20191205081203+432bf48c08d-1~exp1~20191205191740.102 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Best wishes Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Thu Dec 19 00:19:00 2019 From: cfe-users at lists.llvm.org (Guofeng Zhang via cfe-users) Date: Thu, 19 Dec 2019 16:19:00 +0800 Subject: [cfe-users] Clang optimization options with out dead code elimination? Message-ID: Hi, We use clang 8+. Does clang have options (not -O0) that do not remove dead code when clang optimize the code? We have a old project, now migrating to Clang. It works well with -O0, but failed when use -O1 to -O3. Thanks, Guofeng -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfe-users at lists.llvm.org Thu Dec 19 11:12:21 2019 From: cfe-users at lists.llvm.org (David Blaikie via cfe-users) Date: Thu, 19 Dec 2019 11:12:21 -0800 Subject: [cfe-users] Clang optimization options with out dead code elimination? In-Reply-To: References: Message-ID: There are lots of reasons a program might fail to do what's desired when optimized - dead code is only one of them, any reason to believe that's the issue at hand? But no, LLVM doesn't really have any support for that. You might try running your program using the various sanitizersn (address, memory, undefined behavior sanitizer) to help identify if there are bugs that could be fixed. On Thu, Dec 19, 2019 at 12:19 AM Guofeng Zhang via cfe-users < cfe-users at lists.llvm.org> wrote: > Hi, > > We use clang 8+. Does clang have options (not -O0) that do not remove dead > code when clang optimize the code? > > We have a old project, now migrating to Clang. It works well with -O0, but > failed when use -O1 to -O3. > > Thanks, > > Guofeng > > _______________________________________________ > cfe-users mailing list > cfe-users at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: