[PATCH] D15007: [analyzer] Improve modelling of nullptr_t in the analyzer. Fix PR25414.
xazax.hun created this revision. xazax.hun added reviewers: zaks.anna, dcoughlin. xazax.hun added subscribers: cfe-commits, dkrupp. This is a fix for https://llvm.org/bugs/show_bug.cgi?id=25414 This patch is intended to improve the modelling of std::nullptr_t. http://reviews.llvm.org/D15007 Files: lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/nullptr.cpp Index: test/Analysis/nullptr.cpp === --- test/Analysis/nullptr.cpp +++ test/Analysis/nullptr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s +// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s + +void clang_analyzer_eval(int); // test to see if nullptr is detected as a null pointer void foo1(void) { @@ -87,3 +89,29 @@ // Create MaterializeTemporaryExpr with a nullptr inside. const nullptr_t &r = nullptr; } + +struct X { + virtual void f() {} +}; + +void invokeF(X* x) { + x->f(); // expected-warning{{Called C++ object pointer is null}} +} + +struct Type { + decltype(nullptr) x; +}; + +void shouldNotCrash() { + decltype(nullptr) p; + invokeF(p); + invokeF(nullptr); + X *x = Type().x; + x->f(); +} + +void f(decltype(nullptr) p) { + int *q = nullptr; + clang_analyzer_eval(p == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(q == 0); // expected-warning{{TRUE}} +} Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1362,6 +1362,9 @@ if (!L.getAs()) { return UnknownVal(); } + if (!T.isNull() && T->isNullPtrType()) { +return svalBuilder.makeZeroVal(T); + } const MemRegion *MR = L.castAs().getRegion(); Index: test/Analysis/nullptr.cpp === --- test/Analysis/nullptr.cpp +++ test/Analysis/nullptr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s +// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s + +void clang_analyzer_eval(int); // test to see if nullptr is detected as a null pointer void foo1(void) { @@ -87,3 +89,29 @@ // Create MaterializeTemporaryExpr with a nullptr inside. const nullptr_t &r = nullptr; } + +struct X { + virtual void f() {} +}; + +void invokeF(X* x) { + x->f(); // expected-warning{{Called C++ object pointer is null}} +} + +struct Type { + decltype(nullptr) x; +}; + +void shouldNotCrash() { + decltype(nullptr) p; + invokeF(p); + invokeF(nullptr); + X *x = Type().x; + x->f(); +} + +void f(decltype(nullptr) p) { + int *q = nullptr; + clang_analyzer_eval(p == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(q == 0); // expected-warning{{TRUE}} +} Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1362,6 +1362,9 @@ if (!L.getAs()) { return UnknownVal(); } + if (!T.isNull() && T->isNullPtrType()) { +return svalBuilder.makeZeroVal(T); + } const MemRegion *MR = L.castAs().getRegion(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r254143 - Fix for merging decls in pragma weak
Author: amusman Date: Thu Nov 26 03:34:30 2015 New Revision: 254143 URL: http://llvm.org/viewvc/llvm-project?rev=254143&view=rev Log: Fix for merging decls in pragma weak Calling CheckFunctionDeclaration so that 2 decls for the 'weak' are merged. Differential Revision: http://reviews.llvm.org/D13048 Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/CodeGen/pragma-weak.c cfe/trunk/test/Sema/pragma-weak.c Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=254143&r1=254142&r2=254143&view=diff == --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Nov 26 03:34:30 2015 @@ -5435,17 +5435,22 @@ NamedDecl * Sema::DeclClonePragmaWeak(Na assert(isa(ND) || isa(ND)); NamedDecl *NewD = nullptr; if (FunctionDecl *FD = dyn_cast(ND)) { -FunctionDecl *NewFD; -// FIXME: Missing call to CheckFunctionDeclaration(). // FIXME: Mangling? // FIXME: Is the qualifier info correct? // FIXME: Is the DeclContext correct? -NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(), - Loc, Loc, DeclarationName(II), - FD->getType(), FD->getTypeSourceInfo(), - SC_None, false/*isInlineSpecified*/, - FD->hasPrototype(), - false/*isConstexprSpecified*/); + +LookupResult Previous(*this, II, Loc, LookupOrdinaryName); +LookupParsedName(Previous, TUScope, nullptr, true); + +auto NewFD = FunctionDecl::Create( +FD->getASTContext(), FD->getDeclContext(), Loc, Loc, +DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None, +false /*isInlineSpecified*/, FD->hasPrototype(), +false /*isConstexprSpecified*/); + +CheckFunctionDeclaration(TUScope, NewFD, Previous, + false /*IsExplicitSpecialization*/); + NewD = NewFD; if (FD->getQualifier()) Modified: cfe/trunk/test/CodeGen/pragma-weak.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pragma-weak.c?rev=254143&r1=254142&r2=254143&view=diff == --- cfe/trunk/test/CodeGen/pragma-weak.c (original) +++ cfe/trunk/test/CodeGen/pragma-weak.c Thu Nov 26 03:34:30 2015 @@ -17,6 +17,7 @@ // CHECK-DAG: @mix2 = weak alias void (), void ()* @__mix2 // CHECK-DAG: @a1 = weak alias void (), void ()* @__a1 // CHECK-DAG: @xxx = weak alias void (), void ()* @__xxx +// CHECK-DAG: @weakfoo = weak alias void {{.*}} @localfoo @@ -173,6 +174,14 @@ label: // CHECK: declare extern_weak i32 @PR16705b() // CHECK: declare extern_weak i32 @PR16705c() +// In this test case, we have a declaration of weakfoo before #pragma weak. +// Test that 2 decls for the weakfoo are merged. +extern void weakfoo(); +void localfoo() { } +#pragma weak weakfoo=localfoo +extern void externmain() { return weakfoo(); } +// CHECK-LABEL: define void @externmain() +// CHECK: call{{.*}}@weakfoo / TODO: stuff that still doesn't work Modified: cfe/trunk/test/Sema/pragma-weak.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-weak.c?rev=254143&r1=254142&r2=254143&view=diff == --- cfe/trunk/test/Sema/pragma-weak.c (original) +++ cfe/trunk/test/Sema/pragma-weak.c Thu Nov 26 03:34:30 2015 @@ -9,3 +9,9 @@ void __a3(void) __attribute((noinline)); #pragma weak a3 = __a3 // expected-note {{previous definition}} void a3(void) __attribute((alias("__a3"))); // expected-error {{redefinition of 'a3'}} void __a3(void) {} + +extern void weak2foo(int); // expected-note {{previous declaration is here}} expected-note {{'weak2foo' declared here}} +void local2foo(double d1, double d2) { } +#pragma weak weak2foo=local2foo // expected-error {{conflicting types for 'weak2foo'}} +extern void extern2main() { return weak2foo(); } // expected-error {{too few arguments to function call, expected 1, have 0}} + ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13048: Fix for merging decls in pragma weak
This revision was automatically updated to reflect the committed changes. Closed by commit rL254143: Fix for merging decls in pragma weak (authored by amusman). Changed prior to commit: http://reviews.llvm.org/D13048?vs=35348&id=41216#toc Repository: rL LLVM http://reviews.llvm.org/D13048 Files: cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/CodeGen/pragma-weak.c cfe/trunk/test/Sema/pragma-weak.c Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp === --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -5435,17 +5435,22 @@ assert(isa(ND) || isa(ND)); NamedDecl *NewD = nullptr; if (FunctionDecl *FD = dyn_cast(ND)) { -FunctionDecl *NewFD; -// FIXME: Missing call to CheckFunctionDeclaration(). // FIXME: Mangling? // FIXME: Is the qualifier info correct? // FIXME: Is the DeclContext correct? -NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(), - Loc, Loc, DeclarationName(II), - FD->getType(), FD->getTypeSourceInfo(), - SC_None, false/*isInlineSpecified*/, - FD->hasPrototype(), - false/*isConstexprSpecified*/); + +LookupResult Previous(*this, II, Loc, LookupOrdinaryName); +LookupParsedName(Previous, TUScope, nullptr, true); + +auto NewFD = FunctionDecl::Create( +FD->getASTContext(), FD->getDeclContext(), Loc, Loc, +DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None, +false /*isInlineSpecified*/, FD->hasPrototype(), +false /*isConstexprSpecified*/); + +CheckFunctionDeclaration(TUScope, NewFD, Previous, + false /*IsExplicitSpecialization*/); + NewD = NewFD; if (FD->getQualifier()) Index: cfe/trunk/test/CodeGen/pragma-weak.c === --- cfe/trunk/test/CodeGen/pragma-weak.c +++ cfe/trunk/test/CodeGen/pragma-weak.c @@ -17,6 +17,7 @@ // CHECK-DAG: @mix2 = weak alias void (), void ()* @__mix2 // CHECK-DAG: @a1 = weak alias void (), void ()* @__a1 // CHECK-DAG: @xxx = weak alias void (), void ()* @__xxx +// CHECK-DAG: @weakfoo = weak alias void {{.*}} @localfoo @@ -173,6 +174,14 @@ // CHECK: declare extern_weak i32 @PR16705b() // CHECK: declare extern_weak i32 @PR16705c() +// In this test case, we have a declaration of weakfoo before #pragma weak. +// Test that 2 decls for the weakfoo are merged. +extern void weakfoo(); +void localfoo() { } +#pragma weak weakfoo=localfoo +extern void externmain() { return weakfoo(); } +// CHECK-LABEL: define void @externmain() +// CHECK: call{{.*}}@weakfoo / TODO: stuff that still doesn't work Index: cfe/trunk/test/Sema/pragma-weak.c === --- cfe/trunk/test/Sema/pragma-weak.c +++ cfe/trunk/test/Sema/pragma-weak.c @@ -9,3 +9,9 @@ #pragma weak a3 = __a3 // expected-note {{previous definition}} void a3(void) __attribute((alias("__a3"))); // expected-error {{redefinition of 'a3'}} void __a3(void) {} + +extern void weak2foo(int); // expected-note {{previous declaration is here}} expected-note {{'weak2foo' declared here}} +void local2foo(double d1, double d2) { } +#pragma weak weak2foo=local2foo // expected-error {{conflicting types for 'weak2foo'}} +extern void extern2main() { return weak2foo(); } // expected-error {{too few arguments to function call, expected 1, have 0}} + Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp === --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -5435,17 +5435,22 @@ assert(isa(ND) || isa(ND)); NamedDecl *NewD = nullptr; if (FunctionDecl *FD = dyn_cast(ND)) { -FunctionDecl *NewFD; -// FIXME: Missing call to CheckFunctionDeclaration(). // FIXME: Mangling? // FIXME: Is the qualifier info correct? // FIXME: Is the DeclContext correct? -NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(), - Loc, Loc, DeclarationName(II), - FD->getType(), FD->getTypeSourceInfo(), - SC_None, false/*isInlineSpecified*/, - FD->hasPrototype(), - false/*isConstexprSpecified*/); + +LookupResult Previous(*this, II, Loc, LookupOrdinaryName); +LookupParsedName(Previous, TUScope, nullptr, true); + +auto NewFD = FunctionDecl::Create( +FD->getASTContext(), FD->getDeclContext(), Loc, Loc, +DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None, +false /*isInlineSpecified*/, FD->hasPrototype(), +false /*isConstexprSpecified*/); + +CheckFunctionDeclaration(T
Re: [PATCH] D14919: Fix IssueHash generation
seaneveson added a comment. In http://reviews.llvm.org/D14919#296597, @o.gyorgy wrote: > I did not create a test checker for the NormalizeLine error in the patch. > Should I add a test checker for this? I was wondering what sort of source code causes the crash, but I do think it would be good to have a regression test. > Do you have any suggestions where to put it if required? Maybe in bug_hash_test.cpp, although I'm not sure its necessary to check the plist output when testing for a crash. http://reviews.llvm.org/D14919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14919: Fix IssueHash generation
xazax.hun added a comment. In http://reviews.llvm.org/D14919#297168, @seaneveson wrote: > I was wondering what sort of source code causes the crash, but I do think it > would be good to have a regression test. It is possible to generate bug reports without associated declaration, altough it is not advies. I think the reason why it is possible, to give flexibility. E.g.: one could report issues regarding documentation. http://reviews.llvm.org/D14919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15007: [analyzer] Improve modelling of nullptr_t in the analyzer. Fix PR25414.
NoQ added a subscriber: NoQ. NoQ added a comment. Wow, useful stuff! There's a little problem with the `shouldNotCrash()` test: the first warning on `invokeF()` on line 107 generates a sink, and the rest of the function never gets executed. It's probably a good idea to split it into three separate tests. Then it'd also warn on line 110. http://reviews.llvm.org/D15007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15007: [analyzer] Improve modelling of nullptr_t in the analyzer. Fix PR25414.
xazax.hun updated this revision to Diff 41221. xazax.hun added a comment. Improved test cases. http://reviews.llvm.org/D15007 Files: lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/nullptr.cpp Index: test/Analysis/nullptr.cpp === --- test/Analysis/nullptr.cpp +++ test/Analysis/nullptr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s +// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s + +void clang_analyzer_eval(int); // test to see if nullptr is detected as a null pointer void foo1(void) { @@ -87,3 +89,35 @@ // Create MaterializeTemporaryExpr with a nullptr inside. const nullptr_t &r = nullptr; } + +int getSymbol(); + +struct X { + virtual void f() {} +}; + +void invokeF(X* x) { + x->f(); // expected-warning{{Called C++ object pointer is null}} +} + +struct Type { + decltype(nullptr) x; +}; + +void shouldNotCrash() { + decltype(nullptr) p; + if (getSymbol()) +invokeF(p); + if (getSymbol()) +invokeF(nullptr); + if (getSymbol()) { +X *x = Type().x; +x->f(); // expected-warning{{Called C++ object pointer is null}} + } +} + +void f(decltype(nullptr) p) { + int *q = nullptr; + clang_analyzer_eval(p == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(q == 0); // expected-warning{{TRUE}} +} Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1362,6 +1362,9 @@ if (!L.getAs()) { return UnknownVal(); } + if (!T.isNull() && T->isNullPtrType()) { +return svalBuilder.makeZeroVal(T); + } const MemRegion *MR = L.castAs().getRegion(); Index: test/Analysis/nullptr.cpp === --- test/Analysis/nullptr.cpp +++ test/Analysis/nullptr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s +// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s + +void clang_analyzer_eval(int); // test to see if nullptr is detected as a null pointer void foo1(void) { @@ -87,3 +89,35 @@ // Create MaterializeTemporaryExpr with a nullptr inside. const nullptr_t &r = nullptr; } + +int getSymbol(); + +struct X { + virtual void f() {} +}; + +void invokeF(X* x) { + x->f(); // expected-warning{{Called C++ object pointer is null}} +} + +struct Type { + decltype(nullptr) x; +}; + +void shouldNotCrash() { + decltype(nullptr) p; + if (getSymbol()) +invokeF(p); + if (getSymbol()) +invokeF(nullptr); + if (getSymbol()) { +X *x = Type().x; +x->f(); // expected-warning{{Called C++ object pointer is null}} + } +} + +void f(decltype(nullptr) p) { + int *q = nullptr; + clang_analyzer_eval(p == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(q == 0); // expected-warning{{TRUE}} +} Index: lib/StaticAnalyzer/Core/RegionStore.cpp === --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1362,6 +1362,9 @@ if (!L.getAs()) { return UnknownVal(); } + if (!T.isNull() && T->isNullPtrType()) { +return svalBuilder.makeZeroVal(T); + } const MemRegion *MR = L.castAs().getRegion(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15007: [analyzer] Improve modelling of nullptr_t in the analyzer. Fix PR25414.
xazax.hun added a comment. In http://reviews.llvm.org/D15007#297183, @NoQ wrote: > There's a little problem with the `shouldNotCrash()` test: the first warning > on `invokeF()` on line 107 generates a sink, and the rest of the function > never gets executed. It's probably a good idea to split it into three > separate tests. Then it'd also warn on line 110. Thank you for pointing this out! I originally used separate test files and did not notice this problem after merging the into the regression test suite. http://reviews.llvm.org/D15007 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14872: PR25575: Make GCC 4.4+ comatible layout for packed bit-fileds of char type
DmitryPolukhin updated this revision to Diff 41222. DmitryPolukhin marked 2 inline comments as done. DmitryPolukhin added a comment. Changed note text message + fixed outdated comment. http://reviews.llvm.org/D14872 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/struct-packed-align.c Index: test/Sema/struct-packed-align.c === --- test/Sema/struct-packed-align.c +++ test/Sema/struct-packed-align.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -// expected-no-diagnostics +// RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-windows-coff -verify // Packed structs. struct s { @@ -138,3 +138,24 @@ extern int n1[sizeof(struct nS) == 9 ? 1 : -1]; extern int n2[__alignof(struct nS) == 1 ? 1 : -1]; #endif + +// Packed attribute shouldn't be ignored for bit-field of char types. +// Note from GCC reference manual: The 4.1, 4.2 and 4.3 series of GCC ignore +// the packed attribute on bit-fields of type char. This has been fixed in +// GCC 4.4 but the change can lead to differences in the structure layout. +// See the documentation of -Wpacked-bitfield-compat for more information. +struct packed_chars { + char a:4; + char b:8 __attribute__ ((packed)); + // expected-warning@-1 {{the offset assigned to packed bit-field member 'b' changed with GCC version 4.4 - the newer offset is used here}} + char c:4; +}; + +#if defined(_WIN32) +// On Windows clang ignores uses MSVC compatible layout in this case. +extern int o1[sizeof(struct packed_chars) == 3 ? 1 : -1]; +extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1]; +#else +extern int o1[sizeof(struct packed_chars) == 2 ? 1 : -1]; +extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1]; +#endif Index: lib/Sema/SemaDeclAttr.cpp === --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -1036,17 +1036,17 @@ TD->addAttr(::new (S.Context) PackedAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); else if (FieldDecl *FD = dyn_cast(D)) { -// If the alignment is less than or equal to 8 bits, the packed attribute -// has no effect. +// Report warning about changed offset in the newer compiler versions. if (!FD->getType()->isDependentType() && !FD->getType()->isIncompleteType() && +FD->isBitField() && S.Context.getTypeAlign(FD->getType()) <= 8) - S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type) -<< Attr.getName() << FD->getType(); -else - FD->addAttr(::new (S.Context) - PackedAttr(Attr.getRange(), S.Context, - Attr.getAttributeSpellingListIndex())); + S.Diag(Attr.getLoc(), + diag::note_attribute_packed_for_bitfield_offset_changed) +<< FD->getDeclName(); + +FD->addAttr(::new (S.Context) PackedAttr( +Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); } else S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName(); } Index: include/clang/Basic/DiagnosticSemaKinds.td === --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -2780,9 +2780,10 @@ "cast to %1 from smaller integer type %0">, InGroup; -def warn_attribute_ignored_for_field_of_type : Warning< - "%0 attribute ignored for field of type %1">, - InGroup; +def note_attribute_packed_for_bitfield_offset_changed : Warning< + "the offset assigned to packed bit-field member %0 changed with GCC " + "version 4.4 - the newer offset is used here">, + InGroup>; def warn_transparent_union_attribute_field_size_align : Warning< "%select{alignment|size}0 of field %1 (%2 bits) does not match the " "%select{alignment|size}0 of the first field in transparent union; " Index: test/Sema/struct-packed-align.c === --- test/Sema/struct-packed-align.c +++ test/Sema/struct-packed-align.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -// expected-no-diagnostics +// RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-windows-coff -verify // Packed structs. struct s { @@ -138,3 +138,24 @@ extern int n1[sizeof(struct nS) == 9 ? 1 : -1]; extern int n2[__alignof(struct nS) == 1 ? 1 : -1]; #endif + +// Packed attribute shouldn't be ignored for bit-field of char types. +// Note from GCC reference manual: The 4.1, 4.2 and 4.3 series of GCC ignore +// the packed attribute on bit-fields of type char. This has been fixed in +// GCC 4.4 but the change can lead to differences in the structure layout. +// See the documentation of -Wpacked-bitfield-compat for more information. +struct packed_chars { + char a:4; + char b:8 __attribute__ ((packed)); + // expected-warning@-1 {{t
Re: [PATCH] D15006: Driver: Better detection of mingw-gcc
ismail added a comment. Tested on openSUSE and it works. Thanks! http://reviews.llvm.org/D15006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15022: [AArch64] Add command-line options for ARMv8.2-A
olista01 created this revision. olista01 added a reviewer: t.p.northover. olista01 added a subscriber: cfe-commits. olista01 set the repository for this revision to rL LLVM. Herald added subscribers: rengolin, aemerson. This adds new values for the -march option (armv8.2a and armv8.2-a, which are aliases of each other), and new suffixes for the -march and -mcpu options (+fp16 and +nofp16), to allow targeting the ARMv8.2-A architecture and it's optional half-precision floating-point extension. Repository: rL LLVM http://reviews.llvm.org/D15022 Files: lib/Driver/Tools.cpp test/Driver/aarch64-cpus.c Index: test/Driver/aarch64-cpus.c === --- test/Driver/aarch64-cpus.c +++ test/Driver/aarch64-cpus.c @@ -114,6 +114,18 @@ // RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s + +// RUN: %clang -target aarch64 -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// GENERICV82A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" + +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s +// GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2031,10 +2031,12 @@ .Case("simd", "+neon") .Case("crc", "+crc") .Case("crypto", "+crypto") + .Case("fp16", "+fullfp16") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") + .Case("nofp16", "-fullfp16") .Default(nullptr); if (result) Features.push_back(result); @@ -2080,6 +2082,8 @@ // ok, no additional features. } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { Features.push_back("+v8.1a"); + } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) { +Features.push_back("+v8.2a"); } else { return false; } Index: test/Driver/aarch64-cpus.c === --- test/Driver/aarch64-cpus.c +++ test/Driver/aarch64-cpus.c @@ -114,6 +114,18 @@ // RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s + +// RUN: %clang -target aarch64 -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// GENERICV82A: "-cc1"{{.*}} "-triple" "aarch6
[PATCH] D15023: [AArch64] Add command-line options for Statistical
olista01 created this revision. olista01 added a reviewer: t.p.northover. olista01 added a subscriber: cfe-commits. olista01 set the repository for this revision to rL LLVM. Herald added subscribers: rengolin, aemerson. This adds the "+profile" and +noprofile" suffixes for the -march and -mcpu options, to allow enabling or disabling the options Statistical Profiling Extension to ARMv8.2-A. Repository: rL LLVM http://reviews.llvm.org/D15023 Files: lib/Driver/Tools.cpp test/Driver/aarch64-cpus.c Index: test/Driver/aarch64-cpus.c === --- test/Driver/aarch64-cpus.c +++ test/Driver/aarch64-cpus.c @@ -126,6 +126,12 @@ // RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s // GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" +// RUN: %clang -target aarch64 -march=armv8.2-a+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-SPE %s +// GENERICV82A-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+spe" +// +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16-SPE %s +// GENERICV82A-FP16-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" "-target-feature" "+spe" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2032,11 +2032,13 @@ .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("fp16", "+fullfp16") + .Case("profile", "+spe") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Case("nofp16", "-fullfp16") + .Case("noprofile", "-spe") .Default(nullptr); if (result) Features.push_back(result); Index: test/Driver/aarch64-cpus.c === --- test/Driver/aarch64-cpus.c +++ test/Driver/aarch64-cpus.c @@ -126,6 +126,12 @@ // RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s // GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" +// RUN: %clang -target aarch64 -march=armv8.2-a+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-SPE %s +// GENERICV82A-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+spe" +// +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16-SPE %s +// GENERICV82A-FP16-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" "-target-feature" "+spe" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2032,11 +2032,13 @@ .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("fp16", "+fullfp16") + .Case("profile", "+spe") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Case("nofp16", "-fullfp16") + .Case("noprofile", "-spe") .Default(nullptr); if (result) Features.push_back(result); ___ cfe-commits ma
Re: [PATCH] D15022: [AArch64] Add command-line options for ARMv8.2-A
t.p.northover accepted this revision. t.p.northover added a comment. This revision is now accepted and ready to land. This looks good, too. Tim. Repository: rL LLVM http://reviews.llvm.org/D15022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15023: [AArch64] Add command-line options for Statistical
t.p.northover accepted this revision. t.p.northover added a comment. This revision is now accepted and ready to land. All obviously good stuff here too. Repository: rL LLVM http://reviews.llvm.org/D15023 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15025: [ThinLTO] Option to invoke ThinLTO backend passes and importing
tejohnson created this revision. tejohnson added reviewers: joker.eph, dexonsmith. tejohnson added subscribers: cfe-commits, davidxl. tejohnson added a dependency: D15024: [ThinLTO] Support for specifying function index from pass manager. Herald added a subscriber: joker.eph. Adds new option -fthinlto-backend= to invoke the LTO pipeline along with function importing via clang using the supplied function summary index file. This supports invoking the parallel ThinLTO backend processes in a distributed build environment via clang. Additionally, this causes the module linker to be invoked on the bitcode file being compiled to perform any necessary promotion and renaming of locals that are exported via the function summary index file. Add a couple tests that confirm we get expected errors when we try to use the new option on a file that isn't bitcode, or specify an invalid index file. The tests also confirm that we trigger the expected function import pass. Depends on D15024 http://reviews.llvm.org/D15025 Files: include/clang/Driver/Options.td include/clang/Driver/Types.h include/clang/Frontend/CodeGenOptions.h lib/CodeGen/BackendUtil.cpp lib/CodeGen/CodeGenAction.cpp lib/Driver/Tools.cpp lib/Driver/Types.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/thinlto_backend.c test/Driver/thinlto_backend.c Index: test/Driver/thinlto_backend.c === --- /dev/null +++ test/Driver/thinlto_backend.c @@ -0,0 +1,12 @@ +// RUN: %clang -target x86_64-unknown-linux -O2 %s -flto=thin -c -o %t.o +// RUN: %clang -target x86_64-unknown-linux -O2 -flto=thin -fuse-ld=gold -o %t %t.o + +// -fthinlto_backend should be passed to cc1 +// RUN: %clang -target x86_64-unknown-linux -O2 -o %t1.o -x ir %t.o -c -fthinlto-backend=%t.thinlto.bc -### 2> %t +// RUN: FileCheck -check-prefix=CHECK-THINLTOBE-ACTION < %t %s +// CHECK-THINLTOBE-ACTION: -fthinlto-backend= + +// Ensure clang driver gives the expected error for incorrect input type +// RUN: not %clang -target x86_64-unknown-linux -O2 -o %t1.o %s -c -fthinlto-backend=%t.thinlto.bc 2> %t +// RUN: FileCheck -check-prefix=CHECK-WARNING < %t %s +// CHECK-WARNING: error: invalid argument '-fthinlto-backend={{.*}}' only allowed with '-x ir' Index: test/CodeGen/thinlto_backend.c === --- /dev/null +++ test/CodeGen/thinlto_backend.c @@ -0,0 +1,17 @@ +// RUN: %clang -target x86_64-unknown-linux -O2 %s -flto=thin -c -o %t.o +// RUN: %clang -target x86_64-unknown-linux -O2 -flto=thin -fuse-ld=gold -o %t %t.o + +// Ensure clang -cc1 give expected error for incorrect input type +// RUN: not %clang_cc1 -target x86_64-unknown-linux -O2 -o %t1.o %s -c -fthinlto-backend=%t.thinlto.bc 2> %t +// RUN: FileCheck -check-prefix=CHECK-WARNING < %t %s +// CHECK-WARNING: error: invalid argument '-fthinlto-backend={{.*}}' only allowed with '-x ir' + +// Ensure we get expected error for missing index file +// RUN: %clang -target x86_64-unknown-linux -O2 -o %t1.o -x ir %t.o -c -fthinlto-backend=bad.thinlto.bc 2> %t +// RUN: FileCheck -check-prefix=CHECK-ERROR < %t %s +// CHECK-ERROR: Error loading index file 'bad.thinlto.bc': No such file or directory + +// Ensure Function Importing pass added +// RUN: %clang -target x86_64-unknown-linux -O2 -o %t1.o -x ir %t.o -c -fthinlto-backend=%t.thinlto.bc -mllvm -debug-pass=Structure 2> %t +// RUN: FileCheck -check-prefix=CHECK-PASS < %t %s +// CHECK-PASS: Function Importing Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -521,6 +521,12 @@ Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ); Opts.EmitFunctionSummary = A && A->containsValue("thin"); + if (Arg *A = Args.getLastArg(OPT_fthinlto_backend_EQ)) { +if (IK != IK_LLVM_IR) + Diags.Report(diag::err_drv_argument_only_allowed_with) + << A->getAsString(Args) << "-x ir"; +Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_backend_EQ); + } Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index: lib/Driver/Types.cpp === --- lib/Driver/Types.cpp +++ lib/Driver/Types.cpp @@ -128,6 +128,19 @@ } } +bool types::isLLVMIR(ID Id) { + switch (Id) { + default: +return false; + + case TY_LLVM_IR: + case TY_LLVM_BC: + case TY_LTO_IR: + case TY_LTO_BC: +return true; + } +} + bool types::isCuda(ID Id) { switch (Id) { default: Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3413,6 +3413,13 @@ Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ); } + if (const Arg *A = Args.getLastArg(options::OPT_fthinlto_backend_EQ)) { +
r254160 - [AArch64] Add command-line options for ARMv8.2-A
Author: olista01 Date: Thu Nov 26 09:36:42 2015 New Revision: 254160 URL: http://llvm.org/viewvc/llvm-project?rev=254160&view=rev Log: [AArch64] Add command-line options for ARMv8.2-A This adds new values for the -march option (armv8.2a and armv8.2-a, which are aliases of each other), and new suffixes for the -march and -mcpu options (+fp16 and +nofp16), to allow targeting the ARMv8.2-A architecture and it's optional half-precision floating-point extension. Differential Revision: http://reviews.llvm.org/D15022 Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/aarch64-cpus.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=254160&r1=254159&r2=254160&view=diff == --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Nov 26 09:36:42 2015 @@ -2031,10 +2031,12 @@ static bool DecodeAArch64Features(const .Case("simd", "+neon") .Case("crc", "+crc") .Case("crypto", "+crypto") + .Case("fp16", "+fullfp16") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") + .Case("nofp16", "-fullfp16") .Default(nullptr); if (result) Features.push_back(result); @@ -2080,6 +2082,8 @@ getAArch64ArchFeaturesFromMarch(const Dr // ok, no additional features. } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { Features.push_back("+v8.1a"); + } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) { +Features.push_back("+v8.2a"); } else { return false; } Modified: cfe/trunk/test/Driver/aarch64-cpus.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=254160&r1=254159&r2=254160&view=diff == --- cfe/trunk/test/Driver/aarch64-cpus.c (original) +++ cfe/trunk/test/Driver/aarch64-cpus.c Thu Nov 26 09:36:42 2015 @@ -114,6 +114,18 @@ // RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s + +// RUN: %clang -target aarch64 -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// GENERICV82A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" + +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s +// GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15022: [AArch64] Add command-line options for ARMv8.2-A
This revision was automatically updated to reflect the committed changes. Closed by commit rL254160: [AArch64] Add command-line options for ARMv8.2-A (authored by olista01). Changed prior to commit: http://reviews.llvm.org/D15022?vs=41243&id=41257#toc Repository: rL LLVM http://reviews.llvm.org/D15022 Files: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/aarch64-cpus.c Index: cfe/trunk/lib/Driver/Tools.cpp === --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -2031,10 +2031,12 @@ .Case("simd", "+neon") .Case("crc", "+crc") .Case("crypto", "+crypto") + .Case("fp16", "+fullfp16") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") + .Case("nofp16", "-fullfp16") .Default(nullptr); if (result) Features.push_back(result); @@ -2080,6 +2082,8 @@ // ok, no additional features. } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { Features.push_back("+v8.1a"); + } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) { +Features.push_back("+v8.2a"); } else { return false; } Index: cfe/trunk/test/Driver/aarch64-cpus.c === --- cfe/trunk/test/Driver/aarch64-cpus.c +++ cfe/trunk/test/Driver/aarch64-cpus.c @@ -114,6 +114,18 @@ // RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s + +// RUN: %clang -target aarch64 -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s +// GENERICV82A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" + +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s +// GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: cfe/trunk/lib/Driver/Tools.cpp === --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -2031,10 +2031,12 @@ .Case("simd", "+neon") .Case("crc", "+crc") .Case("crypto", "+crypto") + .Case("fp16", "+fullfp16") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") + .Case("nofp16", "-fullfp16") .Default(nullptr); if (result) Features.push_back(result); @@ -2080,6 +2082,8 @@ // ok, no additional features. } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { Features.push_back("+v8.1a"); + } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) { +Features.push_back("+v8.2a"); } else { return false; } Index: cfe/trunk/test/Driver/aarch64-cpus.c === --- cfe/trunk/test/Driver/aarch64-cpus.c +++ cfe/trunk/test/Driver/aarch64-cpus.c @@ -114,6 +114,18 @@ // RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -targ
r254161 - [AArch64] Add command-line options for Statistical Profiling Extension
Author: olista01 Date: Thu Nov 26 09:38:54 2015 New Revision: 254161 URL: http://llvm.org/viewvc/llvm-project?rev=254161&view=rev Log: [AArch64] Add command-line options for Statistical Profiling Extension This adds the "+profile" and +noprofile" suffixes for the -march and -mcpu options, to allow enabling or disabling the options Statistical Profiling Extension to ARMv8.2-A. Differential Revision: http://reviews.llvm.org/D15023 Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/aarch64-cpus.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=254161&r1=254160&r2=254161&view=diff == --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Nov 26 09:38:54 2015 @@ -2032,11 +2032,13 @@ static bool DecodeAArch64Features(const .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("fp16", "+fullfp16") + .Case("profile", "+spe") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Case("nofp16", "-fullfp16") + .Case("noprofile", "-spe") .Default(nullptr); if (result) Features.push_back(result); Modified: cfe/trunk/test/Driver/aarch64-cpus.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=254161&r1=254160&r2=254161&view=diff == --- cfe/trunk/test/Driver/aarch64-cpus.c (original) +++ cfe/trunk/test/Driver/aarch64-cpus.c Thu Nov 26 09:38:54 2015 @@ -126,6 +126,12 @@ // RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s // GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" +// RUN: %clang -target aarch64 -march=armv8.2-a+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-SPE %s +// GENERICV82A-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+spe" +// +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16-SPE %s +// GENERICV82A-FP16-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" "-target-feature" "+spe" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15023: [AArch64] Add command-line options for Statistical
This revision was automatically updated to reflect the committed changes. Closed by commit rL254161: [AArch64] Add command-line options for Statistical Profiling Extension (authored by olista01). Changed prior to commit: http://reviews.llvm.org/D15023?vs=41244&id=41258#toc Repository: rL LLVM http://reviews.llvm.org/D15023 Files: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/aarch64-cpus.c Index: cfe/trunk/test/Driver/aarch64-cpus.c === --- cfe/trunk/test/Driver/aarch64-cpus.c +++ cfe/trunk/test/Driver/aarch64-cpus.c @@ -126,6 +126,12 @@ // RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s // GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" +// RUN: %clang -target aarch64 -march=armv8.2-a+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-SPE %s +// GENERICV82A-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+spe" +// +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16-SPE %s +// GENERICV82A-FP16-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" "-target-feature" "+spe" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: cfe/trunk/lib/Driver/Tools.cpp === --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -2032,11 +2032,13 @@ .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("fp16", "+fullfp16") + .Case("profile", "+spe") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Case("nofp16", "-fullfp16") + .Case("noprofile", "-spe") .Default(nullptr); if (result) Features.push_back(result); Index: cfe/trunk/test/Driver/aarch64-cpus.c === --- cfe/trunk/test/Driver/aarch64-cpus.c +++ cfe/trunk/test/Driver/aarch64-cpus.c @@ -126,6 +126,12 @@ // RUN: %clang -target aarch64 -march=armv8.2-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16 %s // GENERICV82A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" +// RUN: %clang -target aarch64 -march=armv8.2-a+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-SPE %s +// GENERICV82A-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+spe" +// +// RUN: %clang -target aarch64 -march=armv8.2-a+fp16+profile -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-FP16-SPE %s +// GENERICV82A-FP16-SPE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a" "-target-feature" "+fullfp16" "-target-feature" "+spe" + // == Check whether -march accepts mixed-case values. // RUN: %clang -target aarch64_be -march=ARMV8.1A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s // RUN: %clang -target aarch64_be -march=ARMV8.1-A -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s Index: cfe/trunk/lib/Driver/Tools.cpp === --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -2032,11 +2032,13 @@ .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("fp16", "+fullfp16") + .Case("profile", "+spe") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Case("nofp16", "-fullfp16") + .Case("noprofile", "-spe") .Default(nullptr); if (result) Features.push_back(result); __
[A fix related to closing C++ header file descriptors on windows]
I use clang 3.6.2 with qt creator 3.5.1 on windows 7 for parsing code in this IDE. It works well. However, I can see that clang keeps a few times some file descriptors opened on c++ header files (h files) after having parsed a cpp file (that includes these h files). The effect is that we cannot save these h files, what is quite frustrating when using an IDE. After debugging clang, I remarked that there was a file descriptor leak in the method Preprocessor::HandleIncludeDirective (file tools/clang/lib/Lex/PPDirectives.cpp) The object 'FileEntry *File' is created (for a given h file) and after some checks, the regular treatment calls EnterSourceFile. The File object is detroyed during this call (quite deeply in the stack) However, when some errors occur, the execution path goes through early returns and other code pathes. In this case, the file descriptor associated to File is not closed and the file descriptor remains open. So I did a correction that uses RAII in order to have the file descriptor closed. So I wrapped 'FileEntry *File' in a dedicated 'FileEntryCloser fileEntryCloser(File)' On regular treatment, the closer is released: // If all is good, enter the new file! if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation())) { fileEntryCloser.release(); return; } Otherwise, the file descriptor is closed ~FileEntryCloser() { if(m_File) m_File->closeFile(); } Now, I have no more remaining file descriptors ... Would it be possible to have an evaluation on that? Thanks in advance. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] Don't crash when dumping objc_bridge_related attributes
On Wed, Nov 25, 2015 at 6:13 PM, Joe Ranieri wrote: > Clang's AST dumping currently crashes when dumping objc_bridge_related > attributes where the class method and instance method fields are left > empty. The attached patch marks the two arguments as optional and > updates TableGen to understand the optional flag for identifier > attribute arguments when generating the dump function. LGTM, thank you! Do you have commit privileges, or would you like me to commit on your behalf? ~Aaron ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13330: Implement __attribute__((unique_instantiation))
loladiro updated this revision to Diff 41261. loladiro added a comment. Rebased and made the small suggested changes to the test cases. http://reviews.llvm.org/D13330 Files: include/clang/AST/ASTContext.h include/clang/Basic/Attr.td include/clang/Basic/AttrDocs.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/AttributeList.h lib/AST/ASTContext.cpp lib/CodeGen/CGVTables.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/unique-instantiation.cpp test/SemaCXX/unique-instantiations.cpp utils/TableGen/ClangAttrEmitter.cpp Index: utils/TableGen/ClangAttrEmitter.cpp === --- utils/TableGen/ClangAttrEmitter.cpp +++ utils/TableGen/ClangAttrEmitter.cpp @@ -2371,6 +2371,8 @@ case Func | ObjCMethod | Param: return "ExpectedFunctionMethodOrParameter"; case Func | ObjCMethod: return "ExpectedFunctionOrMethod"; case Func | Var: return "ExpectedVariableOrFunction"; +case Func | Class: + return "ExpectedFunctionOrClass"; // If not compiling for C++, the class portion does not apply. case Func | Var | Class: Index: test/SemaCXX/unique-instantiations.cpp === --- /dev/null +++ test/SemaCXX/unique-instantiations.cpp @@ -0,0 +1,34 @@ +// RUN: %clang -cc1 -std=c++11 -fsyntax-only -verify %s + +// Correct usage +template +struct foo {}; +extern template struct __attribute__((unique_instantiation)) foo; +template struct __attribute__((unique_instantiation)) foo; + +// Various examples of incorrect usage +template +struct foo1 {}; +template struct __attribute__((unique_instantiation)) foo1; // expected-error{{'unique_instantiation' attribute on an explicit instantiation requires a previous explicit instantiation declaration}} + +template +struct foo2 {}; +extern template struct foo2;// expected-note{{previous explicit instantiation is here}} +template struct __attribute__((unique_instantiation)) foo2; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct foo3 {}; +extern template struct __attribute__((unique_instantiation)) foo3; // expected-note{{previous explicit instantiation is here}} +extern template struct foo3; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct __attribute__((unique_instantiation)) foo4 {}; // expected-error{{'unique_instantiation' attribute only applies to explicit template declarations or definitions}} + +template +struct foo5 {}; +extern template struct __attribute__((unique_instantiation)) foo5; // expected-note{{previous explicit instantiation is here}} +template struct foo5; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct foo6 {}; +extern template struct __attribute__((unique_instantiation(16))) foo6;// expected-error{{'unique_instantiation' attribute takes no arguments}} Index: test/CodeGenCXX/unique-instantiation.cpp === --- /dev/null +++ test/CodeGenCXX/unique-instantiation.cpp @@ -0,0 +1,38 @@ +// RUN: %clang -std=c++11 -emit-llvm -c -S -o - %s | FileCheck %s + +template +struct foo { + T x; + T getX() { return x; } + struct bar { +T y; +bar(T y) : y(y) {} + }; +}; +template +T bar(); + +// CHECK: define i32 @_ZN3fooIiE4getXEv +// CHECK: define void @_ZN3fooIiE3barC2Ei +// CHECK-NOT: define weak_odr i32 @_ZN3fooIiE4getXEv +// CHECK-NOT: define weak_odr void @_ZN3fooIiE3barC2Ei +extern template struct __attribute__((unique_instantiation)) foo; +template struct __attribute__((unique_instantiation)) foo; + +extern template __attribute__((unique_instantiation)) int bar(); + +template +T bar() { + return (T)0; +} + +// CHECK: define i32 @_Z3barIiET_v() +// CHECK-NOT: define weak_odr i32 @_Z3barIiET_v() +template __attribute__((unique_instantiation)) int bar(); + +int footest() { + auto var = foo{5}; + auto var2 = foo::bar{5}; + auto x = bar(); + return var.getX(); +} Index: lib/Sema/SemaTemplate.cpp === --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -7398,20 +7398,22 @@ Specialization->setExternLoc(ExternLoc); Specialization->setTemplateKeywordLoc(TemplateLoc); Specialization->setRBraceLoc(SourceLocation()); + Specialization->setTemplateSpecializationKind(TSK); if (Attr) ProcessDeclAttributeList(S, Specialization, Attr); + if (PrevDecl) +mergeDeclAttributes(Specialization, PrevDecl); + // Add
Re: [PATCH] Don't crash when dumping objc_bridge_related attributes
On Thu, Nov 26, 2015 at 11:29 AM, Aaron Ballman wrote: > On Wed, Nov 25, 2015 at 6:13 PM, Joe Ranieri wrote: >> Clang's AST dumping currently crashes when dumping objc_bridge_related >> attributes where the class method and instance method fields are left >> empty. The attached patch marks the two arguments as optional and >> updates TableGen to understand the optional flag for identifier >> attribute arguments when generating the dump function. > > LGTM, thank you! Do you have commit privileges, or would you like me > to commit on your behalf? > > ~Aaron Please commit on my behalf. -- Joe Ranieri ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15006: Driver: Better detection of mingw-gcc
yaron.keren added a comment. findGccDir() can return llvm::ErrorOr and then all Base assignments happen at the same if-elseif-else: if (getDriver().SysRoot.size()) Base = getDriver().SysRoot; else if (llvm::ErrorOr GPPName = findGccDir()) Base = llvm::sys::path::parent_path( llvm::sys::path::parent_path(GPPName.get())); else Base = llvm::sys::path::parent_path(getDriver().getInstalledDir()); Then, findGccDir() is actually findGcc(). About tests, adding empty script "gcc" with x set in the directory structure, and adding the directory to the path at start of the LIT test may work. It will fail on Windows so try this with a new test file so we can XFAIL:windows only the new one if required. http://reviews.llvm.org/D15006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15025: [ThinLTO] Option to invoke ThinLTO backend passes and importing
joker.eph added inline comments. Comment at: lib/CodeGen/BackendUtil.cpp:308 @@ +307,3 @@ +return; + } + It does not seem to be nicely integrated within the context of this function. What about all the options set just a few line below? It is not clear if `CodeGenOpts.DisableLLVMOpts` is well honored either. Comment at: lib/CodeGen/CodeGenAction.cpp:30 @@ -29,2 +29,3 @@ #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/FunctionInfo.h" #include "llvm/IR/Module.h" Not well sorted :) Comment at: lib/CodeGen/CodeGenAction.cpp:190 @@ -169,3 +189,3 @@ [=](const DiagnosticInfo &DI) { - linkerDiagnosticHandler(DI, LinkModule); + linkerDiagnosticHandler(DI, LinkModule, Diags); }, Is this an unrelated change to the `-fthinlto-backend` one that could be committed separately? Comment at: lib/CodeGen/CodeGenAction.cpp:821 @@ +820,3 @@ +linkerDiagnosticHandler(DI, TheModule.get(), +CI.getDiagnostics()); + }, llvm::Linker::Flags::None, Index.get())) This lambda is the same as the one just above for `getFunctionIndexForFile`, name it and define it once? Comment at: lib/CodeGen/CodeGenAction.cpp:826 @@ +825,3 @@ + TheModule = std::move(Combined); +} + So for the renaming we need to duplicate completely the module? It cannot be done by morphing the existing module in place? That seems quite inefficient :( http://reviews.llvm.org/D15025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13330: Implement __attribute__((unique_instantiation))
loladiro updated this revision to Diff 41265. loladiro added a comment. Add support for variable templates http://reviews.llvm.org/D13330 Files: include/clang/AST/ASTContext.h include/clang/Basic/Attr.td include/clang/Basic/AttrDocs.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/AttributeList.h lib/AST/ASTContext.cpp lib/CodeGen/CGVTables.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/unique-instantiation.cpp test/SemaCXX/unique-instantiations.cpp utils/TableGen/ClangAttrEmitter.cpp Index: utils/TableGen/ClangAttrEmitter.cpp === --- utils/TableGen/ClangAttrEmitter.cpp +++ utils/TableGen/ClangAttrEmitter.cpp @@ -2371,6 +2371,8 @@ case Func | ObjCMethod | Param: return "ExpectedFunctionMethodOrParameter"; case Func | ObjCMethod: return "ExpectedFunctionOrMethod"; case Func | Var: return "ExpectedVariableOrFunction"; +case Func | Class: + return "ExpectedFunctionOrClass"; // If not compiling for C++, the class portion does not apply. case Func | Var | Class: Index: test/SemaCXX/unique-instantiations.cpp === --- /dev/null +++ test/SemaCXX/unique-instantiations.cpp @@ -0,0 +1,48 @@ +// RUN: %clang -cc1 -std=c++14 -fsyntax-only -verify %s + +// Correct usage +template +struct foo {}; +extern template struct __attribute__((unique_instantiation)) foo; +template struct __attribute__((unique_instantiation)) foo; + +template +T pi = T(3.1415926535897932385); +extern template __attribute__((unique_instantiation)) float pi; +template __attribute__((unique_instantiation)) float pi; + +// Usages on non-templates +float __attribute__((unique_instantiation)) notpi(2.71828182845904523536028747135); // expected-error{{'unique_instantiation' attribute only applies to explicit template declarations or definitions}} +struct __attribute__((unique_instantiation)) bar {};// expected-error{{'unique_instantiation' attribute only applies to explicit template declarations or definitions}} +void __attribute__((unique_instantiation)) func() {}// expected-error{{'unique_instantiation' attribute only applies to explicit template declarations or definitions}} + +// Usages that violate one of the conditions required conditions +template +struct foo1 {}; +template struct __attribute__((unique_instantiation)) foo1; // expected-error{{'unique_instantiation' attribute on an explicit instantiation requires a previous explicit instantiation declaration}} + +template +T pi1 = T(3.1415926535897932385); +template __attribute__((unique_instantiation)) float pi1; // expected-error{{'unique_instantiation' attribute on an explicit instantiation requires a previous explicit instantiation declaration}} + +template +struct foo2 {}; +extern template struct foo2;// expected-note{{previous explicit instantiation is here}} +template struct __attribute__((unique_instantiation)) foo2; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct foo3 {}; +extern template struct __attribute__((unique_instantiation)) foo3; // expected-note{{previous explicit instantiation is here}} +extern template struct foo3; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct __attribute__((unique_instantiation)) foo4 {}; // expected-error{{'unique_instantiation' attribute only applies to explicit template declarations or definitions}} + +template +struct foo5 {}; +extern template struct __attribute__((unique_instantiation)) foo5; // expected-note{{previous explicit instantiation is here}} +template struct foo5; // expected-error{{'unique_instantiation' attribute must be specified for all declarations and definitions of this explicit template instantiation}} + +template +struct foo6 {}; +extern template struct __attribute__((unique_instantiation(16))) foo6; // expected-error{{'unique_instantiation' attribute takes no arguments}} Index: test/CodeGenCXX/unique-instantiation.cpp === --- /dev/null +++ test/CodeGenCXX/unique-instantiation.cpp @@ -0,0 +1,45 @@ +// RUN: %clang -std=c++14 -emit-llvm -c -S -o - %s | FileCheck %s + +// CHECK: @_Z2piIfE = global float +// CHECK-NOT: @_Z2piIfE = weak_odr global float +template +T pi = T(3.1415926535897932385); +extern template __attribute__((unique_instantiation)) float pi; +template __attribute__((unique_instantiation)) float pi; + +template +struct foo { + T x; + T getX() { return x; } + struct bar { +T y;
r254173 - docs: Remove references to the long-defunct LLVM_USED_LIBS
Author: bogner Date: Thu Nov 26 13:52:24 2015 New Revision: 254173 URL: http://llvm.org/viewvc/llvm-project?rev=254173&view=rev Log: docs: Remove references to the long-defunct LLVM_USED_LIBS LLVM_USED_LIBS hasn't done anything since 2012, stop telling people to set it in the docs. Modified: cfe/trunk/docs/LibASTMatchersTutorial.rst cfe/trunk/docs/RAVFrontendAction.rst Modified: cfe/trunk/docs/LibASTMatchersTutorial.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersTutorial.rst?rev=254173&r1=254172&r2=254173&view=diff == --- cfe/trunk/docs/LibASTMatchersTutorial.rst (original) +++ cfe/trunk/docs/LibASTMatchersTutorial.rst Thu Nov 26 13:52:24 2015 @@ -108,7 +108,6 @@ CMakeLists.txt should have the following :: set(LLVM_LINK_COMPONENTS support) - set(LLVM_USED_LIBS clangTooling clangBasic clangAST) add_clang_executable(loop-convert LoopConvert.cpp Modified: cfe/trunk/docs/RAVFrontendAction.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/RAVFrontendAction.rst?rev=254173&r1=254172&r2=254173&view=diff == --- cfe/trunk/docs/RAVFrontendAction.rst (original) +++ cfe/trunk/docs/RAVFrontendAction.rst Thu Nov 26 13:52:24 2015 @@ -205,10 +205,10 @@ following CMakeLists.txt to link it: :: -set(LLVM_USED_LIBS clangTooling) - add_clang_executable(find-class-decls FindClassDecls.cpp) +target_link_libraries(find-class-decls clangTooling) + When running this tool over a small code snippet it will output all declarations of a class n::m::C it found: ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15029: [OpenMP] Parsing and sema support for thread_limit clause
kkwli0 created this revision. kkwli0 added reviewers: ABataev, hfinkel, sfantao, fraggamuffin, rsmith. kkwli0 added a subscriber: cfe-commits. This patch is to add parsing and sema support for thread_limit clause. http://reviews.llvm.org/D15029 Files: include/clang/AST/OpenMPClause.h include/clang/AST/RecursiveASTVisitor.h include/clang/Basic/OpenMPKinds.def include/clang/Sema/Sema.h lib/AST/StmtPrinter.cpp lib/AST/StmtProfile.cpp lib/Basic/OpenMPKinds.cpp lib/CodeGen/CGStmtOpenMP.cpp lib/Parse/ParseOpenMP.cpp lib/Sema/SemaOpenMP.cpp lib/Sema/TreeTransform.h lib/Serialization/ASTReaderStmt.cpp lib/Serialization/ASTWriterStmt.cpp test/OpenMP/teams_ast_print.cpp test/OpenMP/teams_thread_limit_messages.cpp tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -2079,6 +2079,10 @@ Visitor->AddStmt(C->getNumTeams()); } +void OMPClauseEnqueue::VisitOMPThreadLimitClause(const OMPThreadLimitClause *C) { + Visitor->AddStmt(C->getThreadLimit()); +} + template void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { for (const auto *I : Node->varlists()) { Index: test/OpenMP/teams_thread_limit_messages.cpp === --- /dev/null +++ test/OpenMP/teams_thread_limit_messages.cpp @@ -0,0 +1,111 @@ +// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 100 -o - %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} + +template // expected-note {{declared here}} +T tmain(T argc) { + char **a; +#pragma omp target +#pragma omp teams thread_limit(C) + foo(); +#pragma omp target +#pragma omp teams thread_limit(T) // expected-error {{'T' does not refer to a value}} + foo(); +#pragma omp target +#pragma omp teams thread_limit // expected-error {{expected '(' after 'thread_limit'}} + foo(); +#pragma omp target +#pragma omp teams thread_limit( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams thread_limit() // expected-error {{expected expression}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(argc)) // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(argc > 0 ? a[1] : a[2]) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(argc + argc) + foo(); +#pragma omp target +#pragma omp teams thread_limit(argc), thread_limit (argc+1) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'thread_limit' clause}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(-2) // expected-error {{argument to 'thread_limit' clause must be a positive integer value}} + foo(); +#pragma omp target +#pragma omp teams thread_limit(-10u) + foo(); +#pragma omp target +#pragma omp teams thread_limit(3.14) // expected-error 2 {{expression must have integral or unscoped enumeration type, not 'double'}} + foo(); + + return 0; +} + +int main(int argc, char **argv) { +#pragma omp target +#pragma omp teams thread_limit // expected-error {{expected '(' after 'thread_limit'}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit () // expected-error {{expected expression}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (argc)) // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (argc > 0 ? argv[1] : argv[2]) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (argc + argc) + foo(); + +#pragma omp target +#pragma omp teams thread_limit (argc), thread_limit (argc+1) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'thread_limit' clause}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (S1) // expected-error {{'S1' does not refer to a value}} + foo(); + +#pragma omp target +#pragma omp teams thread_limit (-2) // expected-error {{argument to 'thread_limit' clause must be
Re: [libcxx] r254119 - Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. vector/unordered/list/string already do this.
This used to build and now doesn't: std::map, std::allocator>> m; Maybe the static assert text could say something slightly more friendly that hints at the pair's first entry having to be const? This is probably difficult to figure out unless you know this already. (Real-life version: https://code.google.com/p/chromium/issues/detail?id=562227) On Wed, Nov 25, 2015 at 8:24 PM, Marshall Clow via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: marshall > Date: Wed Nov 25 19:24:04 2015 > New Revision: 254119 > > URL: http://llvm.org/viewvc/llvm-project?rev=254119&view=rev > Log: > Add static_assert to set/multiset/map/multimap/forward_list/deque that the > allocator's value_type match the container's value_type. > vector/unordered/list/string already do this. Add tests for all the > containers to verify this. > > Added: > > libcxx/trunk/test/std/containers/associative/map/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/associative/multimap/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/associative/multiset/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/associative/set/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/sequences/list/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/unord/unord.map/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/unord/unord.multimap/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/unord/unord.multiset/allocator_mismatch.fail.cpp > > libcxx/trunk/test/std/containers/unord/unord.set/allocator_mismatch.fail.cpp > libcxx/trunk/test/std/strings/basic.string/allocator_mismatch.fail.cpp > Modified: > libcxx/trunk/include/deque > libcxx/trunk/include/forward_list > libcxx/trunk/include/map > libcxx/trunk/include/set > > Modified: libcxx/trunk/include/deque > URL: > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=254119&r1=254118&r2=254119&view=diff > > == > --- libcxx/trunk/include/deque (original) > +++ libcxx/trunk/include/deque Wed Nov 25 19:24:04 2015 > @@ -1196,6 +1196,9 @@ public: > typedef _Tp value_type; > typedef _Allocator allocator_type; > > +static_assert((is_same value_type>::value), > + "Allocator::value_type must be same type as > value_type"); > + > typedef __deque_base __base; > > typedef typename __base::__alloc_traits__alloc_traits; > > Modified: libcxx/trunk/include/forward_list > URL: > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/forward_list?rev=254119&r1=254118&r2=254119&view=diff > > == > --- libcxx/trunk/include/forward_list (original) > +++ libcxx/trunk/include/forward_list Wed Nov 25 19:24:04 2015 > @@ -537,6 +537,9 @@ public: > typedef _Tpvalue_type; > typedef _Alloc allocator_type; > > +static_assert((is_same value_type>::value), > + "Allocator::value_type must be same type as > value_type"); > + > typedef value_type& > reference; > typedef const value_type& > const_reference; > typedef typename allocator_traits::pointer > pointer; > > Modified: libcxx/trunk/include/map > URL: > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/map?rev=254119&r1=254118&r2=254119&view=diff > > == > --- libcxx/trunk/include/map (original) > +++ libcxx/trunk/include/map Wed Nov 25 19:24:04 2015 > @@ -840,6 +840,9 @@ public: > typedef value_type& reference; > typedef const value_type&const_reference; > > +static_assert((is_same value_type>::value), > + "Allocator::value_type must be same type as > value_type"); > + > class _LIBCPP_TYPE_VIS_ONLY value_compare > : public binary_function > { > @@ -1696,6 +1699,9 @@ public: > typedef value_type& reference; > typedef const value_type&const_reference; > > +static_assert((is_same value_type>::value), > + "Allocator::value_type must be same type as > value_type"); > + > class _LIBCPP_TYPE_VIS_ONLY value_compare > : public binary_function > { > > Modified: libcxx/trunk/include/set > URL: > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/set?rev=254119&r1=254118&r2=254119&view=diff > > == > --- libcxx/trunk/include/set (original) > +++ libcxx/trunk/include/set Wed Nov 25 19:24:04 2015 > @@ -409,6
Re: [PATCH] D14325: [clang-format] Do not align assignments that aren't after the same number of commas. (Closes: 25329)
berenm updated this revision to Diff 41271. berenm added a comment. [clang-format] alignConsecutiveXXX: replace the buggy paren / braces counter with a better scope tracker. http://reviews.llvm.org/D14325 Files: lib/Format/WhitespaceManager.cpp lib/Format/WhitespaceManager.h unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp === --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -8659,7 +8659,7 @@ Alignment); verifyFormat("class C {\n" "public:\n" - " int i = 1;\n" + " int i= 1;\n" " virtual void f() = 0;\n" "};", Alignment); @@ -8708,6 +8708,19 @@ " loongParameterB);\n" "int j = 2;", Alignment); + + verifyFormat("template \n" + "auto foo() {}\n", + Alignment); + verifyFormat("int a, b = 1;\n" + "int c = 2;\n" + "int dd = 3;\n", + Alignment); + verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" + "float b[1][] = {{3.f}};\n", + Alignment); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { @@ -8908,6 +8921,47 @@ "int myvar = 1;", Alignment); Alignment.ColumnLimit = 80; + Alignment.AlignConsecutiveAssignments = false; + + verifyFormat( + "template \n" + "auto foo() {}\n", + Alignment); + verifyFormat("float a, b = 1;\n" + "int c = 2;\n" + "int dd = 3;\n", + Alignment); + verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" + "float b[1][] = {{3.f}};\n", + Alignment); + Alignment.AlignConsecutiveAssignments = true; + verifyFormat("float a, b = 1;\n" + "int c = 2;\n" + "int dd = 3;\n", + Alignment); + verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" + "float b[1][] = {{3.f}};\n", + Alignment); + Alignment.AlignConsecutiveAssignments = false; + + Alignment.ColumnLimit = 30; + Alignment.BinPackParameters = false; + verifyFormat("void foo(float a,\n" + " float b,\n" + " int c,\n" + " uint32_t *d) {\n" + " int * e = 0;\n" + " float f = 0;\n" + " double g = 0;\n" + "}\n" + "void bar(ino_t a,\n" + " int b,\n" + " uint32_t *c,\n" + " bool d) {}\n", + Alignment); + Alignment.BinPackParameters = true; + Alignment.ColumnLimit = 80; } TEST_F(FormatTest, LinuxBraceBreaking) { Index: lib/Format/WhitespaceManager.h === --- lib/Format/WhitespaceManager.h +++ lib/Format/WhitespaceManager.h @@ -168,20 +168,9 @@ /// \brief Align consecutive assignments over all \c Changes. void alignConsecutiveAssignments(); - /// \brief Align consecutive assignments from change \p Start to change \p End - /// at - /// the specified \p Column. - void alignConsecutiveAssignments(unsigned Start, unsigned End, - unsigned Column); - /// \brief Align consecutive declarations over all \c Changes. void alignConsecutiveDeclarations(); - /// \brief Align consecutive declarations from change \p Start to change \p - /// End at the specified \p Column. - void alignConsecutiveDeclarations(unsigned Start, unsigned End, -unsigned Column); - /// \brief Align trailing comments over all \c Changes. void alignTrailingComments(); Index: lib/Format/WhitespaceManager.cpp === --- lib/Format/WhitespaceManager.cpp +++ lib/Format/WhitespaceManager.cpp @@ -148,125 +148,24 @@ } } -// Walk through all of the changes and find sequences of "=" to align. To do -// so, keep track of the lines and whether or not an "=" was found on align. If -// a "=" is found on a line, extend the current sequence. If the current line -// cannot be part of a sequence, e.g. because there is an empty line before it -// or it contains non-assignments, finalize the previous sequence. -// -// FIXME: The code between assignment and declaration alignment is mostly -// duplicated and would benefit from factorization. -void WhitespaceManager::alignConsecutiveAssignments() { - if (!Style.AlignConsecutiveAssignments) -return; - - unsigned MinColumn = 0; - unsigned MaxColumn = UINT_MAX; - unsigned StartOfSequence = 0; - unsigned EndOfSequence = 0; - bool FoundAssignmentOnLine = false; - bool FoundLeftBraceOnLine = false; - bool FoundLeftParenOnLine = false; - - // Aligns a sequence o
Re: [PATCH] D14325: [clang-format] Do not align assignments that aren't after the same number of commas. (Closes: 25329)
berenm added a comment. Updated the diff with a fix for the issue reported in http://lists.llvm.org/pipermail/cfe-dev/2015-November/046057.html http://reviews.llvm.org/D14325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r254181 - Test commit
Author: pgousseau Date: Thu Nov 26 16:08:58 2015 New Revision: 254181 URL: http://llvm.org/viewvc/llvm-project?rev=254181&view=rev Log: Test commit Remove tabs. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=254181&r1=254180&r2=254181&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp Thu Nov 26 16:08:58 2015 @@ -86,8 +86,7 @@ public: // Helpers. bool checkCall_strCommon(const CallExpr *CE, const FunctionDecl *FD); - typedef void (WalkAST::*FnCheck)(const CallExpr *, - const FunctionDecl *); + typedef void (WalkAST::*FnCheck)(const CallExpr *, const FunctionDecl *); // Checker-specific methods. void checkLoopConditionForFloat(const ForStmt *FS); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r254182 - [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic
Author: mgehre Date: Thu Nov 26 16:32:11 2015 New Revision: 254182 URL: http://llvm.org/viewvc/llvm-project?rev=254182&view=rev Log: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic Summary: Inside a range-based for-loop over an array, the compiler generates pointer arithmetic (end = array + size). Don't flag this. Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D14582 Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp?rev=254182&r1=254181&r2=254182&view=diff == --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp Thu Nov 26 16:32:11 2015 @@ -22,9 +22,11 @@ void ProBoundsPointerArithmeticCheck::re // Flag all operators +, -, +=, -=, ++, -- that result in a pointer Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"), - hasOperatorName("+="), hasOperatorName("-=")), - hasType(pointerType())) + binaryOperator( + anyOf(hasOperatorName("+"), hasOperatorName("-"), +hasOperatorName("+="), hasOperatorName("-=")), + hasType(pointerType()), + unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())) .bind("expr"), this); @@ -36,8 +38,10 @@ void ProBoundsPointerArithmeticCheck::re // Array subscript on a pointer (not an array) is also pointer arithmetic Finder->addMatcher( - arraySubscriptExpr(hasBase(ignoringImpCasts(anyOf(hasType(pointerType()), - hasType(decayedType(hasDecayedType(pointerType( + arraySubscriptExpr( + hasBase(ignoringImpCasts( + anyOf(hasType(pointerType()), +hasType(decayedType(hasDecayedType(pointerType( .bind("expr"), this); } Modified: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp?rev=254182&r1=254181&r2=254182&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp Thu Nov 26 16:32:11 2015 @@ -84,4 +84,6 @@ void okay() { i = j - 1; auto diff = p - q; // OK, result is arithmetic + + for(int ii : a) ; // OK, pointer arithmetic generated by compiler } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14582: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic
This revision was automatically updated to reflect the committed changes. Closed by commit rL254182: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore… (authored by mgehre). Changed prior to commit: http://reviews.llvm.org/D14582?vs=40448&id=41272#toc Repository: rL LLVM http://reviews.llvm.org/D14582 Files: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp === --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp @@ -84,4 +84,6 @@ i = j - 1; auto diff = p - q; // OK, result is arithmetic + + for(int ii : a) ; // OK, pointer arithmetic generated by compiler } Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp @@ -22,9 +22,11 @@ // Flag all operators +, -, +=, -=, ++, -- that result in a pointer Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"), - hasOperatorName("+="), hasOperatorName("-=")), - hasType(pointerType())) + binaryOperator( + anyOf(hasOperatorName("+"), hasOperatorName("-"), +hasOperatorName("+="), hasOperatorName("-=")), + hasType(pointerType()), + unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())) .bind("expr"), this); @@ -36,8 +38,10 @@ // Array subscript on a pointer (not an array) is also pointer arithmetic Finder->addMatcher( - arraySubscriptExpr(hasBase(ignoringImpCasts(anyOf(hasType(pointerType()), - hasType(decayedType(hasDecayedType(pointerType( + arraySubscriptExpr( + hasBase(ignoringImpCasts( + anyOf(hasType(pointerType()), +hasType(decayedType(hasDecayedType(pointerType( .bind("expr"), this); } Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp === --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp @@ -84,4 +84,6 @@ i = j - 1; auto diff = p - q; // OK, result is arithmetic + + for(int ii : a) ; // OK, pointer arithmetic generated by compiler } Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp @@ -22,9 +22,11 @@ // Flag all operators +, -, +=, -=, ++, -- that result in a pointer Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"), - hasOperatorName("+="), hasOperatorName("-=")), - hasType(pointerType())) + binaryOperator( + anyOf(hasOperatorName("+"), hasOperatorName("-"), +hasOperatorName("+="), hasOperatorName("-=")), + hasType(pointerType()), + unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())) .bind("expr"), this); @@ -36,8 +38,10 @@ // Array subscript on a pointer (not an array) is also pointer arithmetic Finder->addMatcher( - arraySubscriptExpr(hasBase(ignoringImpCasts(anyOf(hasType(pointerType()), -hasType(decayedType(hasDecayedType(pointerType( + arraySubscriptExpr( + hasBase(ignoringImpCasts( + anyOf(hasType(pointerType()), +hasType(decayedType(hasDecayedType(pointerType( .bind("expr"), this); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D15030: [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index
mgehre created this revision. mgehre added reviewers: alexfh, sbenza, bkramer, aaron.ballman. mgehre added a subscriber: cfe-commits. This is http://reviews.llvm.org/D13746 but instead of including , a stub is provided. This check flags all array subscriptions on static arrays and std::arrays that either have a non-compile-time-constant index or are out of bounds. Dynamic accesses into arrays are difficult for both tools and humans to validate as safe. array_view is a bounds-checked, safe type for accessing arrays of data. at() is another alternative that ensures single accesses are bounds-checked. If iterators are needed to access an array, use the iterators from an array_view constructed over the array. This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds2-only-index-into-arrays-using-constant-expressions http://reviews.llvm.org/D15030 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp Index: test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp @@ -0,0 +1,79 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t -- -config='{CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: "dir1/gslheader.h"}]}' -- -std=c++11 +// CHECK-FIXES: #include "dir1/gslheader.h" + +typedef unsigned int size_t; + +namespace std { + template + struct array { +T& operator[](size_t n); +T& at(size_t n); + }; +} + + +namespace gsl { + template + T& at( T(&a)[N], size_t index ); + + template + T& at( std::array &a, size_t index ); +} + +constexpr int const_index(int base) { + return base + 3; +} + +void f(std::array a, int pos) { + a [ pos / 2 /*comment*/] = 1; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not a compile-time constant; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index] + // CHECK-FIXES: gsl::at(a, pos / 2 /*comment*/) = 1; + int j = a[pos - 1]; + // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not a compile-time constant; use gsl::at() instead + // CHECK-FIXES: int j = gsl::at(a, pos - 1); + + a.at(pos-1) = 2; // OK, at() instead of [] + gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of [] + + a[-1] = 3; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is before the beginning of the array [cppcoreguidelines-pro-bounds-constant-array-index] + a[10] = 4; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index] + + a[const_index(7)] = 3; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) + + a[0] = 3; // OK, constant index and inside bounds + a[1] = 3; // OK, constant index and inside bounds + a[9] = 3; // OK, constant index and inside bounds + a[const_index(6)] = 3; // OK, constant index and inside bounds +} + +void g() { + int a[10]; + for (int i = 0; i < 10; ++i) { +a[i] = i; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not a compile-time constant; use gsl::at() instead +// CHECK-FIXES: gsl::at(a, i) = i; +gsl::at(a, i) = i; // OK, gsl::at() instead of [] + } + + a[-1] = 3; // flagged by clang-diagnostic-array-bounds + a[10] = 4; // flagged by clang-diagnostic-array-bounds + a[const_index(7)] = 3; // flagged by clang-diagnostic-array-bounds + + a[0] = 3; // OK, constant index and inside bounds + a[1] = 3; // OK, constant index and inside bounds + a[9] = 3; // OK, constant index and inside bounds + a[const_index(6)] = 3; // OK, constant index and inside bounds +} + +struct S { + int& operator[](int i); +}; + +void customOperator() { + S s; + int i = 0; + s[i] = 3; // OK, custom operator +} Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -6,6 +6,7 @@ cert-thrown-exception-type cert-variadic-function-def cppcoreguidelines-pro-bounds-array-to-pointer-decay + cppcoreguidelines-pro-bounds-constant-array-index cppcoreguidelines-pro-bounds-pointer-arithmetic cppcoreguidelines-pro-type-const-cast cppcoreguidelin
[PATCH] D15031: CFG: Add CFGElement for automatic variables that leave the scope
mgehre created this revision. mgehre added reviewers: krememek, jordan_rose. mgehre added a subscriber: cfe-commits. This mimics the implementation for the implicit destructors. The generation of this scope leaving elements is hidden behind a flag to the CFGBuilder, thus it should not affect existing code. Currently, I'm missing a test (it's implicitly tested by the clang-tidy lifetime checker that I'm proposing). I though about a test using debug.DumpCFG, but then I would have to add an option to StaticAnalyzer/Core/AnalyzerOptions to enable the scope leaving CFGElement, which would only be useful to that particular test. Any other ideas how I could make a test for this feature? http://reviews.llvm.org/D15031 Files: include/clang/Analysis/CFG.h lib/Analysis/CFG.cpp Index: lib/Analysis/CFG.cpp === --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -578,6 +578,10 @@ CFGBlock *addInitializer(CXXCtorInitializer *I); void addAutomaticObjDtors(LocalScope::const_iterator B, LocalScope::const_iterator E, Stmt *S); + void addAutomaticObjLeavesScope(LocalScope::const_iterator B, + LocalScope::const_iterator E, Stmt *S); + void addAutomaticObjHandling(LocalScope::const_iterator B, + LocalScope::const_iterator E, Stmt *S); void addImplicitDtorsForDestructor(const CXXDestructorDecl *DD); // Local scopes creation. @@ -618,13 +622,20 @@ B->appendAutomaticObjDtor(VD, S, cfg->getBumpVectorContext()); } + void appendAutomaticObjLeavesScope(CFGBlock *B, VarDecl *VD, Stmt *S) { +B->appendAutomaticObjLeavesScope(VD, S, cfg->getBumpVectorContext()); + } + void appendDeleteDtor(CFGBlock *B, CXXRecordDecl *RD, CXXDeleteExpr *DE) { B->appendDeleteDtor(RD, DE, cfg->getBumpVectorContext()); } void prependAutomaticObjDtorsWithTerminator(CFGBlock *Blk, LocalScope::const_iterator B, LocalScope::const_iterator E); + void prependAutomaticObjLeavesScopeWithTerminator(CFGBlock *Blk, + LocalScope::const_iterator B, LocalScope::const_iterator E); + void addSuccessor(CFGBlock *B, CFGBlock *S, bool IsReachable = true) { B->addSuccessor(CFGBlock::AdjacentBlock(S, IsReachable), cfg->getBumpVectorContext()); @@ -1033,6 +1044,8 @@ assert(Succ == &cfg->getExit()); Block = nullptr; // the EXIT block is empty. Create all other blocks lazily. + assert(!(BuildOpts.AddImplicitDtors && BuildOpts.AddAutomaticObjLeavesScope) && "AddImplicitDtors and AddScopeLeavers cannot be used at the same time"); + if (BuildOpts.AddImplicitDtors) if (const CXXDestructorDecl *DD = dyn_cast_or_null(D)) addImplicitDtorsForDestructor(DD); @@ -1208,7 +1221,41 @@ return Init->getType(); } - + +void CFGBuilder::addAutomaticObjHandling(LocalScope::const_iterator B, + LocalScope::const_iterator E, Stmt *S) { + if (BuildOpts.AddImplicitDtors) +addAutomaticObjDtors(B, E, S); + if (BuildOpts.AddAutomaticObjLeavesScope) +addAutomaticObjLeavesScope(B, E, S); +} + +/// addAutomaticObjLeavesScope - Add to current block automatic objects thats leave the scope. +void CFGBuilder::addAutomaticObjLeavesScope(LocalScope::const_iterator B, +LocalScope::const_iterator E, Stmt *S) { + if (!BuildOpts.AddAutomaticObjLeavesScope) +return; + + if (B == E) +return; + + int dist = B.distance(E); + if (dist <= 0) +return; + + // We need to perform the scope leaving in reverse order + SmallVector Decls; + Decls.reserve(dist); + for (LocalScope::const_iterator I = B; I != E; ++I) +Decls.push_back(*I); + + autoCreateBlock(); + for (SmallVectorImpl::reverse_iterator I = Decls.rbegin(), + E = Decls.rend(); + I != E; ++I) +appendAutomaticObjLeavesScope(Block, *I, S); +} + /// addAutomaticObjDtors - Add to current block automatic objects destructors /// for objects in range of local scope positions. Use S as trigger statement /// for destructors. @@ -1308,7 +1355,7 @@ /// addLocalScopeForStmt - Add LocalScope to local scopes tree for statement /// that should create implicit scope (e.g. if/else substatements). void CFGBuilder::addLocalScopeForStmt(Stmt *S) { - if (!BuildOpts.AddImplicitDtors) + if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddAutomaticObjLeavesScope) return; LocalScope *Scope = nullptr; @@ -1333,7 +1380,7 @@ /// reuse Scope if not NULL. LocalScope* CFGBuilder::addLocalScopeForDeclStmt(DeclStmt *DS, LocalScope* Scope) { - if (!BuildOpts.AddImplicitDtors) + if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddAutomaticObjLeavesScope) return Scope; for (auto *DI : DS->decls()) @@ -1347,7 +1394,7 @@ /// const reference. Will reuse Scope if not NULL.
[PATCH] D15032: [clang-tidy] new checker cppcoreguidelines-pro-lifetime
mgehre created this revision. mgehre added reviewers: alexfh, sbenza, bkramer, aaron.ballman. mgehre added a subscriber: cfe-commits. mgehre added a dependency: D15031: CFG: Add CFGElement for automatic variables that leave the scope. This checker implements the lifetime rules presented in the paper by Herb Sutter and Neil MacIntosh paper [1]. Basically, for each "Pointer" we track a set of possible "Owners" to which it it directly or transitivly points, called its pset (points-to set). If an Owner is invalidated, all Pointers that contain that Owner in their pset get an "invalid" pset. For an in-depth explanation, please refer to the paper. "Pointers" are not only variable with pointer type, but also references, and objects that contain Pointers (e.g. iterators). A pset can contain "null", "invalid", "static" (for static duration Owners that cannot be invalidated), and tuples (Owner, order). Order 0 means that the Pointer points to the object, e.g. int* p = &i => pset(p) = {(i,0)}. Order 1 means that the Pointer points to something owned by the object, e.g. int* p = o.getp() => pset(p) = {(o,1)}. The paper, and thus the checker, are implemented in a path-independent way. That leads to some false positives, but increases speed and allows e.g. to reason about loops without unrolling. Function bodies are analyzed separately. When calling a function, the caller can assume how the psets of the Pointers change. Those assumptions are checked for each analyzed function. (Just like for const methods; callers assume that the object does not change; bodies of const methods are not allowed to change the object). The checker assumes that the code to be checked is valid according to the C++ Core Guidelines type and bounds profile. If "forbidden" expressions (such as pointer arithmetic) are used, or if an unimplemented expression is encountered, the resulting pset will be "unknown". Psets containing "unknown" will not cause any warnings by the checker. The checker will emit the pset of an variable if it finds a call to "clang_analyzer_pset" in the C++ code. This is used by the tests to display the pset of a Pointer. For now, the checker is split into ProLifetimeCheck.cpp and ProLifetimeVisitor.cpp. The only reason is that it speeds up the compile time for me. ProLifetimeCheck.cpp is quite slow to compile (I guess due to ASTMatchers.h). I can happily merge both cpp files before the commiting, if required. This checker is not complete. I would like to hear your comments about high level stuff (e.g. architecture) and what is the best way forward to get this upstream. Currently state: - Pointers are only variables of pointer type or reference type (no objects containing Pointers, like iterators). - Psets are computed through all expressions and conditionals. - "(null)" will be removed from a pset in a branch if the pointer appears in a conditional guarding that branch. It does not handle all types of conditionals yet. - Pointers are invalidated when the Owner they point to goes out of scope. - Dereferencing invalid pointers is flagged. - Pointers with static duration will be checked on assignment to only have a pset of (null) and/or (static). Anything else is flagged. - CFGs with loops are supported and lead to an iterative refinement - I have run this on the llvm code base, and the diagnosed issues are mostly related to null pointer dereferencing. I would not call them false-positives, because this checker assumes that pointer arguments can be null, and otherwise gsl::not_null should be used. If you like to see what it can diagnose, look at test/clang-tidy/cppcoreguidelines-pro-lifetime.cpp For the internal pset propagation, look at test/clang-tidy/cppcoreguidelines-pro-lifetime-psets.cpp (incomplete) TODO: - track psets for objects containing Pointers - compute pset of return values and out-parameters in function calls - check correct pset in 'return' statments - support annotations for non-standard lifetime behavior [1] https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetimes%20I%20and%20II%20-%20v0.9.1.pdf Depends on D15031 http://reviews.llvm.org/D15032 Files: clang-tidy/cppcoreguidelines/CMakeLists.txt clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tidy/cppcoreguidelines/ProLifetimeCheck.cpp clang-tidy/cppcoreguidelines/ProLifetimeCheck.h clang-tidy/cppcoreguidelines/ProLifetimeVisitor.cpp clang-tidy/cppcoreguidelines/ProLifetimeVisitor.h docs/clang-tidy/checks/cppcoreguidelines-pro-lifetime.rst docs/clang-tidy/checks/list.rst test/clang-tidy/cppcoreguidelines-pro-lifetime-psets.cpp test/clang-tidy/cppcoreguidelines-pro-lifetime.cpp Index: test/clang-tidy/cppcoreguidelines-pro-lifetime.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-pro-lifetime.cpp @@ -0,0 +1,87 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-lifetime %t -- -config="{CheckOptions: [{key: c
Re: [PATCH] D15031: CFG: Add CFGElement for automatic variables that leave the scope
mgehre added a comment. The lifetime checker that needs this is at http://reviews.llvm.org/D15032 http://reviews.llvm.org/D15031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15029: [OpenMP] Parsing and sema support for thread_limit clause
ABataev added inline comments. Comment at: lib/Sema/SemaOpenMP.cpp:5220-5242 @@ -5216,2 +5219,25 @@ +static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, + OpenMPClauseKind CKind) { + if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && + !ValExpr->isInstantiationDependent()) { +SourceLocation Loc = ValExpr->getExprLoc(); +ExprResult Value = +SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); +if (Value.isInvalid()) + return false; + +ValExpr = Value.get(); +// The expression must evaluate to a non-negative integer value. +llvm::APSInt Result; +if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && +Result.isSigned() && !Result.isStrictlyPositive()) { + SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) + << getOpenMPClauseName(CKind) << ValExpr->getSourceRange(); + return false; +} + } + return true; +} + OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, Use Sema::VerifyPositiveIntegerConstantInClause() instead. http://reviews.llvm.org/D15029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15029: [OpenMP] Parsing and sema support for thread_limit clause
kkwli0 added inline comments. Comment at: lib/Sema/SemaOpenMP.cpp:5220-5242 @@ -5216,2 +5219,25 @@ +static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, + OpenMPClauseKind CKind) { + if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && + !ValExpr->isInstantiationDependent()) { +SourceLocation Loc = ValExpr->getExprLoc(); +ExprResult Value = +SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); +if (Value.isInvalid()) + return false; + +ValExpr = Value.get(); +// The expression must evaluate to a non-negative integer value. +llvm::APSInt Result; +if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && +Result.isSigned() && !Result.isStrictlyPositive()) { + SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) + << getOpenMPClauseName(CKind) << ValExpr->getSourceRange(); + return false; +} + } + return true; +} + OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, ABataev wrote: > Use Sema::VerifyPositiveIntegerConstantInClause() instead. num_teams/thread_limit/num_threads is not required to be a constant. Using Sema::VerifyPositiveIntegerConstantInClause() will impose a stricter constraint. http://reviews.llvm.org/D15029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits