[clang] 39191c4 - [NFC][Clang] Fix static analyzer concerns

2023-08-29 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-29T12:23:26-07:00
New Revision: 39191c45771564b8a0930d71b4c229147cf839db

URL: 
https://github.com/llvm/llvm-project/commit/39191c45771564b8a0930d71b4c229147cf839db
DIFF: 
https://github.com/llvm/llvm-project/commit/39191c45771564b8a0930d71b4c229147cf839db.diff

LOG: [NFC][Clang] Fix static analyzer concerns

Fix static analyzer concerns about dereferencing null values.

Differential Revision: https://reviews.llvm.org/D157118

Added: 


Modified: 
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/PathDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 20e0e5d9cdf59f..a31aa0cfeeed8d 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@ namespace {
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())
@@ -599,8 +600,10 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
 
   if (auto *FS = static_cast(Node->getFinallyStmt())) {
 Indent() << "@finally";
-PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody()));
-OS << NL;
+if (auto *CS = dyn_cast(FS->getFinallyBody())) {
+  PrintRawCompoundStmt(CS);
+  OS << NL;
+}
   }
 }
 
@@ -635,7 +638,7 @@ void 
StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
 
 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
   Indent() << "@autoreleasepool";
-  PrintRawCompoundStmt(dyn_cast(Node->getSubStmt()));
+  PrintRawCompoundStmt(cast(Node->getSubStmt()));
   OS << NL;
 }
 

diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
b/clang/lib/Analysis/PathDiagnostic.cpp
index ac1306fd80711b..93e6d98492ddef 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@ PathDiagnosticLocation
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager ,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }



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


[clang] 847186e - [NFC][Clang] Fix static analyzer concern

2023-08-25 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-25T13:03:06-07:00
New Revision: 847186eb94bd8c3535f0384456eeffe85f1d9696

URL: 
https://github.com/llvm/llvm-project/commit/847186eb94bd8c3535f0384456eeffe85f1d9696
DIFF: 
https://github.com/llvm/llvm-project/commit/847186eb94bd8c3535f0384456eeffe85f1d9696.diff

LOG: [NFC][Clang] Fix static analyzer concern

Fix a few static analyzer concerns about dereferencing
null value.

Differential Revision: https://reviews.llvm.org/D158671

Added: 


Modified: 
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 17c2ab6fd20501..84ea8e2f7ce385 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@ bool ExtractAPIVisitorBase::VisitVarDecl(const 
VarDecl *Decl) {
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);

diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 3c15d5073b01eb..5c5a9df6505271 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@ 
DeclarationFragmentsBuilder::getFragmentsForSpecialCXXMethod(
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f78d46f5950360..63f022d5c2ff09 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 



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


[clang] e62b2fc - [NFC][Clang] Fix static analyzer concern

2023-08-16 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-16T13:52:45-07:00
New Revision: e62b2fc40d11b6b13bcc08d7ceafe1472abe4c58

URL: 
https://github.com/llvm/llvm-project/commit/e62b2fc40d11b6b13bcc08d7ceafe1472abe4c58
DIFF: 
https://github.com/llvm/llvm-project/commit/e62b2fc40d11b6b13bcc08d7ceafe1472abe4c58.diff

LOG: [NFC][Clang] Fix static analyzer concern

Fixed static analyzer concern about null value
dereference. getStmtForDiagnostics() can return
null. Ensure statement exists before dereference
in PathDiagnosticLocation::createBegin().

Differential Revision: https://reviews.llvm.org/D157888

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
index 38b4caa12aef16..b2e55332074c49 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -653,10 +653,11 @@ void FuchsiaHandleChecker::reportBug(SymbolRef Sym, 
ExplodedNode *ErrorNode,
   if (Type.isSuppressOnSink()) {
 const ExplodedNode *AcquireNode = getAcquireSite(ErrorNode, Sym, C);
 if (AcquireNode) {
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =
   PathDiagnosticLocation::createBegin(
-  AcquireNode->getStmtForDiagnostics(), C.getSourceManager(),
-  AcquireNode->getLocationContext());
+  S, C.getSourceManager(), AcquireNode->getLocationContext());
 
   R = std::make_unique(
   Type, Msg, ErrorNode, LocUsedForUniqueing,



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


[clang] c70dab0 - [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-14T13:07:24-07:00
New Revision: c70dab026d377736c1281d3c8005bb5e578ec8b3

URL: 
https://github.com/llvm/llvm-project/commit/c70dab026d377736c1281d3c8005bb5e578ec8b3
DIFF: 
https://github.com/llvm/llvm-project/commit/c70dab026d377736c1281d3c8005bb5e578ec8b3.diff

LOG: [NFC][Clang] Fix static analyzer concern about null value dereference

Differential Revision: https://reviews.llvm.org/D157885

Added: 


Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index c8cbee14be4f02..15e88a9be44ad0 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4459,7 +4459,9 @@ void ASTDeclReader::UpdateDecl(Decl *D,
   if (auto *VTSD = dyn_cast(D)) {
 VTSD->setPointOfInstantiation(POI);
   } else if (auto *VD = dyn_cast(D)) {
-VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
+MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
+assert(MSInfo && "No member specialization information");
+MSInfo->setPointOfInstantiation(POI);
   } else {
 auto *FD = cast(D);
 if (auto *FTSInfo = FD->TemplateOrSpecialization



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


[clang] c4ada13 - [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-14T12:19:45-07:00
New Revision: c4ada13e4b3e72543e454a12a6db085812114c0c

URL: 
https://github.com/llvm/llvm-project/commit/c4ada13e4b3e72543e454a12a6db085812114c0c
DIFF: 
https://github.com/llvm/llvm-project/commit/c4ada13e4b3e72543e454a12a6db085812114c0c.diff

LOG: [NFC][Clang] Fix static analyzer concern about null value dereference

Differential Revision: https://reviews.llvm.org/D157554

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 82afb084efd0b1..e6eb9508f8e6ff 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,8 +9072,10 @@ Sema::BuildExprRequirement(
 MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
  /*Final=*/false);
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
-Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
-ExprResult Constraint = SubstExpr(IDC, MLTAL);
+const TypeConstraint *TC = Param->getTypeConstraint();
+assert(TC && "Type Constraint cannot be null here");
+ExprResult Constraint =
+SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
 if (Constraint.isInvalid()) {
   Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
 } else {



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


[clang] 421c9bb - [NFC][Clang] Fix static analyzer concern

2023-08-14 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-14T07:14:32-07:00
New Revision: 421c9bbf65b78e3410415cac2edf4e00bd4d38ca

URL: 
https://github.com/llvm/llvm-project/commit/421c9bbf65b78e3410415cac2edf4e00bd4d38ca
DIFF: 
https://github.com/llvm/llvm-project/commit/421c9bbf65b78e3410415cac2edf4e00bd4d38ca.diff

LOG: [NFC][Clang] Fix static analyzer concern

Fix static analyzer concern about null value
dereference. InterfacePointerType is dereferenced
and should not be null.

Differential Revision: https://reviews.llvm.org/D157454

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 46c37eaea82b1a..6c594b5db4bca1 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -222,6 +222,7 @@ llvm::Value 
*CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
   QualType ResultType = E->getType();
   const ObjCObjectPointerType *InterfacePointerType
 = ResultType->getAsObjCInterfacePointerType();
+  assert(InterfacePointerType && "Unexpected InterfacePointerType - null");
   ObjCInterfaceDecl *Class
 = InterfacePointerType->getObjectType()->getInterface();
   CGObjCRuntime  = CGM.getObjCRuntime();



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


[clang] 6a4779c - [NFC] Fix static analyzer concern

2023-08-08 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-08T13:28:15-07:00
New Revision: 6a4779cc235c171f7a5049726f58e14a2cc4e6c8

URL: 
https://github.com/llvm/llvm-project/commit/6a4779cc235c171f7a5049726f58e14a2cc4e6c8
DIFF: 
https://github.com/llvm/llvm-project/commit/6a4779cc235c171f7a5049726f58e14a2cc4e6c8.diff

LOG: [NFC] Fix static analyzer concern

Fix static analyzer concern about potential null value
dereference. findBackingIvar() dereferences Prop. PR
checks that Prop exists before calling the function.

Differential Revision: https://reviews.llvm.org/D157429

Added: 


Modified: 
clang/lib/Analysis/BodyFarm.cpp

Removed: 




diff  --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp
index b989b8422cfc82..13ec9b65c9f0b2 100644
--- a/clang/lib/Analysis/BodyFarm.cpp
+++ b/clang/lib/Analysis/BodyFarm.cpp
@@ -806,7 +806,7 @@ static Stmt *createObjCPropertyGetter(ASTContext ,
 
   if (!IVar) {
 Prop = MD->findPropertyDecl();
-IVar = findBackingIvar(Prop);
+IVar = Prop ? findBackingIvar(Prop) : nullptr;
   }
 
   if (!IVar || !Prop)



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


[clang] c1401e9 - [Clang][Sema] Fix access of friend class in local class

2023-06-06 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-06-06T10:46:50-07:00
New Revision: c1401e9f3e7cfe10d5c8d7d040d66898bbc8ef39

URL: 
https://github.com/llvm/llvm-project/commit/c1401e9f3e7cfe10d5c8d7d040d66898bbc8ef39
DIFF: 
https://github.com/llvm/llvm-project/commit/c1401e9f3e7cfe10d5c8d7d040d66898bbc8ef39.diff

LOG: [Clang][Sema] Fix access of friend class in local class

Clang currently emits an error when a friend of a local class
tries to access it's private data members. This patch fixes the bug.

Differential Revision: https://reviews.llvm.org/D152195

Added: 
clang/test/Sema/local-class-friend.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f582f584bdf6..d6b498ced6ca2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -539,6 +539,9 @@ Bug Fixes to C++ Support
 - Allow omitting ``typename`` in the parameter declaration of a friend
   constructor declaration.
   (`#63119 `_)
+- Fix access of a friend class declared in a local class. Clang previously
+  emitted an error when a friend of a local class tried to access it's
+  private data members.
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 12fd378fb170c..992d497ca915a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17066,11 +17066,14 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
   S = getTagInjectionScope(S, getLangOpts());
 } else {
   assert(TUK == TUK_Friend);
+  CXXRecordDecl *RD = dyn_cast(SearchDC);
+
   // C++ [namespace.memdef]p3:
   //   If a friend declaration in a non-local class first declares a
   //   class or function, the friend class or function is a member of
   //   the innermost enclosing namespace.
-  SearchDC = SearchDC->getEnclosingNamespaceContext();
+  SearchDC = RD->isLocalClass() ? RD->isLocalClass()
+: SearchDC->getEnclosingNamespaceContext();
 }
 
 // In C++, we need to do a redeclaration lookup to properly

diff  --git a/clang/test/Sema/local-class-friend.cpp 
b/clang/test/Sema/local-class-friend.cpp
new file mode 100644
index 0..6f9af7132c2a1
--- /dev/null
+++ b/clang/test/Sema/local-class-friend.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+// expected-no-diagnostics
+
+void foo()
+{ class c1 {
+private:
+  int testVar;
+public:
+  friend class c2;
+  };
+
+  class c2 {
+void f(c1 obj) {
+  int a = obj.testVar; // Ok
+}
+  };
+}



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


[clang] cecd847 - [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

2023-06-02 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-06-02T08:11:18-07:00
New Revision: cecd8471e4991b4bea5d2b38a3758cafdb1cbe29

URL: 
https://github.com/llvm/llvm-project/commit/cecd8471e4991b4bea5d2b38a3758cafdb1cbe29
DIFF: 
https://github.com/llvm/llvm-project/commit/cecd8471e4991b4bea5d2b38a3758cafdb1cbe29.diff

LOG: [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

Clang was rejecting valid code where GNU style attributes preceded C++ style
attributes in template declarations as follows:

template
__attribute__((deprecated("oh no!"))) [[deprecated("oh no!")]] void foo();

This PR fixes the bug.

Differential Revision: https://reviews.llvm.org/D151837

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseTemplate.cpp
clang/test/Parser/attr-order.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02736f2ee67fc..69ab645d49c23 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,10 @@ Bug Fixes to Attribute Support
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behavior exhibited by GCC, which permits mixed ordering of GNU and C++
+  attributes.
 
 Bug Fixes to C++ Support
 

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 79f4ab683281e..d2e8a81ad521a 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into 
diff erent containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, );
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));

diff  --git a/clang/test/Parser/attr-order.cpp 
b/clang/test/Parser/attr-order.cpp
index 9a8490d819ee3..10bad38cac644 100644
--- a/clang/test/Parser/attr-order.cpp
+++ b/clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@ struct [[]] __attribute__((lockable)) [[]] 
__declspec(dllexport) H {}; // ok
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok



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


[clang] ca06638 - [SYCL][NFC] Remove dead code

2023-05-08 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-05-08T13:08:23-07:00
New Revision: ca06638bbbf42a511d1be141fc7c547c7995ed29

URL: 
https://github.com/llvm/llvm-project/commit/ca06638bbbf42a511d1be141fc7c547c7995ed29
DIFF: 
https://github.com/llvm/llvm-project/commit/ca06638bbbf42a511d1be141fc7c547c7995ed29.diff

LOG: [SYCL][NFC] Remove dead code

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaSYCL.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e28ec936e4c2..f65f8e3f2b50 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13957,20 +13957,6 @@ class Sema final {
   SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc,
  unsigned DiagID);
 
-  /// Check whether we're allowed to call Callee from the current context.
-  ///
-  /// - If the call is never allowed in a semantically-correct program
-  ///   emits an error and returns false.
-  ///
-  /// - If the call is allowed in semantically-correct programs, but only if
-  ///   it's never codegen'ed, creates a deferred diagnostic to be emitted if
-  ///   and when the caller is codegen'ed, and returns true.
-  ///
-  /// - Otherwise, returns true without emitting any diagnostics.
-  ///
-  /// Adds Callee to DeviceCallGraph if we don't know if its caller will be
-  /// codegen'ed yet.
-  bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
   void deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
   llvm::DenseSet Visited,
   ValueDecl *DeclToCheck);

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 31936bce7862..4efa1b408607 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15672,9 +15672,6 @@ Sema::BuildCXXConstructExpr(SourceLocation 
ConstructLoc, QualType DeclInitType,
   MarkFunctionReferenced(ConstructLoc, Constructor);
   if (getLangOpts().CUDA && !CheckCUDACall(ConstructLoc, Constructor))
 return ExprError();
-  if (getLangOpts().SYCLIsDevice &&
-  !checkSYCLDeviceFunction(ConstructLoc, Constructor))
-return ExprError();
 
   return CheckForImmediateInvocation(
   CXXConstructExpr::Create(

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec0f31e489d5..2e463346e70f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -309,8 +309,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
 if (getLangOpts().CUDA && !CheckCUDACall(Loc, FD))
   return true;
 
-if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
-  return true;
   }
 
   if (auto *MD = dyn_cast(D)) {
@@ -18468,9 +18466,6 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   if (getLangOpts().CUDA)
 CheckCUDACall(Loc, Func);
 
-  if (getLangOpts().SYCLIsDevice)
-checkSYCLDeviceFunction(Loc, Func);
-
   // If we need a definition, try to create one.
   if (NeedDefinition && !Func->getBody()) {
 runWithSufficientStackSpace(Loc, [&] {

diff  --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp
index f8c713c8545d..ca0254d29e7f 100644
--- a/clang/lib/Sema/SemaSYCL.cpp
+++ b/clang/lib/Sema/SemaSYCL.cpp
@@ -33,22 +33,6 @@ Sema::SemaDiagnosticBuilder 
Sema::SYCLDiagIfDeviceCode(SourceLocation Loc,
   return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this);
 }
 
-bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
-  assert(getLangOpts().SYCLIsDevice &&
- "Should only be called during SYCL compilation");
-  assert(Callee && "Callee may not be null.");
-
-  // Errors in an unevaluated context don't need to be generated,
-  // so we can safely skip them.
-  if (isUnevaluatedContext() || isConstantEvaluated())
-return true;
-
-  SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop;
-
-  return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
- DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
-}
-
 static bool isZeroSizedArray(Sema , QualType Ty) {
   if (const auto *CAT = SemaRef.getASTContext().getAsConstantArrayType(Ty))
 return CAT->getSize() == 0;



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


[clang] c10615e - [SYCL] Fix test to conform to SYCL2020

2023-01-26 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-01-26T13:52:48-08:00
New Revision: c10615e4a94fc8dec65a48a6eb8f7efccc3fb1fc

URL: 
https://github.com/llvm/llvm-project/commit/c10615e4a94fc8dec65a48a6eb8f7efccc3fb1fc
DIFF: 
https://github.com/llvm/llvm-project/commit/c10615e4a94fc8dec65a48a6eb8f7efccc3fb1fc.diff

LOG: [SYCL] Fix test to conform to SYCL2020

Added: 


Modified: 
clang/test/SemaSYCL/bf16.cpp

Removed: 




diff  --git a/clang/test/SemaSYCL/bf16.cpp b/clang/test/SemaSYCL/bf16.cpp
index 06ae263fbcfe5..d1b4776f34044 100644
--- a/clang/test/SemaSYCL/bf16.cpp
+++ b/clang/test/SemaSYCL/bf16.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
 
 template 
-__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+__attribute__((sycl_kernel)) void kernel(const Func ) {
   kernelFunc(); // expected-note {{called by 'kernel}}
 }
 



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


[clang] f81d529 - [Clang] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-01-25T12:43:36-08:00
New Revision: f81d529f8955dbdf64d429c27dee994257b4ee99

URL: 
https://github.com/llvm/llvm-project/commit/f81d529f8955dbdf64d429c27dee994257b4ee99
DIFF: 
https://github.com/llvm/llvm-project/commit/f81d529f8955dbdf64d429c27dee994257b4ee99.diff

LOG: [Clang] Fix compilation errors for unsupported __bf16 intrinsics

This patch uses existing deferred diagnostics framework to emit error
for unsupported type __bf16 in device code. Error is not emitted in
host code.

Differential Revision: https://reviews.llvm.org/D141375

Added: 
clang/test/SemaSYCL/bf16.cpp

Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2884fe6604228..3ba8b90898b30 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2140,6 +2140,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   if (Target->hasBFloat16Type()) {
 Width = Target->getBFloat16Width();
 Align = Target->getBFloat16Align();
+  } else if ((getLangOpts().SYCLIsDevice ||
+  (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
+ AuxTarget->hasBFloat16Type()) {
+Width = AuxTarget->getBFloat16Width();
+Align = AuxTarget->getBFloat16Align();
   }
   break;
 case BuiltinType::Float16:

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b23bc5f8d8816..88549c7344506 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3051,7 +3051,11 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 break;
   }
   case BuiltinType::BFloat16: {
-const TargetInfo *TI = ().getTargetInfo();
+const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsDevice) ||
+getASTContext().getLangOpts().SYCLIsDevice)
+   ? getASTContext().getAuxTargetInfo()
+   : ().getTargetInfo();
 Out << TI->getBFloat16Mangling();
 break;
   }

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 0f03054224545..f983c477ac18e 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1975,6 +1975,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
+(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
+ !LangOpts.CUDAIsDevice) ||
 LongDoubleMismatched) {
   PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
   if (D)

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 89d819a77dcbb..505b3b922d33d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState ) {
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
   case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type())
-  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
-<< "__bf16";
+if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
+!S.getLangOpts().SYCLIsDevice)
+  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
 Result = Context.BFloat16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;

diff  --git a/clang/test/SemaSYCL/bf16.cpp b/clang/test/SemaSYCL/bf16.cpp
new file mode 100644
index 0..06ae263fbcfe5
--- /dev/null
+++ b/clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type 
support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+



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


[clang] ed5b42b - Fix address space for function pointers with qualifier

2022-02-07 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2022-02-07T12:53:24-08:00
New Revision: ed5b42b741881a0a94e65999f0c785ec53b46511

URL: 
https://github.com/llvm/llvm-project/commit/ed5b42b741881a0a94e65999f0c785ec53b46511
DIFF: 
https://github.com/llvm/llvm-project/commit/ed5b42b741881a0a94e65999f0c785ec53b46511.diff

LOG: Fix address space for function pointers with qualifier

This patch fixes a bug introduced in commit 4eaf5846d0e7. Commit
4eaf5846d0e7 sets address space of function type as program
address space unconditionally. This breaks types which have
address space qualifiers. E.g. __ptr32.

This patch fixes the bug by using address space qualifiers if
present.

Differential Revision: https://reviews.llvm.org/D119045

Added: 
clang/test/CodeGen/address-space-ptr32.c

Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5fa2d46de89b2..f2ac57465398b 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,13 @@ uint64_t 
ASTContext::getTargetNullPointerValue(QualType QT) const {
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
- : getTargetAddressSpace(T.getQualifiers());
+  // Return the address space for the type. If the type is a
+  // function type without an address space qualifier, the
+  // program address space is used. Otherwise, the target picks
+  // the best address space based on the type information
+  return T->isFunctionType() && !T.hasAddressSpace()
+ ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {

diff  --git a/clang/test/CodeGen/address-space-ptr32.c 
b/clang/test/CodeGen/address-space-ptr32.c
new file mode 100644
index 0..7684fdc487d49
--- /dev/null
+++ b/clang/test/CodeGen/address-space-ptr32.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s 
| FileCheck %s
+
+int foo(void) {
+  int (*__ptr32 a)(int);
+  return sizeof(a);
+}
+
+// CHECK: define dso_local i32 @foo
+// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
+// CHECK: ret i32 4



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


[clang] 4eaf584 - [clang] Fix function pointer address space

2022-01-13 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2022-01-13T08:06:19-08:00
New Revision: 4eaf5846d0e738264d9328b4a919bc352ea83b7a

URL: 
https://github.com/llvm/llvm-project/commit/4eaf5846d0e738264d9328b4a919bc352ea83b7a
DIFF: 
https://github.com/llvm/llvm-project/commit/4eaf5846d0e738264d9328b4a919bc352ea83b7a.diff

LOG: [clang] Fix function pointer address space

Functions pointers should be created with program address space. This
patch introduces program address space in TargetInfo. Targets with
non-default (default is 0) address space for functions should explicitly
set this value. This patch fixes a crash on lvalue reference to function
pointer (in device code) when using oneAPI DPC++ compiler.

Differential Revision: https://reviews.llvm.org/D111566

Added: 
clang/test/CodeGen/avr/functionptr-addrspace.c
clang/test/CodeGenSYCL/functionptr-addrspace.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AVR.h
clang/lib/CodeGen/CodeGenTypes.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 7a9e3a643d6f4..c5946b662cb29 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2727,13 +2727,9 @@ class ASTContext : public RefCountedBase {
   QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
  QualType typeDomain) const;
 
-  unsigned getTargetAddressSpace(QualType T) const {
-return getTargetAddressSpace(T.getQualifiers());
-  }
+  unsigned getTargetAddressSpace(QualType T) const;
 
-  unsigned getTargetAddressSpace(Qualifiers Q) const {
-return getTargetAddressSpace(Q.getAddressSpace());
-  }
+  unsigned getTargetAddressSpace(Qualifiers Q) const;
 
   unsigned getTargetAddressSpace(LangAS AS) const;
 

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 46eb190333aa2..686a365b8c12d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -212,6 +212,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   unsigned char RegParmMax, SSERegParmMax;
   TargetCXXABI TheCXXABI;
   const LangASMap *AddrSpaceMap;
+  unsigned ProgramAddrSpace;
 
   mutable StringRef PlatformName;
   mutable VersionTuple PlatformMinVersion;
@@ -767,6 +768,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
 return getTypeWidth(IntMaxType);
   }
 
+  /// Return the address space for functions for the given target.
+  unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
+
   // Return the size of unwind_word for this target.
   virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6f3c0dc14867a..9d63724c919a0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11575,6 +11575,15 @@ uint64_t 
ASTContext::getTargetNullPointerValue(QualType QT) const {
   return getTargetInfo().getNullPointerValue(AS);
 }
 
+unsigned ASTContext::getTargetAddressSpace(QualType T) const {
+  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
+}
+
+unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {
+  return getTargetAddressSpace(Q.getAddressSpace());
+}
+
 unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
   if (isTargetAddressSpace(AS))
 return toTargetAddressSpace(AS);

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index ddb20008bc9da..4fd31647bab24 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -150,6 +150,7 @@ TargetInfo::TargetInfo(const llvm::Triple ) : Triple(T) {
   PlatformMinVersion = VersionTuple();
 
   MaxOpenCLWorkGroupSize = 1024;
+  ProgramAddrSpace = 0;
 }
 
 // Out of line virtual dtor for TargetInfo.

diff  --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 89a80ca6a39a3..a281e2c2cd744 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -55,6 +55,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
+ProgramAddrSpace = 1;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
   }
 

diff  --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index 77721510dfd0f..4839e22c4b144 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -643,11 +643,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
 llvm::Type *PointeeType = 

[clang] 3ad0c6b - [clang-repl][NFC] Fix calling convention mismatch in test

2021-11-30 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2021-11-30T13:26:10-08:00
New Revision: 3ad0c6b75ea503e0a5bf2faaad9a34da0a020de0

URL: 
https://github.com/llvm/llvm-project/commit/3ad0c6b75ea503e0a5bf2faaad9a34da0a020de0
DIFF: 
https://github.com/llvm/llvm-project/commit/3ad0c6b75ea503e0a5bf2faaad9a34da0a020de0.diff

LOG: [clang-repl][NFC] Fix calling convention mismatch in test

Test failed on x86 platforms due to a calling convention mismatch
when member function was called like a free function. In this patch,
member function is marked static to address this.

Added: 


Modified: 
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 742aa4976357..280c6d7fdae2 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -221,7 +221,7 @@ TEST(IncrementalProcessing, InstantiateTemplate) {
"class A {};"
"struct B {"
"  template"
-   "  int callme(T) { return 42; }"
+   "  static int callme(T) { return 42; }"
"};"));
   auto  = llvm::cantFail(Interp->Parse("auto _t = ::callme;"));
   auto PTUDeclRange = PTU.TUPart->decls();



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


[clang] 5c8d305 - Fix complex types declared using mode TC

2021-11-02 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2021-11-02T12:00:26-07:00
New Revision: 5c8d3053fa0c183ea4f908e51a111ada3d4031f2

URL: 
https://github.com/llvm/llvm-project/commit/5c8d3053fa0c183ea4f908e51a111ada3d4031f2
DIFF: 
https://github.com/llvm/llvm-project/commit/5c8d3053fa0c183ea4f908e51a111ada3d4031f2.diff

LOG: Fix complex types declared using mode TC

This patch reverts incorrect IR introduced in commit d11ec6f67e45
[Clang] Enable IC/IF mode for __ibm128, for complex types declared
using __attribute__((mode(TC))). TC corresponds to an unspecified
128-bit format, which on some targets is a double-double format
(like __ibm128_t) and on others is float128_t. The bug in d11ec6f67e45
is that long double is only safe to use when it's known to be one of
these formats.

Differential Revision: https://reviews.llvm.org/D112975

Added: 
clang/test/CodeGenCXX/complex128.cpp

Modified: 
clang/lib/Basic/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 514893b47b4f4..76855b0c045c5 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -300,8 +300,11 @@ FloatModeKind TargetInfo::getRealTypeByWidth(unsigned 
BitWidth,
 if (ExplicitType == FloatModeKind::Ibm128)
   return hasIbm128Type() ? FloatModeKind::Ibm128
  : FloatModeKind::NoFloat;
-if (ExplicitType == FloatModeKind::LongDouble)
-  return ExplicitType;
+if (() == ::APFloat::PPCDoubleDouble() ||
+() == ::APFloat::IEEEquad())
+  return FloatModeKind::LongDouble;
+if (hasFloat128Type())
+  return FloatModeKind::Float128;
 break;
   }
 

diff  --git a/clang/test/CodeGenCXX/complex128.cpp 
b/clang/test/CodeGenCXX/complex128.cpp
new file mode 100644
index 0..71746314b9d39
--- /dev/null
+++ b/clang/test/CodeGenCXX/complex128.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | 
FileCheck %s
+
+// Define __complex128 type corresponding to __float128 (as in GCC headers).
+typedef _Complex float __attribute__((mode(TC))) __complex128;
+
+void check() {
+  // CHECK: alloca { fp128, fp128 }
+  __complex128 tmp;
+}



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


[clang] d8b8f54 - [Reland] "Do not apply calling conventions to MSVC entry points"

2021-03-18 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2021-03-18T04:26:47-07:00
New Revision: d8b8f544d9de30cd14584094596090d3f9992345

URL: 
https://github.com/llvm/llvm-project/commit/d8b8f544d9de30cd14584094596090d3f9992345
DIFF: 
https://github.com/llvm/llvm-project/commit/d8b8f544d9de30cd14584094596090d3f9992345.diff

LOG: [Reland] "Do not apply calling conventions to MSVC entry points"

This patch is a second attempt at fixing a link error for MSVC
entry points when calling conventions are specified using a flag.

Calling conventions specified using flags should not be applied to MSVC
entry points. The default calling convention is set in this case. The
default calling convention for MSVC entry points main and wmain is cdecl.
For WinMain, wWinMain and DllMain, the default calling convention is
stdcall on 32 bit Windows.

Explicitly specified calling conventions are applied to MSVC entry points.

For MinGW, the default calling convention for all MSVC entry points is
cdecl.

First attempt: 4cff1b40dacf6
Revert of first attempt: bebfc3b92d5e8

Differential Revision: https://reviews.llvm.org/D97941

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/default_calling_conv.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b962bd965223..76e3ee965777 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11173,6 +11173,25 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& 
DS) {
   }
 }
 
+static bool isDefaultStdCall(FunctionDecl *FD, Sema ) {
+
+  // Default calling convention for main and wmain is __cdecl
+  if (FD->getName() == "main" || FD->getName() == "wmain")
+return false;
+
+  // Default calling convention for MinGW is __cdecl
+  const llvm::Triple  = S.Context.getTargetInfo().getTriple();
+  if (T.isWindowsGNUEnvironment())
+return false;
+
+  // Default calling convention for WinMain, wWinMain and DllMain
+  // is __stdcall on 32 bit Windows
+  if (T.isOSWindows() && T.getArch() == llvm::Triple::x86)
+return true;
+
+  return false;
+}
+
 void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
@@ -11187,6 +11206,21 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  // Explicity specified calling conventions are applied to MSVC entry points
+  if (!hasExplicitCallingConv(T)) {
+if (isDefaultStdCall(FD, *this)) {
+  if (FT->getCallConv() != CC_X86StdCall) {
+FT = Context.adjustFunctionType(
+FT, FT->getExtInfo().withCallingConv(CC_X86StdCall));
+FD->setType(QualType(FT, 0));
+  }
+} else if (FT->getCallConv() != CC_C) {
+  FT = Context.adjustFunctionType(FT,
+  FT->getExtInfo().withCallingConv(CC_C));
+  FD->setType(QualType(FT, 0));
+}
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();

diff  --git a/clang/test/CodeGenCXX/default_calling_conv.cpp 
b/clang/test/CodeGenCXX/default_calling_conv.cpp
index e3d7ac429a60..83d1200e0ab1 100644
--- a/clang/test/CodeGenCXX/default_calling_conv.cpp
+++ b/clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -4,6 +4,9 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | 
FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i686-pc-win32 -fdefault-calling-conv=vectorcall 
-emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WIN32
+// RUN: %clang_cc1 -triple x86_64-windows-msvc 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s 
--check-prefix=WIN64
+// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm -o - %s -DEXPLICITCC | 
FileCheck %s --check-prefix=EXPLICITCC
 
 // CDECL: define{{.*}} void @_Z5test1v
 // FASTCALL: define{{.*}} x86_fastcallcc void @_Z5test1v
@@ -50,3 +53,45 @@ void test() {
 int main() {
   return 1;
 }
+
+#ifdef WINDOWS
+// WIN32: define dso_local i32 @wmain
+// WIN64: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @WinMain
+// WIN64: define dso_local i32 @WinMain
+int WinMain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @wWinMain
+// WIN64: define dso_local i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @DllMain
+// WIN64: define 

[clang] 4cff1b4 - Do not apply calling conventions to MSVC entry points

2020-09-16 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2020-09-16T09:39:37-07:00
New Revision: 4cff1b40dacf6a5489b09657d94ea4757b8cd3b0

URL: 
https://github.com/llvm/llvm-project/commit/4cff1b40dacf6a5489b09657d94ea4757b8cd3b0
DIFF: 
https://github.com/llvm/llvm-project/commit/4cff1b40dacf6a5489b09657d94ea4757b8cd3b0.diff

LOG: Do not apply calling conventions to MSVC entry points

Fix link error for MSVC entry points when calling conventions
are specified. MSVC entry points should have default calling
convention.

Differential Revision: https://reviews.llvm.org/D87701

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/default_calling_conv.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4ede2f9192f4..3e0d284bdf71 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11095,6 +11095,11 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT, 
FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();

diff  --git a/clang/test/CodeGenCXX/default_calling_conv.cpp 
b/clang/test/CodeGenCXX/default_calling_conv.cpp
index b5b0f47ceb98..16b623c30197 100644
--- a/clang/test/CodeGenCXX/default_calling_conv.cpp
+++ b/clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | 
FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
-
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s 
-DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWMAIN | FileCheck %s  
--check-prefix=WMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINMAIN | FileCheck %s  
--check-prefix=WINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWWINMAIN | FileCheck %s  
--check-prefix=WWINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DDLLMAIN | FileCheck %s  
--check-prefix=DLLMAIN
+//
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
@@ -46,7 +50,37 @@ void test() {
   a.test_member();
 }
 
+#ifdef MAIN
 // ALL: define i32 @main
 int main() {
   return 1;
 }
+#endif // main
+
+#ifdef WMAIN
+// WMAIN: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+#endif // wmain
+
+#ifdef WINMAIN
+// WINMAIN: define dso_local i32 @WinMain
+int WinMain() {
+  return 1;
+}
+#endif // WinMain
+
+#ifdef WWINMAIN
+// WWINMAIN: define dso_local i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+#endif // wWinMain
+
+#ifdef DLLMAIN
+// DLLMAIN: 

[clang] a58017e - Fix type-dependency of bitfields in templates

2020-02-12 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2020-02-12T13:31:41-08:00
New Revision: a58017e5cae5be948fd1913b68d46553e87aa622

URL: 
https://github.com/llvm/llvm-project/commit/a58017e5cae5be948fd1913b68d46553e87aa622
DIFF: 
https://github.com/llvm/llvm-project/commit/a58017e5cae5be948fd1913b68d46553e87aa622.diff

LOG: Fix type-dependency of bitfields in templates

This patch is a follow up to 878a24ee244a24. Name of bitfields
with value-dependent width should be set as type-dependent. This
patch adds the required value-dependency check and sets the
type-dependency accordingly.

Patch fixes PR44886

Differential revision: https://reviews.llvm.org/D72242

Added: 
clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp

Modified: 
clang/lib/AST/Expr.cpp
clang/test/SemaTemplate/enum-argument.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d9291616c66a..7e8808f84ead 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1680,6 +1680,11 @@ MemberExpr *MemberExpr::Create(
 CXXRecordDecl *RD = dyn_cast_or_null(DC);
 if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
   E->setTypeDependent(T->isDependentType());
+
+// Bitfield with value-dependent width is type-dependent.
+FieldDecl *FD = dyn_cast(MemberDecl);
+if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent())
+  E->setTypeDependent(true);
   }
 
   if (HasQualOrFound) {

diff  --git a/clang/test/SemaTemplate/enum-argument.cpp 
b/clang/test/SemaTemplate/enum-argument.cpp
index a79ed8403e9f..7ff419613990 100644
--- a/clang/test/SemaTemplate/enum-argument.cpp
+++ b/clang/test/SemaTemplate/enum-argument.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -30,7 +31,7 @@ namespace rdar8020920 {
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j; // expected-warning {{expression result unused}}
+  bitfield + j;
 }
   };
 }

diff  --git a/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp 
b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
new file mode 100644
index ..873e4d48e837
--- /dev/null
+++ b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template 
+class A {
+  int c : b;
+
+public:
+  void f() {
+if (c)
+  ;
+  }
+};



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


[clang] 878a24e - Reapply "Fix crash on switch conditions of non-integer types in templates"

2019-12-03 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2019-12-03T15:27:19-08:00
New Revision: 878a24ee244a24c39d1c57e9af2e88c621f7cce9

URL: 
https://github.com/llvm/llvm-project/commit/878a24ee244a24c39d1c57e9af2e88c621f7cce9
DIFF: 
https://github.com/llvm/llvm-project/commit/878a24ee244a24c39d1c57e9af2e88c621f7cce9.diff

LOG: Reapply "Fix crash on switch conditions of non-integer types in templates"

This patch reapplies commit 759948467ea. Patch was reverted due to a
clang-tidy test fail on Windows. The test has been modified. There
are no additional code changes.

Patch was tested with ninja check-all on Windows and Linux.

Summary of code changes:

Clang currently crashes for switch statements inside a template when the
condition is a non-integer field member because contextual implicit
conversion is skipped when parsing the condition. This conversion is
however later checked in an assert when the case statement is handled.
The conversion is skipped when parsing the condition because
the field member is set as type-dependent based on its containing class.
This patch sets the type dependency based on the field's type instead.

This patch fixes Bug 40982.

Added: 
clang/test/SemaTemplate/non-integral-switch-cond.cpp

Modified: 

clang-tools-extra/test/clang-tidy/checkers/bugprone-string-integer-assignment.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaTemplate/dependent-names.cpp
clang/test/SemaTemplate/enum-argument.cpp
clang/test/SemaTemplate/member-access-expr.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-string-integer-assignment.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-string-integer-assignment.cpp
index 18fe5ef4e5c2..2c288e0bbddf 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-string-integer-assignment.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-string-integer-assignment.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-string-integer-assignment %t
+// RUN: %check_clang_tidy %s bugprone-string-integer-assignment %t -- -- 
-fno-delayed-template-parsing
 
 namespace std {
 template
@@ -103,6 +103,8 @@ struct S {
   static constexpr T t = 0x8000;
   std::string s;
   void f(char c) { s += c | static_cast(t); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an integer is interpreted as a 
chara
+  // CHECK-FIXES: {{^}}  void f(char c) { s += std::to_string(c | 
static_cast(t)); } 
 };
 
 template S;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
index 119eff67318e..8e546b44ab74 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
@@ -233,7 +233,7 @@ struct a {
 template 
 class d {
   a e;
-  void f() { e.b(); }
+  void f() { e.b(0); }
 };
 }  // namespace
 }  // namespace PR38055

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 322b3a7fa740..a73531ad5fad 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1678,6 +1678,15 @@ MemberExpr *MemberExpr::Create(
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
+  if (FieldDecl *Field = dyn_cast(MemberDecl)) {
+DeclContext *DC = MemberDecl->getDeclContext();
+// dyn_cast_or_null is used to handle objC variables which do not
+// have a declaration context.
+CXXRecordDecl *RD = dyn_cast_or_null(DC);
+if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
+  E->setTypeDependent(T->isDependentType());
+  }
+
   if (HasQualOrFound) {
 // FIXME: Wrong. We should be looking at the member declaration we found.
 if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ed42833531d4..825e0faa3037 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14706,6 +14706,8 @@ void Sema::RefersToMemberWithReducedAlignment(
   bool AnyIsPacked = false;
   do {
 QualType BaseType = ME->getBase()->getType();
+if (BaseType->isDependentType())
+  return;
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->castAs()->getDecl();

diff  --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp 
b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index 8db705dcdc67..c2e443b9bec1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -18,6 +18,7 @@ namespace std {
 [[nodiscard]] void 

r368706 - Fix crash on switch conditions of non-integer types in templates

2019-08-13 Thread Elizabeth Andrews via cfe-commits
Author: eandrews
Date: Tue Aug 13 08:53:19 2019
New Revision: 368706

URL: http://llvm.org/viewvc/llvm-project?rev=368706=rev
Log:
Fix crash on switch conditions of non-integer types in templates

Clang currently crashes for switch statements inside a template when
the condition is a non-integer field. The crash is due to incorrect
type-dependency of field. Type-dependency of member expressions is
currently set based on the containing class. This patch changes this for
'members of the current instantiation' to set the type dependency based
on the member's type instead.

A few lit tests started to fail once I applied this patch because errors
are now diagnosed earlier (does not wait till instantiation). I've modified
these tests in this patch as well.

Patch fixes PR#40982

Differential Revision: https://reviews.llvm.org/D61027

Added:
cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaTemplate/dependent-names.cpp
cfe/trunk/test/SemaTemplate/enum-argument.cpp
cfe/trunk/test/SemaTemplate/member-access-expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=368706=368705=368706=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Aug 13 08:53:19 2019
@@ -1669,6 +1669,15 @@ MemberExpr *MemberExpr::Create(
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
+  if (FieldDecl *Field = dyn_cast(MemberDecl)) {
+DeclContext *DC = MemberDecl->getDeclContext();
+// dyn_cast_or_null is used to handle objC variables which do not
+// have a declaration context.
+CXXRecordDecl *RD = dyn_cast_or_null(DC);
+if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
+  E->setTypeDependent(T->isDependentType());
+  }
+
   if (HasQualOrFound) {
 // FIXME: Wrong. We should be looking at the member declaration we found.
 if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=368706=368705=368706=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Aug 13 08:53:19 2019
@@ -14288,6 +14288,8 @@ void Sema::RefersToMemberWithReducedAlig
   bool AnyIsPacked = false;
   do {
 QualType BaseType = ME->getBase()->getType();
+if (BaseType->isDependentType())
+  return;
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();

Modified: cfe/trunk/test/SemaTemplate/dependent-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-names.cpp?rev=368706=368705=368706=diff
==
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Tue Aug 13 08:53:19 2019
@@ -273,9 +273,6 @@ namespace PR10187 {
   }
   int e[10];
 };
-void g() {
-  S().f(); // expected-note {{here}}
-}
   }
 
   namespace A2 {

Modified: cfe/trunk/test/SemaTemplate/enum-argument.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/enum-argument.cpp?rev=368706=368705=368706=diff
==
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp (original)
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp Tue Aug 13 08:53:19 2019
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -31,7 +30,7 @@ namespace rdar8020920 {
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j;
+  bitfield + j; // expected-warning {{expression result unused}}
 }
   };
 }

Modified: cfe/trunk/test/SemaTemplate/member-access-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-access-expr.cpp?rev=368706=368705=368706=diff
==
--- cfe/trunk/test/SemaTemplate/member-access-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/member-access-expr.cpp Tue Aug 13 08:53:19 2019
@@ -156,7 +156,7 @@ namespace test6 {
 void get(B **ptr) {
   // It's okay if at some point we figure out how to diagnose this
   // at instantiation time.
-  *ptr = field;
+  *ptr = field; // expected-error {{assigning to 'test6::B *' from 
incompatible type 'test6::A *}}
 }
   };
 }

Added: 

r340439 - Currently clang does not emit unused static constants. GCC emits these

2018-08-22 Thread Elizabeth Andrews via cfe-commits
Author: eandrews
Date: Wed Aug 22 12:05:19 2018
New Revision: 340439

URL: http://llvm.org/viewvc/llvm-project?rev=340439=rev
Log:
Currently clang does not emit unused static constants. GCC emits these
constants by default when there is no optimization.

GCC's option -fno-keep-static-consts can be used to not emit
unused static constants.

In Clang, since default behavior does not keep unused static constants, 
-fkeep-static-consts can be used to emit these if required. This could be 
useful for producing identification strings like SVN identifiers 
inside the object file even though the string isn't used by the program.

Differential Revision: https://reviews.llvm.org/D40925

Added:
cfe/trunk/test/CodeGen/keep-static-consts.cpp
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=340439=340438=340439=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Aug 22 12:05:19 2018
@@ -893,7 +893,8 @@ def fforce_enable_int128 : Flag<["-"], "
 def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable support for int128_t type">;
-
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=340439=340438=340439=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Wed Aug 22 12:05:19 2018
@@ -341,6 +341,9 @@ CODEGENOPT(Addrsig, 1, 0)
 
 ENUM_CODEGENOPT(SignReturnAddress, SignReturnAddressScope, 2, None)
 
+/// Whether to emit unused static constants.
+CODEGENOPT(KeepStaticConsts, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=340439=340438=340439=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Aug 22 12:05:19 2018
@@ -1350,6 +1350,12 @@ void CodeGenModule::SetCommonAttributes(
 
   if (D && D->hasAttr())
 addUsedGlobal(GV);
+
+  if (CodeGenOpts.KeepStaticConsts && D && isa(D)) {
+const auto *VD = cast(D);
+if (VD->getType().isConstQualified() && VD->getStorageClass() == SC_Static)
+  addUsedGlobal(GV);
+  }
 }
 
 bool CodeGenModule::GetCPUAndFeaturesAttributes(const Decl *D,
@@ -1985,6 +1991,13 @@ bool CodeGenModule::MustBeEmitted(const
   if (LangOpts.EmitAllDecls)
 return true;
 
+  if (CodeGenOpts.KeepStaticConsts) {
+const auto *VD = dyn_cast(Global);
+if (VD && VD->getType().isConstQualified() &&
+VD->getStorageClass() == SC_Static)
+  return true;
+  }
+
   return getContext().DeclMustBeEmitted(Global);
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=340439=340438=340439=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Aug 22 12:05:19 2018
@@ -4008,6 +4008,7 @@ void Clang::ConstructJob(Compilation ,
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=340439=340438=340439=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Aug 22 12:05:19 2018
@@ -1145,6 +1145,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
   <<