Skip to content

Commit 39413b1

Browse files
author
anoopkg6
committed
Merge branch 'llvm-jitlink' of github.com:anoopkg6/llvm-project into llvm-jitlink
2 parents 3a8141f + 18dbe0e commit 39413b1

File tree

80 files changed

+22661
-20119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+22661
-20119
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ Improvements to Clang's diagnostics
345345
-----------------------------------
346346
- Diagnostics messages now refer to ``structured binding`` instead of ``decomposition``,
347347
to align with `P0615R0 <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0615r0.html>`_ changing the term. (#GH157880)
348+
- Clang now suppresses runtime behavior warnings for unreachable code in file-scope
349+
variable initializers, matching the behavior for functions. This prevents false
350+
positives for operations in unreachable branches of constant expressions.
348351
- Added a separate diagnostic group ``-Wfunction-effect-redeclarations``, for the more pedantic
349352
diagnostics for function effects (``[[clang::nonblocking]]`` and ``[[clang::nonallocating]]``).
350353
Moved the warning for a missing (though implied) attribute on a redeclaration into this group.

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5223,11 +5223,7 @@ class Parser : public CodeCompletionHandler {
52235223
/// assignment-expression
52245224
/// '{' ...
52255225
/// \endverbatim
5226-
ExprResult ParseInitializer() {
5227-
if (Tok.isNot(tok::l_brace))
5228-
return ParseAssignmentExpression();
5229-
return ParseBraceInitializer();
5230-
}
5226+
ExprResult ParseInitializer(Decl *DeclForInitializer = nullptr);
52315227

52325228
/// MayBeDesignationStart - Return true if the current token might be the
52335229
/// start of a designator. If we can tell it is impossible that it is a

clang/include/clang/Sema/AnalysisBasedWarnings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
#define LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
1515

1616
#include "clang/AST/Decl.h"
17+
#include "clang/Sema/ScopeInfo.h"
1718
#include "llvm/ADT/DenseMap.h"
19+
#include "llvm/ADT/MapVector.h"
1820
#include <memory>
1921

2022
namespace clang {
2123

24+
class AnalysisDeclContext;
2225
class Decl;
2326
class FunctionDecl;
2427
class QualType;
2528
class Sema;
29+
class VarDecl;
2630
namespace sema {
2731
class FunctionScopeInfo;
2832
class SemaPPCallbacks;
@@ -57,6 +61,8 @@ class AnalysisBasedWarnings {
5761

5862
enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
5963
llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
64+
std::multimap<VarDecl *, PossiblyUnreachableDiag>
65+
VarDeclPossiblyUnreachableDiags;
6066

6167
Policy PolicyOverrides;
6268
void clearOverrides();
@@ -107,6 +113,10 @@ class AnalysisBasedWarnings {
107113
// Issue warnings that require whole-translation-unit analysis.
108114
void IssueWarnings(TranslationUnitDecl *D);
109115

116+
void registerVarDeclWarning(VarDecl *VD, PossiblyUnreachableDiag PUD);
117+
118+
void issueWarningsForRegisteredVarDecl(VarDecl *VD);
119+
110120
// Gets the default policy which is in effect at the given source location.
111121
Policy getPolicyInEffectAt(SourceLocation Loc);
112122

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6756,6 +6756,11 @@ class Sema final : public SemaBase {
67566756
/// suffice, e.g., in a default function argument.
67576757
Decl *ManglingContextDecl;
67586758

6759+
/// Declaration for initializer if one is currently being
6760+
/// parsed. Used when an expression has a possibly unreachable
6761+
/// diagnostic to reference the declaration as a whole.
6762+
VarDecl *DeclForInitializer = nullptr;
6763+
67596764
/// If we are processing a decltype type, a set of call expressions
67606765
/// for which we have deferred checking the completeness of the return type.
67616766
SmallVector<CallExpr *, 8> DelayedDecltypeCalls;

clang/lib/Analysis/AnalysisDeclContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
117117
return BD->getBody();
118118
else if (const auto *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
119119
return FunTmpl->getTemplatedDecl()->getBody();
120+
else if (const auto *VD = dyn_cast_or_null<VarDecl>(D)) {
121+
if (VD->isFileVarDecl()) {
122+
return const_cast<Stmt *>(dyn_cast_or_null<Stmt>(VD->getInit()));
123+
}
124+
}
120125

121126
llvm_unreachable("unknown code decl");
122127
}

clang/lib/CodeGen/Targets/SPIR.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,16 @@ CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
260260
LangAS AS = QT->getUnqualifiedDesugaredType()->isNullPtrType()
261261
? LangAS::Default
262262
: QT->getPointeeType().getAddressSpace();
263+
unsigned ASAsInt = static_cast<unsigned>(AS);
264+
unsigned FirstTargetASAsInt =
265+
static_cast<unsigned>(LangAS::FirstTargetAddressSpace);
266+
unsigned CodeSectionINTELAS = FirstTargetASAsInt + 9;
267+
// As per SPV_INTEL_function_pointers, it is illegal to addrspacecast
268+
// function pointers to/from the generic AS.
269+
bool IsFunctionPtrAS =
270+
CGM.getTriple().isSPIRV() && ASAsInt == CodeSectionINTELAS;
263271
if (AS == LangAS::Default || AS == LangAS::opencl_generic ||
264-
AS == LangAS::opencl_constant)
272+
AS == LangAS::opencl_constant || IsFunctionPtrAS)
265273
return llvm::ConstantPointerNull::get(PT);
266274

267275
auto &Ctx = CGM.getContext();

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
26132613
}
26142614

26152615
PreferredType.enterVariableInit(Tok.getLocation(), ThisDecl);
2616-
ExprResult Init = ParseInitializer();
2616+
ExprResult Init = ParseInitializer(ThisDecl);
26172617

26182618
// If this is the only decl in (possibly) range based for statement,
26192619
// our best guess is that the user meant ':' instead of '='.

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction,
33593359
Diag(Tok, diag::err_ms_property_initializer) << PD;
33603360
return ExprError();
33613361
}
3362-
return ParseInitializer();
3362+
return ParseInitializer(D);
33633363
}
33643364

33653365
void Parser::SkipCXXMemberSpecification(SourceLocation RecordLoc,

clang/lib/Parse/ParseInit.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,26 @@ bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
581581

582582
return !trailingComma;
583583
}
584+
585+
ExprResult Parser::ParseInitializer(Decl *DeclForInitializer) {
586+
// Set DeclForInitializer for file-scope variables.
587+
// For constexpr references, set it to suppress runtime warnings.
588+
// For non-constexpr references, don't set it to avoid evaluation issues
589+
// with self-referencing initializers. Local variables (including local
590+
// constexpr) should emit runtime warnings.
591+
if (DeclForInitializer && !Actions.ExprEvalContexts.empty()) {
592+
if (auto *VD = dyn_cast<VarDecl>(DeclForInitializer);
593+
VD && VD->isFileVarDecl() &&
594+
(!VD->getType()->isReferenceType() || VD->isConstexpr()))
595+
Actions.ExprEvalContexts.back().DeclForInitializer = VD;
596+
}
597+
598+
ExprResult init;
599+
if (Tok.isNot(tok::l_brace)) {
600+
init = ParseAssignmentExpression();
601+
} else {
602+
init = ParseBraceInitializer();
603+
}
604+
605+
return init;
606+
}

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) {
339339
}
340340

341341
PreferredType.enterVariableInit(Tok.getLocation(), OmpPrivParm);
342-
ExprResult Init = ParseInitializer();
342+
ExprResult Init = ParseInitializer(OmpPrivParm);
343343

344344
if (Init.isInvalid()) {
345345
SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);

0 commit comments

Comments
 (0)