Skip to content

Commit 67f57df

Browse files
Merge branch 'release/20.x' into revert_121559_release20
2 parents 517e0a8 + 182e8b7 commit 67f57df

File tree

24 files changed

+680
-92
lines changed

24 files changed

+680
-92
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,11 @@ SourceLocation CallExpr::getBeginLoc() const {
16651665
Method && Method->isExplicitObjectMemberFunction()) {
16661666
bool HasFirstArg = getNumArgs() > 0 && getArg(0);
16671667
assert(HasFirstArg);
1668-
if (HasFirstArg)
1669-
return getArg(0)->getBeginLoc();
1668+
if (HasFirstArg) {
1669+
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
1670+
return FirstArgLoc;
1671+
}
1672+
}
16701673
}
16711674
}
16721675

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
349349
}
350350
}
351351

352+
// Allow breaking before the right parens with block indentation if there was
353+
// a break after the left parens, which is tracked by BreakBeforeClosingParen.
354+
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
355+
Current.is(tok::r_paren)) {
356+
return CurrentState.BreakBeforeClosingParen;
357+
}
358+
352359
// Don't allow breaking before a closing brace of a block-indented braced list
353360
// initializer if there isn't already a break.
354361
if (Current.is(tok::r_brace) && Current.MatchingParen &&

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,8 +3961,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39613961
FormatToken *AfterLastAttribute = nullptr;
39623962
FormatToken *ClosingParen = nullptr;
39633963

3964-
for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
3965-
Tok = Tok->Next) {
3964+
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
3965+
? FirstNonComment->Next
3966+
: nullptr;
3967+
Tok; Tok = Tok->Next) {
39663968
if (Tok->is(TT_StartOfName))
39673969
SeenName = true;
39683970
if (Tok->Previous->EndsCppAttributeGroup)

clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ class BuiltinFunctionChecker : public Checker<eval::Call> {
9797
void handleOverflowBuiltin(const CallEvent &Call, CheckerContext &C,
9898
BinaryOperator::Opcode Op,
9999
QualType ResultType) const;
100-
const NoteTag *createBuiltinNoOverflowNoteTag(CheckerContext &C,
101-
bool BothFeasible, SVal Arg1,
102-
SVal Arg2, SVal Result) const;
103-
const NoteTag *createBuiltinOverflowNoteTag(CheckerContext &C) const;
100+
const NoteTag *createBuiltinOverflowNoteTag(CheckerContext &C,
101+
bool BothFeasible, SVal Arg1,
102+
SVal Arg2, SVal Result) const;
103+
ProgramStateRef initStateAftetBuiltinOverflow(CheckerContext &C,
104+
ProgramStateRef State,
105+
const CallEvent &Call,
106+
SVal RetCal,
107+
bool IsOverflow) const;
104108
std::pair<bool, bool> checkOverflow(CheckerContext &C, SVal RetVal,
105109
QualType Res) const;
106110

@@ -122,30 +126,24 @@ class BuiltinFunctionChecker : public Checker<eval::Call> {
122126

123127
} // namespace
124128

125-
const NoteTag *BuiltinFunctionChecker::createBuiltinNoOverflowNoteTag(
126-
CheckerContext &C, bool BothFeasible, SVal Arg1, SVal Arg2,
127-
SVal Result) const {
128-
return C.getNoteTag([Result, Arg1, Arg2, BothFeasible](
129-
PathSensitiveBugReport &BR, llvm::raw_ostream &OS) {
129+
const NoteTag *BuiltinFunctionChecker::createBuiltinOverflowNoteTag(
130+
CheckerContext &C, bool overflow, SVal Arg1, SVal Arg2, SVal Result) const {
131+
return C.getNoteTag([Result, Arg1, Arg2, overflow](PathSensitiveBugReport &BR,
132+
llvm::raw_ostream &OS) {
130133
if (!BR.isInteresting(Result))
131134
return;
132135

133-
// Propagate interestingness to input argumets if result is interesting.
136+
// Propagate interestingness to input arguments if result is interesting.
134137
BR.markInteresting(Arg1);
135138
BR.markInteresting(Arg2);
136139

137-
if (BothFeasible)
140+
if (overflow)
141+
OS << "Assuming overflow";
142+
else
138143
OS << "Assuming no overflow";
139144
});
140145
}
141146

142-
const NoteTag *
143-
BuiltinFunctionChecker::createBuiltinOverflowNoteTag(CheckerContext &C) const {
144-
return C.getNoteTag([](PathSensitiveBugReport &BR,
145-
llvm::raw_ostream &OS) { OS << "Assuming overflow"; },
146-
/*isPrunable=*/true);
147-
}
148-
149147
std::pair<bool, bool>
150148
BuiltinFunctionChecker::checkOverflow(CheckerContext &C, SVal RetVal,
151149
QualType Res) const {
@@ -175,6 +173,29 @@ BuiltinFunctionChecker::checkOverflow(CheckerContext &C, SVal RetVal,
175173
return {MayOverflow || MayUnderflow, MayNotOverflow && MayNotUnderflow};
176174
}
177175

176+
ProgramStateRef BuiltinFunctionChecker::initStateAftetBuiltinOverflow(
177+
CheckerContext &C, ProgramStateRef State, const CallEvent &Call,
178+
SVal RetVal, bool IsOverflow) const {
179+
SValBuilder &SVB = C.getSValBuilder();
180+
SVal Arg1 = Call.getArgSVal(0);
181+
SVal Arg2 = Call.getArgSVal(1);
182+
auto BoolTy = C.getASTContext().BoolTy;
183+
184+
ProgramStateRef NewState =
185+
State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
186+
SVB.makeTruthVal(IsOverflow, BoolTy));
187+
188+
if (auto L = Call.getArgSVal(2).getAs<Loc>()) {
189+
NewState = NewState->bindLoc(*L, RetVal, C.getLocationContext());
190+
191+
// Propagate taint if any of the arguments were tainted
192+
if (isTainted(State, Arg1) || isTainted(State, Arg2))
193+
NewState = addTaint(NewState, *L);
194+
}
195+
196+
return NewState;
197+
}
198+
178199
void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
179200
CheckerContext &C,
180201
BinaryOperator::Opcode Op,
@@ -184,8 +205,6 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
184205

185206
ProgramStateRef State = C.getState();
186207
SValBuilder &SVB = C.getSValBuilder();
187-
const Expr *CE = Call.getOriginExpr();
188-
auto BoolTy = C.getASTContext().BoolTy;
189208

190209
SVal Arg1 = Call.getArgSVal(0);
191210
SVal Arg2 = Call.getArgSVal(1);
@@ -195,29 +214,20 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
195214
SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
196215

197216
auto [Overflow, NotOverflow] = checkOverflow(C, RetValMax, ResultType);
198-
if (NotOverflow) {
199-
ProgramStateRef StateNoOverflow = State->BindExpr(
200-
CE, C.getLocationContext(), SVB.makeTruthVal(false, BoolTy));
201-
202-
if (auto L = Call.getArgSVal(2).getAs<Loc>()) {
203-
StateNoOverflow =
204-
StateNoOverflow->bindLoc(*L, RetVal, C.getLocationContext());
205217

206-
// Propagate taint if any of the argumets were tainted
207-
if (isTainted(State, Arg1) || isTainted(State, Arg2))
208-
StateNoOverflow = addTaint(StateNoOverflow, *L);
209-
}
218+
if (NotOverflow) {
219+
auto NewState =
220+
initStateAftetBuiltinOverflow(C, State, Call, RetVal, false);
210221

211-
C.addTransition(
212-
StateNoOverflow,
213-
createBuiltinNoOverflowNoteTag(
214-
C, /*BothFeasible=*/NotOverflow && Overflow, Arg1, Arg2, RetVal));
222+
C.addTransition(NewState, createBuiltinOverflowNoteTag(
223+
C, /*overflow=*/false, Arg1, Arg2, RetVal));
215224
}
216225

217226
if (Overflow) {
218-
C.addTransition(State->BindExpr(CE, C.getLocationContext(),
219-
SVB.makeTruthVal(true, BoolTy)),
220-
createBuiltinOverflowNoteTag(C));
227+
auto NewState = initStateAftetBuiltinOverflow(C, State, Call, RetVal, true);
228+
229+
C.addTransition(NewState, createBuiltinOverflowNoteTag(C, /*overflow=*/true,
230+
Arg1, Arg2, RetVal));
221231
}
222232
}
223233

clang/test/Analysis/builtin_overflow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void test_add_overflow(void)
2626
int res;
2727

2828
if (__builtin_add_overflow(__INT_MAX__, 1, &res)) {
29-
clang_analyzer_dump_int(res); //expected-warning{{1st function call argument is an uninitialized value}}
29+
clang_analyzer_dump_int(res); //expected-warning{{-2147483648 S32b}}
3030
return;
3131
}
3232

@@ -38,7 +38,7 @@ void test_add_underoverflow(void)
3838
int res;
3939

4040
if (__builtin_add_overflow(__INT_MIN__, -1, &res)) {
41-
clang_analyzer_dump_int(res); //expected-warning{{1st function call argument is an uninitialized value}}
41+
clang_analyzer_dump_int(res); //expected-warning{{2147483647 S32b}}
4242
return;
4343
}
4444

@@ -160,7 +160,7 @@ void test_bool_assign(void)
160160
{
161161
int res;
162162

163-
// Reproduce issue from GH#111147. __builtin_*_overflow funcions
163+
// Reproduce issue from GH#111147. __builtin_*_overflow functions
164164
// should return _Bool, but not int.
165165
_Bool ret = __builtin_mul_overflow(10, 20, &res); // no crash
166166
}

clang/test/Analysis/builtin_overflow_notes.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ void test_no_overflow_note(int a, int b)
1919

2020
void test_overflow_note(int a, int b)
2121
{
22-
int res; // expected-note{{'res' declared without an initial value}}
22+
int res;
2323

2424
if (__builtin_add_overflow(a, b, &res)) { // expected-note {{Assuming overflow}}
2525
// expected-note@-1 {{Taking true branch}}
26-
int var = res; // expected-warning{{Assigned value is garbage or undefined}}
27-
// expected-note@-1 {{Assigned value is garbage or undefined}}
26+
if (res) { // expected-note {{Assuming 'res' is not equal to 0}}
27+
// expected-note@-1 {{Taking true branch}}
28+
int *ptr = 0; // expected-note {{'ptr' initialized to a null pointer value}}
29+
int var = *(int *) ptr; //expected-warning {{Dereference of null pointer}}
30+
//expected-note@-1 {{Dereference of null pointer}}
31+
}
2832
return;
2933
}
3034
}

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,10 @@ struct S {
11341134
static_assert((S{} << 11) == a);
11351135
// expected-error@-1 {{use of undeclared identifier 'a'}}
11361136
}
1137+
1138+
namespace GH135522 {
1139+
struct S {
1140+
auto f(this auto) -> S;
1141+
bool g() { return f(); } // expected-error {{no viable conversion from returned value of type 'S' to function return type 'bool'}}
1142+
};
1143+
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
96149614
" auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
96159615
" ) {};",
96169616
Style);
9617+
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaa(\n"
9618+
" &bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
9619+
");",
9620+
Style);
96179621
}
96189622

96199623
TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
10731073
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
10741074
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
10751075
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
1076+
1077+
Tokens = annotate("using std::operator==;");
1078+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
1079+
// Not TT_FunctionDeclarationName.
1080+
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
10761081
}
10771082

10781083
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

cmake/Modules/LLVMVersion.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
77
set(LLVM_VERSION_MINOR 1)
88
endif()
99
if(NOT DEFINED LLVM_VERSION_PATCH)
10-
set(LLVM_VERSION_PATCH 3)
10+
set(LLVM_VERSION_PATCH 4)
1111
endif()
1212
if(NOT DEFINED LLVM_VERSION_SUFFIX)
1313
set(LLVM_VERSION_SUFFIX)

lldb/source/API/SBTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,9 +2020,9 @@ lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
20202020
error, force_live_memory, &load_addr);
20212021
const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
20222022
sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2023-
target_sp->GetArchitecture(), nullptr, target_sp->GetDisassemblyCPU(),
2024-
target_sp->GetDisassemblyFeatures(), flavor_string, *addr_ptr,
2025-
data.GetBytes(), bytes_read, count, data_from_file));
2023+
target_sp->GetArchitecture(), nullptr, flavor_string,
2024+
target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2025+
*addr_ptr, data.GetBytes(), bytes_read, count, data_from_file));
20262026
}
20272027
}
20282028

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Test SBTarget Read Instruction.
3+
"""
4+
5+
from lldbsuite.test.decorators import *
6+
from lldbsuite.test.lldbtest import *
7+
8+
9+
class TargetReadInstructionsFlavor(TestBase):
10+
@skipIfWindows
11+
@skipIf(archs=no_match(["x86_64", "x86", "i386"]))
12+
def test_read_instructions_with_flavor(self):
13+
self.build()
14+
executable = self.getBuildArtifact("a.out")
15+
16+
# create a target
17+
target = self.dbg.CreateTarget(executable)
18+
self.assertTrue(target.IsValid(), "target is not valid")
19+
20+
functions = target.FindFunctions("test_add")
21+
self.assertEqual(len(functions), 1)
22+
test_add = functions[0]
23+
24+
test_add_symbols = test_add.GetSymbol()
25+
self.assertTrue(
26+
test_add_symbols.IsValid(), "test_add function symbols is not valid"
27+
)
28+
29+
expected_instructions = (("mov", "eax, edi"), ("add", "eax, esi"), ("ret", ""))
30+
test_add_insts = test_add_symbols.GetInstructions(target, "intel")
31+
# clang adds an extra nop instruction but gcc does not. It makes more sense
32+
# to check if it is at least 3
33+
self.assertLessEqual(len(expected_instructions), len(test_add_insts))
34+
35+
# compares only the expected instructions
36+
for expected_instr, instr in zip(expected_instructions, test_add_insts):
37+
self.assertTrue(instr.IsValid(), "instruction is not valid")
38+
expected_mnemonic, expected_op_str = expected_instr
39+
self.assertEqual(instr.GetMnemonic(target), expected_mnemonic)
40+
self.assertEqual(instr.GetOperands(target), expected_op_str)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// This simple program is to test the lldb Python API SBTarget ReadInstruction
3+
// function.
4+
//
5+
// When the target is create we get all the instructions using the intel
6+
// flavor and see if it is correct.
7+
8+
int test_add(int a, int b);
9+
10+
__asm__("test_add:\n"
11+
" movl %edi, %eax\n"
12+
" addl %esi, %eax\n"
13+
" ret \n");
14+
15+
int main(int argc, char **argv) {
16+
int a = 10;
17+
int b = 20;
18+
int result = test_add(a, b);
19+
20+
return 0;
21+
}

llvm/lib/CodeGen/GlobalMerge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ bool GlobalMergeImpl::run(Module &M) {
711711
continue;
712712

713713
// Ignore all 'special' globals.
714-
if (GV.getName().starts_with("llvm.") || GV.getName().starts_with(".llvm."))
714+
if (GV.getName().starts_with("llvm.") ||
715+
GV.getName().starts_with(".llvm.") || Section == "llvm.metadata")
715716
continue;
716717

717718
// Ignore all "required" globals:

0 commit comments

Comments
 (0)