There's been a fair amount of chatter lately among pundits and experts that the global economy may be on course to sidestep the recession some had feared would result from central banks' inflation-fighting efforts, and instead make the "soft landing" those institutions had been aiming for. The stock market is reflecting this growing optimism. The S&P 500 is now up 10% from last month's low and is back to 26% above last October's bottom. We may be OK after all.

It would be unwise, however, to completely dismiss the possibility of a recession, and to fail to plan for the market bearishness such events can cause. Typically, recessions are trouble for stocks -- but this trio of tickers could actually thrive on economic weakness.

1. Walmart

Unlike most other retailers, Walmart (WMT -0.08%) isn't vulnerable to the crimped consumer spending that typically accompanies a recession. That's because more than half of its revenue comes from the sale of groceries, which people are going to purchase regardless of the economic environment.

And the other half of its business may be better protected from macro headwinds than investors fully appreciate. While goods like electronics, toys, and home goods are technically discretionary purchases, Walmart's position as a low-price leader means that most of its other business lines are rather resilient too.

Then there's the X factor -- the company's sheer market dominance and massive physical footprint. Walmart operates more than 10,000 stores worldwide  -- 4,616 of them under its namesake brand in the United States. (That's not counting its 599 Sam's Club stores.) According to a report from CSIMarket, Walmart accounts for more than 40% of the country's brick-and-mortar retail sales. Helping it maintain this market share is the fact that 90% of U.S. residents live within 10 miles of a Walmart store, making it too convenient of an option for many consumers to drive past.

Meanwhile, although its e-commerce presence doesn't hold a candle to Amazon's, Walmart's still doing alright on this front. Insider Intelligence reports it's the country's (distant) second-place online retailer, and revenue from that segment of the company's business grew 15% year over year last quarter and rose 24% year over year within the United States.

The kicker: While you've not heard much about it yet, Walmart's digital advertising business grew 20% last quarter. This service allowing the company's third-party sellers to pay to promote their goods on Walmart.com is a high-margin one, and could eventually become one of its top profit centers. If a recession strikes, these sellers might actually grow more interested in advertising on Walmart's site to spur demand, accelerating this high-profit business's growth.

Walmart is a bulldozer of a company. It can shrug off a recession at least as well as any other.

2. Altria Group

Most consumers understand that tobacco use is anything but good for you. In fact, there's plenty of evidence to support the idea that tobacco usage in any form jeopardizes your health.

What investors understand, however, is that hard-to-break habits can be good for the businesses that supply them.

Enter Altria Group (MO -0.37%), owner of cigarette brands including Marlboro, smokeless tobacco brands Copenhagen and Skoal, and pod-based vaping brand NJOY.

Although U.S. and global smoking-cessation efforts are technically gaining traction, they are working slowly, to be sure. How do we know? Altria still sold more than 19 billion cigarettes during the third quarter. That's down nearly 12%, but the company's alternative products helped compensate for some of that decline. Meanwhile, thanks to price increases, revenue is about even with last year's levels, while year-to-date profits are up just a tad.

MO Revenue (Quarterly) Chart

MO Revenue (Quarterly) data by YCharts.

The company's pricing power is helping it. It's the strength of the nicotine habit, however, that's doing most of the heavy lifting.

This won't be the case forever. As was noted, governments' smoking cessation efforts are working. For the first time ever, the World Health Organization expects the number of smokers worldwide to fall in the four-year span between 2021 and 2025. Meanwhile, although vaping and heated tobacco products are promoted as safer than traditional cigarettes, these alternatives aren't exactly drawing large crowds of customers either. Numbers from Altria's underage tobacco usage survey suggest vaping among high school students -- the age at which many people establish lifelong habits -- in the U.S. fell from 2019's 27.5% to an estimated 11.3% in 2021.

Here's the thing: The persistent headwinds against tobacco use are blowing very slowly. There's still plenty of money to be made in the tobacco business and passed along to shareholders in the form of dividends in the meantime. That's what makes such sin stocks such compelling investments to hold in the event of a recession, in fact. Even when corporate spending dries up and consumer discretionary spending slows down, smokers will still buy cigarettes.

Just keep in mind Altria is an increasingly tough name to hold for the long haul. Its stock should be viewed as strictly a short-term defensive position.

3. McDonald's

Last but not least, add McDonald's (MCD -0.91%) to your list of stocks that could prove to be portfolio lifelines in the event of a recession and a bear market.

McDonald's is the world's biggest restaurant chain in terms of number of locations, with 41,198 stores across the planet as of the end of September. Those sites generated around $25 billion in revenue for the franchiser over the last 12 months, making children happy and adults nostalgic in the process.

It's also a company built from the ground not just to support a dividend, but to consistently raise it. Management has boosted the payout annually for the past 47 years, making shareholders happy too. And these reliable cash payments can help cushion shareholders from the impacts of marketwide weakness.

That's not what makes McDonald's stock so attractive in the midst of a recession, though. Far more bullish is the nature of its business.

See, McDonald's isn't merely fun for children and affordable for parents when money is tight. Cheap meals are actually a draw in a challenging economic environment. As CEO Christopher Kempczinski commented during July's second-quarter earnings call:

"If you look at incomes under $100,000, we're actually doing quite well there, which suggests that we're getting some benefit from trade down, from things like full-service dining, casual dining ... then even if you go to incomes of $45,000 and less, our business is performing well there. What we're seeing with that group is we are seeing a little bit of a decrease in order size. But it's being offset by a very strong or continued strength in traffic."

Translation: A tight economy actually works in McDonald's favor, driving sales growth it might not have otherwise achieved. Last quarter's same-store sales growth in the United States was an impressive 8.1%, following Q2's growth of 10.3%.

There's no reason to believe this dynamic will change should another round of economic troubles take hold.